Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3c9ec2f

Browse files
Merge branch 'main' into chore-rsc-nightly
2 parents 8edd8a7 + ce84449 commit 3c9ec2f

File tree

5 files changed

+49
-1
lines changed

5 files changed

+49
-1
lines changed

‎packages/plugin-rsc/e2e/basic.test.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { type Fixture, setupIsolatedFixture, useFixture } from './fixture'
55
import { expectNoReload, testNoJs, waitForHydration } from './helper'
66

77
// TODO: parallel?
8+
// TODO: all tests don't need to be tested in all variants?
89

910
test.describe('dev-default', () => {
1011
const f = useFixture({ root: 'examples/basic', mode: 'dev' })
@@ -928,4 +929,27 @@ function defineTest(f: Fixture) {
928929
'(actionCount: 5, innerFnCount: 3)',
929930
)
930931
})
932+
933+
test('hydration mismatch', async ({ page }) => {
934+
const errors: Error[] = []
935+
page.on('pageerror', (error) => {
936+
errors.push(error)
937+
})
938+
await page.goto(f.url('/?test-hydration-mismatch'))
939+
await waitForHydration(page)
940+
expect(errors).toMatchObject([
941+
{
942+
message: expect.stringContaining(
943+
f.mode === 'dev'
944+
? `Hydration failed because the server rendered HTML didn't match the client.`
945+
: `Minified React error #418`,
946+
),
947+
},
948+
])
949+
950+
errors.length = 0
951+
await page.goto(f.url())
952+
await waitForHydration(page)
953+
expect(errors).toEqual([])
954+
})
931955
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
'use client'
2+
3+
export function Mismatch() {
4+
const value = typeof window !== 'undefined' ? 'browser' : 'ssr'
5+
return <>[{value}]</>
6+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Mismatch } from './client'
2+
3+
export function TestHydrationMismatch(props: { url: URL }) {
4+
const show = props.url.searchParams.has('test-hydration-mismatch')
5+
return (
6+
<div>
7+
<span>test-hydration-mismatch</span>{' '}
8+
{show ? (
9+
<a href="?">hide</a>
10+
) : (
11+
<a href="?test-hydration-mismatch">show</a>
12+
)}{' '}
13+
{show && <Mismatch />}
14+
</div>
15+
)
16+
}

‎packages/plugin-rsc/examples/basic/src/routes/root.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { TestTailwindClient } from './tailwind/client'
2727
import { TestTailwindServer } from './tailwind/server'
2828
import { TestTemporaryReference } from './temporary-reference/client'
2929
import { TestUseCache } from './use-cache/server'
30+
import { TestHydrationMismatch } from './hydration-mismatch/server'
3031

3132
export function Root(props: { url: URL }) {
3233
return (
@@ -47,6 +48,7 @@ export function Root(props: { url: URL }) {
4748
<TestCssClientNoSsr url={props.url} />
4849
<TestTailwindClient />
4950
<TestTailwindServer />
51+
<TestHydrationMismatch url={props.url} />
5052
<TestHmrClientDep />
5153
<TestTemporaryReference />
5254
<TestServerActionError />

‎packages/plugin-rsc/examples/basic/src/styles.css‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ input {
99
}
1010

1111
a {
12-
@apply text-gray-500 underline hover:text-gray-700;
12+
@apply text-gray-500 underline hover:text-gray-700 cursor-pointer;
1313
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /