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
9b39c79d
Unverified
Commit
9b39c79d
authored
Jan 19, 2023
by
Hannes Bornö
Committed by
GitHub
Jan 19, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Display the reason of hydration error in error overlay (#44857)
parent
d363e6f2
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
1316 additions
and
27 deletions
+1316
-27
app-index.tsx
packages/next/src/client/app-index.tsx
+11
-0
hydration-error-info.ts
...eact-dev-overlay/internal/helpers/hydration-error-info.ts
+30
-0
use-error-handler.ts
...s/react-dev-overlay/internal/helpers/use-error-handler.ts
+6
-1
ReactRefreshLogBox.test.ts
test/development/acceptance-app/ReactRefreshLogBox.test.ts
+0
-20
ReactRefreshLogBox.test.ts.snap
...eptance-app/__snapshots__/ReactRefreshLogBox.test.ts.snap
+0
-6
hydration-error.test.ts
test/development/acceptance-app/hydration-error.test.ts
+1269
-0
No files found.
packages/next/src/client/app-index.tsx
View file @
9b39c79d
...
...
@@ -254,6 +254,17 @@ export function hydrate() {
onRecoverableError
,
}
const
isError
=
document
.
documentElement
.
id
===
'__next_error__'
if
(
process
.
env
.
NODE_ENV
!==
'production'
)
{
// Patch console.error to collect information about hydration errors
const
patchConsoleError
=
require
(
'./components/react-dev-overlay/internal/helpers/hydration-error-info'
)
.
patchConsoleError
as
typeof
import
(
'./components/react-dev-overlay/internal/helpers/hydration-error-info'
).
patchConsoleError
if
(
!
isError
)
{
patchConsoleError
()
}
}
const
reactRoot
=
isError
?
(
ReactDOMClient
as
any
).
createRoot
(
appElement
,
options
)
:
(
React
as
any
).
startTransition
(()
=>
...
...
packages/next/src/client/components/react-dev-overlay/internal/helpers/hydration-error-info.ts
0 → 100644
View file @
9b39c79d
export
let
hydrationErrorInfo
:
string
|
undefined
const
knownHydrationWarnings
=
new
Set
([
'Warning: Text content did not match. Server: "%s" Client: "%s"%s'
,
'Warning: Expected server HTML to contain a matching <%s> in <%s>.%s'
,
'Warning: Expected server HTML to contain a matching text node for "%s" in <%s>.%s'
,
'Warning: Did not expect server HTML to contain a <%s> in <%s>.%s'
,
'Warning: Did not expect server HTML to contain the text node "%s" in <%s>.%s'
,
])
export
function
patchConsoleError
()
{
const
prev
=
console
.
error
console
.
error
=
function
(
msg
,
serverContent
,
clientContent
,
// TODO-APP: Display the component stack in the overlay
_componentStack
)
{
if
(
knownHydrationWarnings
.
has
(
msg
))
{
hydrationErrorInfo
=
msg
.
replace
(
'%s'
,
serverContent
)
.
replace
(
'%s'
,
clientContent
)
.
replace
(
'%s'
,
''
)
}
// @ts-expect-error argument is defined
prev
.
apply
(
console
,
arguments
)
}
}
packages/next/src/client/components/react-dev-overlay/internal/helpers/use-error-handler.ts
View file @
9b39c79d
import
{
useEffect
}
from
'react'
import
{
hydrationErrorInfo
}
from
'./hydration-error-info'
export
type
ErrorHandler
=
(
error
:
Error
)
=>
void
...
...
@@ -60,7 +61,11 @@ if (typeof window !== 'undefined') {
'https://nextjs.org/docs/messages/react-hydration-error'
)
)
{
error
.
message
+=
`\n\nSee more info here: https://nextjs.org/docs/messages/react-hydration-error`
if
(
hydrationErrorInfo
)
{
error
.
message
+=
'
\
n
\
n'
+
hydrationErrorInfo
}
error
.
message
+=
'
\
n
\
nSee more info here: https://nextjs.org/docs/messages/react-hydration-error'
}
const
e
=
error
...
...
test/development/acceptance-app/ReactRefreshLogBox.test.ts
View file @
9b39c79d
...
...
@@ -1346,26 +1346,6 @@ for (const variant of ['default', 'turbo']) {
await
cleanup
()
})
test
(
'Hydration errors should get error link'
,
async
()
=>
{
const
{
session
,
browser
,
cleanup
}
=
await
sandbox
(
next
)
await
session
.
patch
(
'app/page.js'
,
`
"use client"
export default function Page() {
return <p>{typeof window === 'undefined' ? "hello" : "world"}</p>
}
`
)
await
browser
.
refresh
()
await
session
.
waitForAndOpenRuntimeError
()
expect
(
await
session
.
getRedboxDescription
()).
toMatchSnapshot
()
await
cleanup
()
})
test
(
'Import trace when module not found in layout'
,
async
()
=>
{
const
{
session
,
cleanup
}
=
await
sandbox
(
next
,
...
...
test/development/acceptance-app/__snapshots__/ReactRefreshLogBox.test.ts.snap
View file @
9b39c79d
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`ReactRefreshLogBox app default Hydration errors should get error link 1`] = `
"Error: Text content does not match server-rendered HTML.
See more info here: https://nextjs.org/docs/messages/react-hydration-error"
`;
exports[`ReactRefreshLogBox app default Import trace when module not found in layout 1`] = `
"./app/module.js:1:0
Module not found: Can't resolve 'non-existing-module'
...
...
test/development/acceptance-app/hydration-error.test.ts
0 → 100644
View file @
9b39c79d
/* eslint-env jest */
import
{
sandbox
}
from
'./helpers'
import
{
createNextDescribe
,
FileRef
}
from
'e2e-utils'
import
path
from
'path'
// https://github.com/facebook/react/blob/main/packages/react-dom/src/__tests__/ReactDOMHydrationDiff-test.js
createNextDescribe
(
'Error Overlay for server components'
,
{
files
:
new
FileRef
(
path
.
join
(
__dirname
,
'fixtures'
,
'default-template'
)),
dependencies
:
{
react
:
'latest'
,
'react-dom'
:
'latest'
,
},
skipStart
:
true
,
},
({
next
})
=>
{
it
(
'should show correct hydration errror when client and server render different text'
,
async
()
=>
{
const
{
cleanup
,
session
}
=
await
sandbox
(
next
,
new
Map
([
[
'app/page.js'
,
`
'use client'
const isClient = typeof window !== 'undefined'
export default function Mismatch() {
return (
<div className="parent">
<main className="child">{isClient ? "client" : "server"}</main>
</div>
);
}
`
,
],
])
)
await
session
.
waitForAndOpenRuntimeError
()
expect
(
await
session
.
getRedboxDescription
()).
toMatchInlineSnapshot
(
`
"Error: Text content does not match server-rendered HTML.
Warning: Text content did not match. Server: \\"server\\" Client: \\"client\\"
See more info here: https://nextjs.org/docs/messages/react-hydration-error"
`
)
await
cleanup
()
})
// TODO: does not throw error, throw to show warning in overlay or remove this test
it
.
skip
(
'should show correct hydration errror when client and server render different html'
,
async
()
=>
{
const
{
cleanup
,
session
}
=
await
sandbox
(
next
,
new
Map
([
[
'app/page.js'
,
`
'use client'
const isClient = typeof window !== 'undefined'
export default function Mismatch() {
return (
<div className="parent">
<main
className="child"
dangerouslySetInnerHTML={{
__html: isClient
? "<span>client</span>"
: "<span>server</span>",
}}
/>
</div>
);
}
`
,
],
])
)
await
session
.
waitForAndOpenRuntimeError
()
expect
(
await
session
.
getRedboxDescription
()).
toMatchInlineSnapshot
()
await
cleanup
()
})
// TODO: does not throw error, throw to show warning in overlay or remove this test
it
.
skip
(
'should show correct hydration errror when client and server render different attributes'
,
async
()
=>
{
const
{
cleanup
,
session
}
=
await
sandbox
(
next
,
new
Map
([
[
'app/page.js'
,
`
'use client'
const isClient = typeof window !== 'undefined'
export default function Mismatch() {
return (
<div className="parent">
<main
className={isClient ? "child client" : "child server"}
dir={isClient ? "ltr" : "rtl"}
/>
</div>
);
}
`
,
],
])
)
await
session
.
waitForAndOpenRuntimeError
()
expect
(
await
session
.
getRedboxDescription
()).
toMatchInlineSnapshot
()
await
cleanup
()
})
// TODO: does not throw error, throw to show warning in overlay or remove this test
it
.
skip
(
'should show correct hydration errror when client renders extra attributes'
,
async
()
=>
{
const
{
cleanup
,
session
}
=
await
sandbox
(
next
,
new
Map
([
[
'app/page.js'
,
`
'use client'
const isClient = typeof window !== 'undefined'
export default function Mismatch() {
return (
<div className="parent">
<main
className="child"
tabIndex={isClient ? 1 : null}
dir={isClient ? "ltr" : null}
/>
</div>
);
}
`
,
],
])
)
await
session
.
waitForAndOpenRuntimeError
()
expect
(
await
session
.
getRedboxDescription
()).
toMatchInlineSnapshot
()
await
cleanup
()
})
// TODO: does not throw error, throw to show warning in overlay or remove this test
it
.
skip
(
'should show correct hydration errror when server renders extra attributes'
,
async
()
=>
{
const
{
cleanup
,
session
}
=
await
sandbox
(
next
,
new
Map
([
[
'app/page.js'
,
`
'use client'
const isClient = typeof window !== 'undefined'
export default function Mismatch() {
return (
<div className="parent">
<main
className="child"
tabIndex={isClient ? null : 1}
dir={isClient ? null : "rtl"}
/>
</div>
);
}
`
,
],
])
)
await
session
.
waitForAndOpenRuntimeError
()
expect
(
await
session
.
getRedboxDescription
()).
toMatchInlineSnapshot
()
await
cleanup
()
})
// TODO: does not throw error, throw to show warning in overlay or remove this test
it
.
skip
(
'should show correct hydration errror when both client and server render extra attributes'
,
async
()
=>
{
const
{
cleanup
,
session
}
=
await
sandbox
(
next
,
new
Map
([
[
'app/page.js'
,
`
'use client'
const isClient = typeof window !== 'undefined'
export default function Mismatch() {
return (
<div className="parent">
<main
className="child"
tabIndex={isClient ? 1 : null}
dir={isClient ? null : "rtl"}
/>
</div>
);
}
`
,
],
])
)
await
session
.
waitForAndOpenRuntimeError
()
expect
(
await
session
.
getRedboxDescription
()).
toMatchInlineSnapshot
()
await
cleanup
()
})
// TODO: does not throw error, throw to show warning in overlay or remove this test
it
.
skip
(
'should show correct hydration errror when client and server render different styles'
,
async
()
=>
{
const
{
cleanup
,
session
}
=
await
sandbox
(
next
,
new
Map
([
[
'app/page.js'
,
`
'use client'
const isClient = typeof window !== 'undefined'
export default function Mismatch() {
return (
<div className="parent">
<main
className="child"
style={{
opacity: isClient ? 1 : 0,
}}
/>
</div>
);
}
`
,
],
])
)
await
session
.
waitForAndOpenRuntimeError
()
expect
(
await
session
.
getRedboxDescription
()).
toMatchInlineSnapshot
()
await
cleanup
()
})
it
(
'should show correct hydration errror when client renders an extra element as only child'
,
async
()
=>
{
const
{
cleanup
,
session
}
=
await
sandbox
(
next
,
new
Map
([
[
'app/page.js'
,
`
'use client'
const isClient = typeof window !== 'undefined'
export default function Mismatch() {
return (
<div className="parent">
{isClient && <main className="only" />}
</div>
);
}
`
,
],
])
)
await
session
.
waitForAndOpenRuntimeError
()
expect
(
await
session
.
getRedboxDescription
()).
toMatchInlineSnapshot
(
`
"Error: Hydration failed because the initial UI does not match what was rendered on the server.
Warning: Expected server HTML to contain a matching <main> in <div>.
See more info here: https://nextjs.org/docs/messages/react-hydration-error"
`
)
await
cleanup
()
})
it
(
'should show correct hydration errror when client renders an extra element in the beginning'
,
async
()
=>
{
const
{
cleanup
,
session
}
=
await
sandbox
(
next
,
new
Map
([
[
'app/page.js'
,
`
'use client'
const isClient = typeof window !== 'undefined'
export default function Mismatch() {
return (
<div className="parent">
{isClient && <header className="1" />}
<main className="2" />
<footer className="3" />
</div>
);
}
`
,
],
])
)
await
session
.
waitForAndOpenRuntimeError
()
expect
(
await
session
.
getRedboxDescription
()).
toMatchInlineSnapshot
(
`
"Error: Hydration failed because the initial UI does not match what was rendered on the server.
Warning: Expected server HTML to contain a matching <header> in <div>.
See more info here: https://nextjs.org/docs/messages/react-hydration-error"
`
)
await
cleanup
()
})
it
(
'should show correct hydration errror when client renders an extra element in the middle'
,
async
()
=>
{
const
{
cleanup
,
session
}
=
await
sandbox
(
next
,
new
Map
([
[
'app/page.js'
,
`
'use client'
const isClient = typeof window !== 'undefined'
export default function Mismatch() {
return (
<div className="parent">
<header className="1" />
{isClient && <main className="2" />}
<footer className="3" />
</div>
);
}
`
,
],
])
)
await
session
.
waitForAndOpenRuntimeError
()
expect
(
await
session
.
getRedboxDescription
()).
toMatchInlineSnapshot
(
`
"Error: Hydration failed because the initial UI does not match what was rendered on the server.
Warning: Expected server HTML to contain a matching <main> in <div>.
See more info here: https://nextjs.org/docs/messages/react-hydration-error"
`
)
await
cleanup
()
})
it
(
'should show correct hydration errror when client renders an extra element in the end'
,
async
()
=>
{
const
{
cleanup
,
session
}
=
await
sandbox
(
next
,
new
Map
([
[
'app/page.js'
,
`
'use client'
const isClient = typeof window !== 'undefined'
export default function Mismatch() {
return (
<div className="parent">
<header className="1" />
<main className="2" />
{isClient && <footer className="3" />}
</div>
);
}
`
,
],
])
)
await
session
.
waitForAndOpenRuntimeError
()
expect
(
await
session
.
getRedboxDescription
()).
toMatchInlineSnapshot
(
`
"Error: Hydration failed because the initial UI does not match what was rendered on the server.
Warning: Expected server HTML to contain a matching <footer> in <div>.
See more info here: https://nextjs.org/docs/messages/react-hydration-error"
`
)
await
cleanup
()
})
it
(
'should show correct hydration errror when client renders an extra text node as only child'
,
async
()
=>
{
const
{
cleanup
,
session
}
=
await
sandbox
(
next
,
new
Map
([
[
'app/page.js'
,
`
'use client'
const isClient = typeof window !== 'undefined'
export default function Mismatch() {
return <div className="parent">{isClient && "only"}</div>;
}
`
,
],
])
)
await
session
.
waitForAndOpenRuntimeError
()
expect
(
await
session
.
getRedboxDescription
()).
toMatchInlineSnapshot
(
`
"Error: Text content does not match server-rendered HTML.
Warning: Text content did not match. Server: \\"\\" Client: \\"only\\"
See more info here: https://nextjs.org/docs/messages/react-hydration-error"
`
)
await
cleanup
()
})
it
(
'should show correct hydration errror when client renders an extra text node in the beginning 1'
,
async
()
=>
{
const
{
cleanup
,
session
}
=
await
sandbox
(
next
,
new
Map
([
[
'app/page.js'
,
`
'use client'
const isClient = typeof window !== 'undefined'
export default function Mismatch() {
return (
<div className="parent">
<header className="1" />
{isClient && "second"}
<footer className="3" />
</div>
);
}
`
,
],
])
)
await
session
.
waitForAndOpenRuntimeError
()
expect
(
await
session
.
getRedboxDescription
()).
toMatchInlineSnapshot
(
`
"Error: Hydration failed because the initial UI does not match what was rendered on the server.
Warning: Expected server HTML to contain a matching text node for \\"second\\" in <div>.
See more info here: https://nextjs.org/docs/messages/react-hydration-error"
`
)
await
cleanup
()
})
it
(
'should show correct hydration errror when client renders an extra text node in the beginning 2'
,
async
()
=>
{
const
{
cleanup
,
session
}
=
await
sandbox
(
next
,
new
Map
([
[
'app/page.js'
,
`
'use client'
const isClient = typeof window !== 'undefined'
export default function Mismatch() {
return (
<div className="parent">
{isClient && "first"}
<main className="2" />
<footer className="3" />
</div>
);
}
`
,
],
])
)
await
session
.
waitForAndOpenRuntimeError
()
expect
(
await
session
.
getRedboxDescription
()).
toMatchInlineSnapshot
(
`
"Error: Hydration failed because the initial UI does not match what was rendered on the server.
Warning: Expected server HTML to contain a matching text node for \\"first\\" in <div>.
See more info here: https://nextjs.org/docs/messages/react-hydration-error"
`
)
await
cleanup
()
})
it
(
'should show correct hydration errror when client renders an extra text node in the end'
,
async
()
=>
{
const
{
cleanup
,
session
}
=
await
sandbox
(
next
,
new
Map
([
[
'app/page.js'
,
`
'use client'
const isClient = typeof window !== 'undefined'
export default function Mismatch() {
return (
<div className="parent">
<header className="1" />
<main className="2" />
{isClient && "third"}
</div>
);
}
`
,
],
])
)
await
session
.
waitForAndOpenRuntimeError
()
expect
(
await
session
.
getRedboxDescription
()).
toMatchInlineSnapshot
(
`
"Error: Hydration failed because the initial UI does not match what was rendered on the server.
Warning: Expected server HTML to contain a matching text node for \\"third\\" in <div>.
See more info here: https://nextjs.org/docs/messages/react-hydration-error"
`
)
await
cleanup
()
})
it
(
'should show correct hydration errror when server renders an extra element as only child'
,
async
()
=>
{
const
{
cleanup
,
session
}
=
await
sandbox
(
next
,
new
Map
([
[
'app/page.js'
,
`
'use client'
const isClient = typeof window !== 'undefined'
export default function Mismatch() {
return (
<div className="parent">
{!isClient && <main className="only" />}
</div>
);
}
`
,
],
])
)
await
session
.
waitForAndOpenRuntimeError
()
expect
(
await
session
.
getRedboxDescription
()).
toMatchInlineSnapshot
(
`
"Error: Hydration failed because the initial UI does not match what was rendered on the server.
Warning: Did not expect server HTML to contain a <main> in <div>.
See more info here: https://nextjs.org/docs/messages/react-hydration-error"
`
)
await
cleanup
()
})
it
(
'should show correct hydration errror when server renders an extra element in the beginning'
,
async
()
=>
{
const
{
cleanup
,
session
}
=
await
sandbox
(
next
,
new
Map
([
[
'app/page.js'
,
`
'use client'
const isClient = typeof window !== 'undefined'
export default function Mismatch() {
return (
<div className="parent">
{!isClient && <header className="1" />}
<main className="2" />
<footer className="3" />
</div>
);
}
`
,
],
])
)
await
session
.
waitForAndOpenRuntimeError
()
expect
(
await
session
.
getRedboxDescription
()).
toMatchInlineSnapshot
(
`
"Error: Hydration failed because the initial UI does not match what was rendered on the server.
Warning: Expected server HTML to contain a matching <main> in <div>.
See more info here: https://nextjs.org/docs/messages/react-hydration-error"
`
)
await
cleanup
()
})
it
(
'should show correct hydration errror when server renders an extra element in the middle'
,
async
()
=>
{
const
{
cleanup
,
session
}
=
await
sandbox
(
next
,
new
Map
([
[
'app/page.js'
,
`
'use client'
const isClient = typeof window !== 'undefined'
export default function Mismatch() {
return (
<div className="parent">
<header className="1" />
{!isClient && <main className="2" />}
<footer className="3" />
</div>
);
}
`
,
],
])
)
await
session
.
waitForAndOpenRuntimeError
()
expect
(
await
session
.
getRedboxDescription
()).
toMatchInlineSnapshot
(
`
"Error: Hydration failed because the initial UI does not match what was rendered on the server.
Warning: Expected server HTML to contain a matching <footer> in <div>.
See more info here: https://nextjs.org/docs/messages/react-hydration-error"
`
)
await
cleanup
()
})
it
(
'should show correct hydration errror when server renders an extra element in the end'
,
async
()
=>
{
const
{
cleanup
,
session
}
=
await
sandbox
(
next
,
new
Map
([
[
'app/page.js'
,
`
'use client'
const isClient = typeof window !== 'undefined'
export default function Mismatch() {
return (
<div className="parent">
<header className="1" />
<main className="2" />
{!isClient && <footer className="3" />}
</div>
);
}
`
,
],
])
)
await
session
.
waitForAndOpenRuntimeError
()
expect
(
await
session
.
getRedboxDescription
()).
toMatchInlineSnapshot
(
`
"Error: Hydration failed because the initial UI does not match what was rendered on the server.
Warning: Did not expect server HTML to contain a <footer> in <div>.
See more info here: https://nextjs.org/docs/messages/react-hydration-error"
`
)
await
cleanup
()
})
it
(
'should show correct hydration errror when server renders an extra text node as only child'
,
async
()
=>
{
const
{
cleanup
,
session
}
=
await
sandbox
(
next
,
new
Map
([
[
'app/page.js'
,
`
'use client'
const isClient = typeof window !== 'undefined'
export default function Mismatch() {
return <div className="parent">{!isClient && "only"}</div>;
}
`
,
],
])
)
await
session
.
waitForAndOpenRuntimeError
()
expect
(
await
session
.
getRedboxDescription
()).
toMatchInlineSnapshot
(
`
"Error: Hydration failed because the initial UI does not match what was rendered on the server.
Warning: Did not expect server HTML to contain the text node \\"only\\" in <div>.
See more info here: https://nextjs.org/docs/messages/react-hydration-error"
`
)
await
cleanup
()
})
it
(
'should show correct hydration errror when server renders an extra text node in the beginning'
,
async
()
=>
{
const
{
cleanup
,
session
}
=
await
sandbox
(
next
,
new
Map
([
[
'app/page.js'
,
`
'use client'
const isClient = typeof window !== 'undefined'
export default function Mismatch() {
return (
<div className="parent">
{!isClient && "first"}
<main className="2" />
<footer className="3" />
</div>
);
}
`
,
],
])
)
await
session
.
waitForAndOpenRuntimeError
()
expect
(
await
session
.
getRedboxDescription
()).
toMatchInlineSnapshot
(
`
"Error: Hydration failed because the initial UI does not match what was rendered on the server.
Warning: Expected server HTML to contain a matching <main> in <div>.
See more info here: https://nextjs.org/docs/messages/react-hydration-error"
`
)
await
cleanup
()
})
it
(
'should show correct hydration errror when server renders an extra text node in the middle'
,
async
()
=>
{
const
{
cleanup
,
session
}
=
await
sandbox
(
next
,
new
Map
([
[
'app/page.js'
,
`
'use client'
const isClient = typeof window !== 'undefined'
export default function Mismatch() {
return (
<div className="parent">
<header className="1" />
{!isClient && "second"}
<footer className="3" />
</div>
);
}
`
,
],
])
)
await
session
.
waitForAndOpenRuntimeError
()
expect
(
await
session
.
getRedboxDescription
()).
toMatchInlineSnapshot
(
`
"Error: Hydration failed because the initial UI does not match what was rendered on the server.
Warning: Expected server HTML to contain a matching <footer> in <div>.
See more info here: https://nextjs.org/docs/messages/react-hydration-error"
`
)
await
cleanup
()
})
it
(
'should show correct hydration errror when server renders an extra text node in the end'
,
async
()
=>
{
const
{
cleanup
,
session
}
=
await
sandbox
(
next
,
new
Map
([
[
'app/page.js'
,
`
'use client'
const isClient = typeof window !== 'undefined'
export default function Mismatch() {
return (
<div className="parent">
<header className="1" />
<main className="2" />
{!isClient && "third"}
</div>
);
}
`
,
],
])
)
await
session
.
waitForAndOpenRuntimeError
()
expect
(
await
session
.
getRedboxDescription
()).
toMatchInlineSnapshot
(
`
"Error: Hydration failed because the initial UI does not match what was rendered on the server.
Warning: Did not expect server HTML to contain the text node \\"third\\" in <div>.
See more info here: https://nextjs.org/docs/messages/react-hydration-error"
`
)
await
cleanup
()
})
it
.
skip
(
'should show correct hydration errror when client renders an extra Suspense node in content mode'
,
async
()
=>
{
const
{
cleanup
,
session
}
=
await
sandbox
(
next
,
new
Map
([
[
'app/page.js'
,
`
'use client'
import React from "react"
const isClient = typeof window !== 'undefined'
export default function Mismatch() {
return (
<div className="parent">
{isClient && (
<React.Suspense fallback={<p>Loading...</p>}>
<main className="only" />
</React.Suspense>
)}
</div>
);
}
`
,
],
])
)
await
session
.
waitForAndOpenRuntimeError
()
expect
(
await
session
.
getRedboxDescription
()).
toMatchInlineSnapshot
()
await
cleanup
()
})
it
.
skip
(
'should show correct hydration errror when server renders an extra Suspense node in content mode'
,
async
()
=>
{
const
{
cleanup
,
session
}
=
await
sandbox
(
next
,
new
Map
([
[
'app/page.js'
,
`
'use client'
import React from "react"
const isClient = typeof window !== 'undefined'
export default function Mismatch() {
return (
<div className="parent">
{!isClient && (
<React.Suspense fallback={<p>Loading...</p>}>
<main className="only" />
</React.Suspense>
)}
</div>
);
}
`
,
],
])
)
await
session
.
waitForAndOpenRuntimeError
()
expect
(
await
session
.
getRedboxDescription
()).
toMatchInlineSnapshot
(
`
"Error: Hydration failed because the initial UI does not match what was rendered on the server.
Warning: Did not expect server HTML to contain a <main> in <div>.
See more info here: https://nextjs.org/docs/messages/react-hydration-error"
`
)
await
cleanup
()
})
it
.
skip
(
'should show correct hydration errror when client renders an extra Suspense node in fallback mode'
,
async
()
=>
{
const
{
cleanup
,
session
}
=
await
sandbox
(
next
,
new
Map
([
[
'app/page.js'
,
`
'use client'
import React from "react"
const isClient = typeof window !== 'undefined'
export default function Mismatch() {
return (
<div className="parent">
{isClient && (
<React.Suspense fallback={<p>Loading...</p>}>
<main className="only" />
<Never />
</React.Suspense>
)}
</div>
);
}
function Never() {
throw new Promise((resolve) => {})
}
`
,
],
])
)
await
session
.
waitForAndOpenRuntimeError
()
expect
(
await
session
.
getRedboxDescription
()).
toMatchInlineSnapshot
()
await
cleanup
()
})
it
.
skip
(
'should show correct hydration errror when server renders an extra Suspense node in fallback mode'
,
async
()
=>
{
const
{
cleanup
,
session
}
=
await
sandbox
(
next
,
new
Map
([
[
'app/page.js'
,
`
'use client'
import React from "react"
const isClient = typeof window !== 'undefined'
export default function Mismatch() {
return (
<div className="parent">
{!isClient && (
<React.Suspense fallback={<p>Loading...</p>}>
<main className="only" />
<Never />
</React.Suspense>
)}
</div>
);
}
function Never() {
throw new Promise((resolve) => {})
}
`
,
],
])
)
await
session
.
waitForAndOpenRuntimeError
()
expect
(
await
session
.
getRedboxDescription
()).
toMatchInlineSnapshot
()
await
cleanup
()
})
it
.
skip
(
'should show correct hydration errror when client renders an extra node inside Suspense content'
,
async
()
=>
{
const
{
cleanup
,
session
}
=
await
sandbox
(
next
,
new
Map
([
[
'app/page.js'
,
`
'use client'
import React from "react"
const isClient = typeof window !== 'undefined'
export default function Mismatch() {
return (
<div className="parent">
<React.Suspense fallback={<p>Loading...</p>}>
<header className="1" />
{isClient && <main className="second" />}
<footer className="3" />
</React.Suspense>
</div>
);
}
`
,
],
])
)
await
session
.
waitForAndOpenRuntimeError
()
expect
(
await
session
.
getRedboxDescription
()).
toMatchInlineSnapshot
()
await
cleanup
()
})
it
.
skip
(
'should show correct hydration errror when server renders an extra node inside Suspense content'
,
async
()
=>
{
const
{
cleanup
,
session
}
=
await
sandbox
(
next
,
new
Map
([
[
'app/page.js'
,
`
'use client'
import React from "react"
const isClient = typeof window !== 'undefined'
export default function Mismatch() {
return (
<div className="parent">
<React.Suspense fallback={<p>Loading...</p>}>
<header className="1" />
{!isClient && <main className="second" />}
<footer className="3" />
</React.Suspense>
</div>
);
}
`
,
],
])
)
await
session
.
waitForAndOpenRuntimeError
()
expect
(
await
session
.
getRedboxDescription
()).
toMatchInlineSnapshot
()
await
cleanup
()
})
it
.
skip
(
'should show correct hydration errror when client renders an extra node inside Suspense fallback'
,
async
()
=>
{
const
{
cleanup
,
session
}
=
await
sandbox
(
next
,
new
Map
([
[
'app/page.js'
,
`
'use client'
import React from "react"
const isClient = typeof window !== 'undefined'
export default function Mismatch() {
return (
<div className="parent">
<React.Suspense
fallback={
<>
<p>Loading...</p>
{isClient && <br />}
</>
}
>
<main className="only" />
<Never />
</React.Suspense>
</div>
);
}
`
,
],
])
)
await
session
.
waitForAndOpenRuntimeError
()
expect
(
await
session
.
getRedboxDescription
()).
toMatchInlineSnapshot
()
await
cleanup
()
})
it
.
skip
(
'should show correct hydration errror when server renders an extra node inside Suspense fallback'
,
async
()
=>
{
const
{
cleanup
,
session
}
=
await
sandbox
(
next
,
new
Map
([
[
'app/page.js'
,
`
'use client'
const isClient = typeof window !== 'undefined'
export default function Mismatch() {
return (
<div className="parent">
<React.Suspense
fallback={
<>
<p>Loading...</p>
{!isClient && <br />}
</>
}
>
<main className="only" />
<Never />
</React.Suspense>
</div>
);
}
`
,
],
])
)
await
session
.
waitForAndOpenRuntimeError
()
expect
(
await
session
.
getRedboxDescription
()).
toMatchInlineSnapshot
()
await
cleanup
()
})
it
(
'should show correct hydration errror when client renders an extra Fragment node'
,
async
()
=>
{
const
{
cleanup
,
session
}
=
await
sandbox
(
next
,
new
Map
([
[
'app/page.js'
,
`
'use client'
const isClient = typeof window !== 'undefined'
export default function Mismatch() {
return (
<div className="parent">
{isClient && (
<>
<header className="1" />
<main className="2" />
<footer className="3" />
</>
)}
</div>
);
}
`
,
],
])
)
await
session
.
waitForAndOpenRuntimeError
()
expect
(
await
session
.
getRedboxDescription
()).
toMatchInlineSnapshot
(
`
"Error: Hydration failed because the initial UI does not match what was rendered on the server.
Warning: Expected server HTML to contain a matching <header> in <div>.
See more info here: https://nextjs.org/docs/messages/react-hydration-error"
`
)
await
cleanup
()
})
it
(
'should show correct hydration errror when server renders an extra Fragment node'
,
async
()
=>
{
const
{
cleanup
,
session
}
=
await
sandbox
(
next
,
new
Map
([
[
'app/page.js'
,
`
'use client'
const isClient = typeof window !== 'undefined'
export default function Mismatch() {
return (
<div className="parent">
{!isClient && (
<>
<header className="1" />
<main className="2" />
<footer className="3" />
</>
)}
</div>
);
}
`
,
],
])
)
await
session
.
waitForAndOpenRuntimeError
()
expect
(
await
session
.
getRedboxDescription
()).
toMatchInlineSnapshot
(
`
"Error: Hydration failed because the initial UI does not match what was rendered on the server.
Warning: Did not expect server HTML to contain a <header> in <div>.
See more info here: https://nextjs.org/docs/messages/react-hydration-error"
`
)
await
cleanup
()
})
it
(
'should show correct hydration errror when client renders an extra node deeper in the tree'
,
async
()
=>
{
const
{
cleanup
,
session
}
=
await
sandbox
(
next
,
new
Map
([
[
'app/page.js'
,
`
'use client'
const isClient = typeof window !== 'undefined'
export default function Mismatch() {
return isClient ? <ProfileSettings /> : <MediaSettings />;
}
function ProfileSettings() {
return (
<div className="parent">
<input />
<Panel type="profile" />
</div>
);
}
function MediaSettings() {
return (
<div className="parent">
<input />
<Panel type="media" />
</div>
);
}
function Panel({ type }) {
return (
<>
<header className="1" />
<main className="2" />
{type === "profile" && <footer className="3" />}
</>
);
}
`
,
],
])
)
await
session
.
waitForAndOpenRuntimeError
()
expect
(
await
session
.
getRedboxDescription
()).
toMatchInlineSnapshot
(
`
"Error: Hydration failed because the initial UI does not match what was rendered on the server.
Warning: Expected server HTML to contain a matching <footer> in <div>.
See more info here: https://nextjs.org/docs/messages/react-hydration-error"
`
)
await
cleanup
()
})
it
(
'should show correct hydration errror when server renders an extra node deeper in the tree'
,
async
()
=>
{
const
{
cleanup
,
session
}
=
await
sandbox
(
next
,
new
Map
([
[
'app/page.js'
,
`
'use client'
const isClient = typeof window !== 'undefined'
export default function Mismatch() {
return isClient ? <ProfileSettings /> : <MediaSettings />;
}
function ProfileSettings() {
return (
<div className="parent">
<input />
<Panel type="profile" />
</div>
);
}
function MediaSettings() {
return (
<div className="parent">
<input />
<Panel type="media" />
</div>
);
}
function Panel({ type }) {
return (
<>
<header className="1" />
<main className="2" />
{type !== "profile" && <footer className="3" />}
</>
);
}
`
,
],
])
)
await
session
.
waitForAndOpenRuntimeError
()
expect
(
await
session
.
getRedboxDescription
()).
toMatchInlineSnapshot
(
`
"Error: Hydration failed because the initial UI does not match what was rendered on the server.
Warning: Did not expect server HTML to contain a <footer> in <div>.
See more info here: https://nextjs.org/docs/messages/react-hydration-error"
`
)
await
cleanup
()
})
}
)
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