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
679c62cc
Commit
679c62cc
authored
Feb 07, 2025
by
Jiachi Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
drop component stacks
parent
547ef944
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
237 additions
and
696 deletions
+237
-696
errors.tsx
...t-dev-overlay/_experimental/internal/container/errors.tsx
+2
-3
component-stack-pseudo-html.stories.tsx
...ner/runtime-error/component-stack-pseudo-html.stories.tsx
+0
-22
component-stack-pseudo-html.tsx
...l/container/runtime-error/component-stack-pseudo-html.tsx
+10
-20
diff-view.tsx
...components/react-dev-overlay/hydration-diff/diff-view.tsx
+20
-58
Errors.tsx
...omponents/react-dev-overlay/internal/container/Errors.tsx
+1
-17
component-stack-pseudo-html.tsx
...al/container/RuntimeError/component-stack-pseudo-html.tsx
+14
-414
hydration-error.test.ts
test/development/acceptance-app/hydration-error.test.ts
+156
-148
hydration-error.test.ts
test/development/acceptance/hydration-error.test.ts
+13
-7
page.tsx
test/e2e/app-dir/hello-world/app/page.tsx
+10
-2
next.config.js
test/e2e/app-dir/hello-world/next.config.js
+5
-1
index.tsx
test/e2e/hello-world/pages/index.tsx
+5
-2
next-test-utils.ts
test/lib/next-test-utils.ts
+1
-2
No files found.
packages/next/src/client/components/react-dev-overlay/_experimental/internal/container/errors.tsx
View file @
679c62cc
...
...
@@ -137,8 +137,8 @@ export function Errors({
:
undefined
const
diffContent
=
(
errorDetails
.
reactOutputComponentDiff
||
''
)
.
trim
()
.
replace
(
/
\.\.\.\s
*/
,
''
)
//
.trim()
//
.replace(/\.\.\.\s*/, '')
const
showHydrationDiff
=
Boolean
(
hydrationWarning
&&
// activeError.componentStackFrames?.length ||
...
...
@@ -193,7 +193,6 @@ export function Errors({
<
PseudoHtmlDiff
className=
"nextjs__container_errors__component-stack"
hydrationMismatchType=
{
hydrationErrorType
}
componentStackFrames=
{
activeError
.
componentStackFrames
||
[]
}
firstContent=
{
serverContent
}
secondContent=
{
clientContent
}
reactOutputComponentDiff=
{
diffContent
}
...
...
packages/next/src/client/components/react-dev-overlay/_experimental/internal/container/runtime-error/component-stack-pseudo-html.stories.tsx
View file @
679c62cc
...
...
@@ -13,28 +13,8 @@ const meta: Meta<typeof PseudoHtmlDiff> = {
export
default
meta
type
Story
=
StoryObj
<
typeof
PseudoHtmlDiff
>
const
sampleComponentStack
=
[
{
component
:
'div'
,
canOpenInEditor
:
false
,
},
{
component
:
'article'
,
canOpenInEditor
:
false
,
},
{
component
:
'main'
,
canOpenInEditor
:
false
,
},
{
component
:
'Home'
,
canOpenInEditor
:
false
,
},
]
export
const
TextMismatch
:
Story
=
{
args
:
{
componentStackFrames
:
sampleComponentStack
,
firstContent
:
'Server rendered content'
,
secondContent
:
'Client rendered content'
,
hydrationMismatchType
:
'text'
,
...
...
@@ -44,7 +24,6 @@ export const TextMismatch: Story = {
export
const
TextInTagMismatch
:
Story
=
{
args
:
{
componentStackFrames
:
sampleComponentStack
,
firstContent
:
'Mismatched content'
,
secondContent
:
'p'
,
hydrationMismatchType
:
'text-in-tag'
,
...
...
@@ -54,7 +33,6 @@ export const TextInTagMismatch: Story = {
export
const
ReactUnifiedMismatch
:
Story
=
{
args
:
{
componentStackFrames
:
sampleComponentStack
,
hydrationMismatchType
:
'tag'
,
reactOutputComponentDiff
:
`<Page>
<Layout>
...
...
packages/next/src/client/components/react-dev-overlay/_experimental/internal/container/runtime-error/component-stack-pseudo-html.tsx
View file @
679c62cc
...
...
@@ -24,15 +24,6 @@ export const PSEUDO_HTML_DIFF_STYLES = css`
background: var(--color-amber-300);
font-weight: bold;
}
[data-nextjs-container-errors-pseudo-html-line--error]::before {
content: '>';
color: var(--color-red-900);
float: left;
width: 0;
margin-left: calc(var(--size-6) * -1);
margin-right: var(--size-8);
}
[data-nextjs-container-errors-pseudo-html-collapse-button] {
all: unset;
margin-left: var(--size-3);
...
...
@@ -43,24 +34,23 @@ export const PSEUDO_HTML_DIFF_STYLES = css`
[data-nextjs-container-errors-pseudo-html--diff='add'] {
background: var(--color-green-300);
}
[data-nextjs-container-errors-pseudo-html--diff='add']::before {
content: '+';
color: var(--color-green-900);
float: left;
width: 0;
[data-nextjs-container-errors-pseudo-html-line-sign] {
margin-left: calc(var(--size-6) * -1);
margin-right: var(--size-8);
margin-right: var(--size-6);
}
[data-nextjs-container-errors-pseudo-html--diff='add'] [data-nextjs-container-errors-pseudo-html-line-sign] {
color: var(--color-green-900);
}
[data-nextjs-container-errors-pseudo-html--diff='remove'] {
background: var(--color-red-300);
}
[data-nextjs-container-errors-pseudo-html--diff='remove']::before {
content: '-';
[data-nextjs-container-errors-pseudo-html--diff='remove'] [data-nextjs-container-errors-pseudo-html-line-sign] {
color: var(--color-red-900);
float: left;
width: 0;
margin-left: calc(var(--size-6) * -1);
margin-right: var(--size-8);
margin-right: var(--size-6);
}
[data-nextjs-container-errors-pseudo-html-line--error] [data-nextjs-container-errors-pseudo-html-line-sign] {
color: var(--color-red-900);
}
${
/* hide but text are still accessible in DOM */
''
}
[data-nextjs-container-errors-pseudo-html--hint] {
...
...
packages/next/src/client/components/react-dev-overlay/hydration-diff/diff-view.tsx
View file @
679c62cc
import
{
useMemo
,
useState
}
from
'react'
import
type
{
ComponentStackFrame
}
from
'../internal/helpers/parse-component-stack'
import
{
CollapseIcon
}
from
'../internal/icons/CollapseIcon'
/**
...
...
@@ -51,14 +50,12 @@ import { CollapseIcon } from '../internal/icons/CollapseIcon'
*
*/
export
function
PseudoHtmlDiff
({
componentStackFrames
,
firstContent
,
secondContent
,
hydrationMismatchType
,
reactOutputComponentDiff
,
...
props
}:
{
componentStackFrames
:
ComponentStackFrame
[]
firstContent
:
string
secondContent
:
string
reactOutputComponentDiff
:
string
...
...
@@ -68,22 +65,19 @@ export function PseudoHtmlDiff({
const
htmlComponents
=
useMemo
(()
=>
{
const
componentStacks
:
React
.
ReactNode
[]
=
[]
let
currentComponentIndex
=
componentStackFrames
.
length
-
1
const
reactComponentDiffLines
=
reactOutputComponentDiff
!
.
split
(
'
\
n'
)
reactComponentDiffLines
.
forEach
((
line
,
index
)
=>
{
let
trimmedLine
=
line
.
trim
()
const
isDiffLine
=
trimmedLine
[
0
]
===
'+'
||
trimmedLine
[
0
]
===
'-'
const
isHighlightedLine
=
trimmedLine
[
0
]
===
'>'
const
spaces
=
' '
.
repeat
(
line
.
length
-
trimmedLine
.
slice
(
1
).
trim
().
length
)
if
(
isHighlightedLine
)
{
trimmedLine
=
trimmedLine
.
slice
(
2
).
trim
()
// trim spaces after sign
}
const
sign
=
isHighlightedLine
||
isDiffLine
?
trimmedLine
[
0
]
:
''
const
[
prefix
,
suffix
]
=
(
isHighlightedLine
||
isDiffLine
)
?
line
.
split
(
sign
,
2
)
:
[
line
,
''
]
if
(
isDiffLine
)
{
const
sign
=
trimmedLine
[
0
]
trimmedLine
=
trimmedLine
.
slice
(
1
).
trim
()
// trim spaces after sign
componentStacks
.
push
(
<
span
key=
{
'comp-diff'
+
index
}
...
...
@@ -94,69 +88,37 @@ export function PseudoHtmlDiff({
>
<
span
>
{
/* Slice 2 spaces for the icon */
}
{
spaces
}
{
trimmedLine
}
{
prefix
}
<
span
data
-
nextjs
-
container
-
errors
-
pseudo
-
html
-
line
-
sign
>
{
sign
}
</
span
>
{
suffix
}
{
'
\
n'
}
</
span
>
</
span
>
)
}
else
if
(
currentComponentIndex
>=
0
)
{
const
isUserLandComponent
=
trimmedLine
.
startsWith
(
'<'
+
componentStackFrames
[
currentComponentIndex
].
component
)
// If it's matched userland component or it's ... we will keep the component stack in diff
if
(
isUserLandComponent
||
trimmedLine
===
'...'
)
{
currentComponentIndex
--
componentStacks
.
push
(
<
span
data
-
nextjs
-
container
-
errors
-
pseudo
-
html
-
line
key=
{
'comp-diff'
+
index
}
{
...
(
isHighlightedLine
?
{
'
data
-
nextjs
-
container
-
errors
-
pseudo
-
html
-
line
--
error
':
true
,
}
:
undefined
)}
>
{
spaces
}
{
trimmedLine
}
{
'
\
n'
}
</
span
>
)
}
else
{
componentStacks
.
push
(
<
span
data
-
nextjs
-
container
-
errors
-
pseudo
-
html
-
line
key=
{
'comp-diff'
+
index
}
{
...
(
isHighlightedLine
?
{
'
data
-
nextjs
-
container
-
errors
-
pseudo
-
html
-
line
--
error
':
true
,
}
:
undefined
)}
>
{
spaces
}
{
trimmedLine
}
{
'
\
n'
}
</
span
>
)
}
}
else
{
// In general, if it's not collapsed, show the whole diff
componentStacks
.
push
(
<
span
data
-
nextjs
-
container
-
errors
-
pseudo
-
html
-
line
key=
{
'comp-diff'
+
index
}
{
...
(
isHighlightedLine
?
{
'
data
-
nextjs
-
container
-
errors
-
pseudo
-
html
-
line
--
error
':
true
,
}
:
undefined
)}
>
{
spaces
}
{
trimmedLine
}
{
prefix
}
<
span
data
-
nextjs
-
container
-
errors
-
pseudo
-
html
-
line
-
sign
>
{
sign
}
</
span
>
{
suffix
}
{
'
\
n'
}
</
span
>
)
}
})
return
componentStacks
},
[
componentStackFrames
,
reactOutputComponentDiff
])
},
[
reactOutputComponentDiff
])
return
(
<
div
...
...
packages/next/src/client/components/react-dev-overlay/internal/container/Errors.tsx
View file @
679c62cc
...
...
@@ -297,25 +297,10 @@ export function Errors({
:
null
const
diffContent
=
(
errorDetails
.
reactOutputComponentDiff
||
''
)
.
trim
()
.
replace
(
/
\.\.\.\s
*/
,
''
)
const
showHydrationDiff
=
Boolean
(
hydrationWarning
&&
// activeError.componentStackFrames?.length ||
!!
diffContent
hydrationWarning
&&
!!
diffContent
)
// const componentStackNames: string[] = activeError.componentStackFrames
// ? activeError.componentStackFrames.map((f) => f.component)
// : ((errorDetails.componentStack || '')
// .split('\n')
// .map((line) => {
// // at ComponentName (location)
// const match = line.trim().match(/at ([\w]+)/)
// return match ? match[1] : ''
// })
// .filter(Boolean) as string[])
return
(
<
Overlay
>
<
Dialog
...
...
@@ -402,7 +387,6 @@ export function Errors({
<
PseudoHtmlDiff
className=
"nextjs__container_errors__component-stack"
hydrationMismatchType=
{
hydrationErrorType
}
componentStackFrames=
{
activeError
.
componentStackFrames
||
[]
}
firstContent=
{
serverContent
}
secondContent=
{
clientContent
}
reactOutputComponentDiff=
{
diffContent
}
...
...
packages/next/src/client/components/react-dev-overlay/internal/container/RuntimeError/component-stack-pseudo-html.tsx
View file @
679c62cc
This diff is collapsed.
Click to expand it.
test/development/acceptance-app/hydration-error.test.ts
View file @
679c62cc
This diff is collapsed.
Click to expand it.
test/development/acceptance/hydration-error.test.ts
View file @
679c62cc
...
...
@@ -76,7 +76,8 @@ describe('Error overlay for hydration errors in Pages router', () => {
await
session
.
assertHasRedbox
()
expect
(
await
getRedboxTotalErrorCount
(
browser
)).
toBe
(
isReact18
?
2
:
1
)
await
session
.
openRedbox
()
if
(
isReact18
)
{
expect
(
await
session
.
getRedboxDescription
()).
toMatchInlineSnapshot
(
`"Text content did not match. Server: "server" Client: "client""`
...
...
@@ -204,6 +205,7 @@ describe('Error overlay for hydration errors in Pages router', () => {
)
})
await
session
.
openRedbox
()
const
pseudoHtml
=
await
session
.
getRedboxComponentStack
()
if
(
isTurbopack
)
{
if
(
isReact18
)
{
...
...
@@ -842,7 +844,8 @@ describe('Error overlay for hydration errors in Pages router', () => {
await
retry
(
async
()
=>
{
expect
(
await
getRedboxTotalErrorCount
(
browser
)).
toBe
(
isReact18
?
3
:
1
)
})
await
session
.
openRedbox
()
const
description
=
await
session
.
getRedboxDescription
()
if
(
isReact18
)
{
expect
(
description
).
toMatchInlineSnapshot
(
...
...
@@ -878,7 +881,7 @@ describe('Error overlay for hydration errors in Pages router', () => {
}
})
it
(
'should only show one hydration error when bad nesting happened - div > tr'
,
async
()
=>
{
it
.
only
(
'should only show one hydration error when bad nesting happened - div > tr'
,
async
()
=>
{
await
using
sandbox
=
await
createSandbox
(
next
,
new
Map
([
...
...
@@ -897,7 +900,8 @@ describe('Error overlay for hydration errors in Pages router', () => {
await
retry
(
async
()
=>
{
expect
(
await
getRedboxTotalErrorCount
(
browser
)).
toBe
(
isReact18
?
3
:
1
)
})
await
session
.
openRedbox
()
const
description
=
await
session
.
getRedboxDescription
()
if
(
isReact18
)
{
expect
(
description
).
toMatchInlineSnapshot
(
...
...
@@ -977,7 +981,8 @@ describe('Error overlay for hydration errors in Pages router', () => {
await
retry
(
async
()
=>
{
expect
(
await
getRedboxTotalErrorCount
(
browser
)).
toBe
(
isReact18
?
3
:
1
)
})
await
session
.
openRedbox
()
const
description
=
await
session
.
getRedboxDescription
()
if
(
isReact18
)
{
expect
(
description
).
toMatchInlineSnapshot
(
...
...
@@ -1125,12 +1130,13 @@ describe('Error overlay for hydration errors in Pages router', () => {
const
{
session
,
browser
}
=
sandbox
await
session
.
assertHasRedbox
()
await
retry
(
async
()
=>
{
await
expect
(
await
getRedboxTotalErrorCount
(
browser
)).
toBe
(
expect
(
await
getRedboxTotalErrorCount
(
browser
)).
toBe
(
// This case only hit 2 errors in React 18
isReact18
?
2
:
1
)
})
await
session
.
openRedbox
()
const
pseudoHtml
=
await
session
.
getRedboxComponentStack
()
if
(
isTurbopack
)
{
// FIXME: Should not fork on Turbopack i.e. match the snapshot in the else-branch
...
...
test/e2e/app-dir/hello-world/app/page.tsx
View file @
679c62cc
export
default
function
Page
()
{
return
<
p
>
hello world
</
p
>
'use client'
const
isClient
=
typeof
window
!==
'undefined'
export
default
function
Mismatch
()
{
return
(
<
div
className=
"parent"
>
<
header
className=
"1"
/>
{
isClient
&&
'second'
}
<
footer
className=
"3"
/>
</
div
>
)
}
test/e2e/app-dir/hello-world/next.config.js
View file @
679c62cc
/**
* @type {import('next').NextConfig}
*/
const
nextConfig
=
{}
const
nextConfig
=
{
experimental
:
{
// newDevOverlay: true,
},
}
module
.
exports
=
nextConfig
test/e2e/hello-world/pages/index.tsx
View file @
679c62cc
// export default function Page() {
// return <p>hello world</p>
// }
export
default
function
Page
()
{
return
<
p
>
hello world
</
p
>
}
return
<
div
><
tr
></
tr
></
div
>
}
\ No newline at end of file
test/lib/next-test-utils.ts
View file @
679c62cc
...
...
@@ -1292,8 +1292,7 @@ export async function getRedboxComponentStack(
'[data-nextjs-container-errors-pseudo-html] code'
,
30000
)
// TODO: the type for elementsByCss is incorrect
const
componentStackFrameElements
:
any
=
await
browser
.
elementsByCss
(
const
componentStackFrameElements
=
await
browser
.
elementsByCss
(
'[data-nextjs-container-errors-pseudo-html] code'
)
const
componentStackFrameTexts
=
await
Promise
.
all
(
...
...
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