Skip to content

Commit 16ffa03

Browse files
authored
Add extensive hydration error test suite for Pages router (#70342)
1 parent fb4bf4a commit 16ffa03

File tree

6 files changed

+887
-60
lines changed

6 files changed

+887
-60
lines changed

test/development/acceptance-app/hydration-error.test.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,49 @@ import { getRedboxTotalErrorCount } from 'next-test-utils'
77

88
// https://github.com/facebook/react/blob/main/packages/react-dom/src/__tests__/ReactDOMHydrationDiff-test.js used as a reference
99

10-
describe('Error overlay for hydration errors', () => {
10+
describe('Error overlay for hydration errors in App router', () => {
1111
const { next, isTurbopack } = nextTestSetup({
1212
files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')),
1313
skipStart: true,
1414
})
1515

16+
it('includes a React docs link when hydration error does occur', async () => {
17+
const { browser } = await sandbox(
18+
next,
19+
new Map([
20+
[
21+
'app/page.js',
22+
outdent`
23+
'use client'
24+
const isClient = typeof window !== 'undefined'
25+
export default function Mismatch() {
26+
return (
27+
<div className="parent">
28+
<main className="child">{isClient ? "client" : "server"}</main>
29+
</div>
30+
);
31+
}
32+
`,
33+
],
34+
]),
35+
'/',
36+
{ pushErrorAsConsoleLog: true }
37+
)
38+
39+
const logs = await browser.log()
40+
expect(logs).toEqual(
41+
expect.arrayContaining([
42+
{
43+
// TODO: Should probably link to https://nextjs.org/docs/messages/react-hydration-error instead.
44+
message: expect.stringContaining(
45+
'https://react.dev/link/hydration-mismatch'
46+
),
47+
source: 'error',
48+
},
49+
])
50+
)
51+
})
52+
1653
it('should show correct hydration error when client and server render different text', async () => {
1754
const { cleanup, session, browser } = await sandbox(
1855
next,

0 commit comments

Comments
 (0)