Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
922f0e92
Unverified
Commit
922f0e92
authored
Feb 21, 2025
by
Jiachi Liu
Committed by
GitHub
Feb 21, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[dev-overlay] do not attach hydration info to non hydration errors (#76349)
parent
5b420d2b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
67 additions
and
3 deletions
+67
-3
attach-hydration-error-state.ts
.../client/components/errors/attach-hydration-error-state.ts
+10
-3
page.tsx
...on-error-count/app/hydration-with-runtime-errors/page.tsx
+15
-0
hydration-error-count.test.ts
...p-dir/hydration-error-count/hydration-error-count.test.ts
+42
-0
No files found.
packages/next/src/client/components/errors/attach-hydration-error-state.ts
View file @
922f0e92
...
@@ -9,12 +9,18 @@ import {
...
@@ -9,12 +9,18 @@ import {
}
from
'./hydration-error-info'
}
from
'./hydration-error-info'
export
function
attachHydrationErrorState
(
error
:
Error
)
{
export
function
attachHydrationErrorState
(
error
:
Error
)
{
const
reactHydrationDiffSegments
=
getReactHydrationDiffSegments
(
error
.
message
)
let
parsedHydrationErrorState
:
typeof
hydrationErrorState
=
{}
let
parsedHydrationErrorState
:
typeof
hydrationErrorState
=
{}
const
isHydrationWarning
=
testReactHydrationWarning
(
error
.
message
)
const
isHydrationWarning
=
testReactHydrationWarning
(
error
.
message
)
const
isHydrationRuntimeError
=
isHydrationError
(
error
)
const
isHydrationRuntimeError
=
isHydrationError
(
error
)
// If it's not hydration warnings or errors, skip
if
(
!
(
isHydrationRuntimeError
||
isHydrationWarning
))
{
return
}
const
reactHydrationDiffSegments
=
getReactHydrationDiffSegments
(
error
.
message
)
// If the reactHydrationDiffSegments exists
// If the reactHydrationDiffSegments exists
// and the diff (reactHydrationDiffSegments[1]) exists
// and the diff (reactHydrationDiffSegments[1]) exists
// e.g. the hydration diff log error.
// e.g. the hydration diff log error.
...
@@ -72,5 +78,6 @@ export function attachHydrationErrorState(error: Error) {
...
@@ -72,5 +78,6 @@ export function attachHydrationErrorState(error: Error) {
hydrationErrorState
.
reactOutputComponentDiff
hydrationErrorState
.
reactOutputComponentDiff
}
}
}
}
// If it's a hydration error, store the hydration error state into the error object
;(
error
as
any
).
details
=
parsedHydrationErrorState
;(
error
as
any
).
details
=
parsedHydrationErrorState
}
}
test/development/app-dir/hydration-error-count/app/hydration-with-runtime-errors/page.tsx
0 → 100644
View file @
922f0e92
'use client'
import
{
useEffect
}
from
'react'
export
default
function
Page
()
{
useEffect
(()
=>
{
throw
new
Error
(
'runtime error'
)
},
[])
return
(
<
p
>
sneaky
<
p
>
very sneaky
</
p
>
</
p
>
)
}
test/development/app-dir/hydration-error-count/hydration-error-count.test.ts
View file @
922f0e92
...
@@ -9,6 +9,7 @@ import {
...
@@ -9,6 +9,7 @@ import {
goToNextErrorView
,
goToNextErrorView
,
getRedboxDescriptionWarning
,
getRedboxDescriptionWarning
,
getHighlightedDiffLines
,
getHighlightedDiffLines
,
assertHasRedbox
,
}
from
'next-test-utils'
}
from
'next-test-utils'
import
{
BrowserInterface
}
from
'next-webdriver'
import
{
BrowserInterface
}
from
'next-webdriver'
...
@@ -131,6 +132,47 @@ describe('hydration-error-count', () => {
...
@@ -131,6 +132,47 @@ describe('hydration-error-count', () => {
}
}
`
)
`
)
})
})
it
(
'should display runtime error separately from hydration errors'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/hydration-with-runtime-errors'
)
await
assertHasRedbox
(
browser
)
expect
(
await
getToastErrorCount
(
browser
)).
toBe
(
3
)
// Move to the last hydration error
await
goToNextErrorView
(
browser
)
expect
(
browser
).
toDisplayRedbox
(
`
{
"count": 3,
"description": "In HTML, <p> cannot be a descendant of <p>.
This will cause a hydration error.",
"environmentLabel": null,
"label": "Unhandled Runtime Error",
"source": "app/hydration-with-runtime-errors/page.tsx (12:14) @ Page
> 12 | sneaky <p>very sneaky</p>
| ^",
"stack": [
"p <anonymous> (0:0)",
"Page app/hydration-with-runtime-errors/page.tsx (12:14)",
],
}
`
)
await
goToNextErrorView
(
browser
)
expect
(
browser
).
toDisplayRedbox
(
`
{
"count": 3,
"description": "Error: runtime error",
"environmentLabel": null,
"label": "Unhandled Runtime Error",
"source": "app/hydration-with-runtime-errors/page.tsx (7:11) @ Page.useEffect
> 7 | throw new Error('runtime error')
| ^",
"stack": [
"Page.useEffect app/hydration-with-runtime-errors/page.tsx (7:11)",
],
}
`
)
})
})
})
async
function
getHydrationErrorSnapshot
(
browser
:
BrowserInterface
)
{
async
function
getHydrationErrorSnapshot
(
browser
:
BrowserInterface
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment