Skip to content

Commit 3309b2e

Browse files
committed
test: add atomic hmr failure example
1 parent 2f9fc1c commit 3309b2e

File tree

5 files changed

+78
-0
lines changed

5 files changed

+78
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use client'
2+
3+
import React from 'react'
4+
import { testShared } from './shared'
5+
6+
export function TestClient({
7+
testSharedFromServer,
8+
}: {
9+
testSharedFromServer: string
10+
}) {
11+
React.useEffect(() => {
12+
console.log({ testShared, testSharedFromServer })
13+
if (testShared !== testSharedFromServer) {
14+
throw new Error(
15+
`Mismatch: ${JSON.stringify({ testShared, testSharedFromServer })}`,
16+
)
17+
}
18+
}, [testShared, testSharedFromServer])
19+
20+
return <>ok ({testShared})</>
21+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
'use client'
2+
3+
import * as React from 'react'
4+
5+
interface Props {
6+
children?: React.ReactNode
7+
}
8+
9+
interface State {
10+
error: Error | null
11+
}
12+
13+
export default class ErrorBoundary extends React.Component<Props, State> {
14+
constructor(props: Props) {
15+
super(props)
16+
this.state = { error: null }
17+
}
18+
19+
static getDerivedStateFromError(error: Error) {
20+
return { error }
21+
}
22+
23+
render() {
24+
if (this.state.error) {
25+
return (
26+
<span>
27+
ERROR
28+
<button
29+
onClick={() => {
30+
this.setState({ error: null })
31+
}}
32+
>
33+
Reset
34+
</button>
35+
</span>
36+
)
37+
}
38+
return this.props.children
39+
}
40+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { TestClient } from './client'
2+
import ErrorBoundary from './error-boundary'
3+
import { testShared } from './shared'
4+
5+
export function TestHmrSharedAtomic() {
6+
return (
7+
<div>
8+
test-hmr-shared-atomic:{' '}
9+
<ErrorBoundary>
10+
<TestClient testSharedFromServer={testShared} />
11+
</ErrorBoundary>
12+
</div>
13+
)
14+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const testShared = 'test-shared'

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { TestTransitiveCjsClient } from './deps/transitive-cjs/client'
3434
import TestDepCssInServer from '@vitejs/test-dep-css-in-server/server'
3535
import { TestHmrSharedServer } from './hmr-shared/server'
3636
import { TestHmrSharedClient } from './hmr-shared/client'
37+
import { TestHmrSharedAtomic } from './hmr-shared/atomic/server'
3738

3839
export function Root(props: { url: URL }) {
3940
return (
@@ -60,6 +61,7 @@ export function Root(props: { url: URL }) {
6061
<TestHmrClientDep />
6162
<TestHmrSharedServer />
6263
<TestHmrSharedClient />
64+
<TestHmrSharedAtomic />
6365
<TestTemporaryReference />
6466
<TestServerActionError />
6567
<TestReplayConsoleLogs url={props.url} />

0 commit comments

Comments
 (0)