Skip to content

Commit 6ef8c20

Browse files
committed
fix(rsc): handle added/removed directive during dev
1 parent 596c76b commit 6ef8c20

File tree

5 files changed

+29
-0
lines changed

5 files changed

+29
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,22 @@ function defineTest(f: Fixture) {
431431
await page.reload()
432432
await expect(page.getByText('ok (test-shared)')).toBeVisible()
433433
})
434+
435+
test('hmr switch server to client', async ({ page }) => {
436+
await page.goto(f.url())
437+
await waitForHydration(page)
438+
439+
const editor = f.createEditor('src/routes/hmr-switch/client.tsx')
440+
editor.edit((s) => `"use client";\n` + s)
441+
})
442+
443+
test('hmr switch client to server', async ({ page }) => {
444+
await page.goto(f.url())
445+
await waitForHydration(page)
446+
447+
const editor = f.createEditor('src/routes/hmr-switch/client.tsx')
448+
editor.edit((s) => s.replace('"use client";', ''))
449+
})
434450
})
435451

436452
test('css @js', async ({ page }) => {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use client'
2+
3+
export function TestHmrMixedClient() {
4+
return <div>test-hmr-mixed-client</div>
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function TestHmrMixedServer() {
2+
return <div>test-hmr-mixed-server</div>
3+
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ import { TestHmrSharedAtomic } from './hmr-shared/atomic/server'
3838
import { TestCssQueries } from './css-queries/server'
3939
import { TestImportMetaGlob } from './import-meta-glob/server'
4040
import { TestAssetsServer } from './assets/server'
41+
import { TestHmrMixedServer } from './hmr-switch/server'
42+
import { TestHmrMixedClient } from './hmr-switch/client'
4143

4244
export function Root(props: { url: URL }) {
4345
return (
@@ -65,6 +67,8 @@ export function Root(props: { url: URL }) {
6567
<TestHmrSharedServer />
6668
<TestHmrSharedClient />
6769
<TestHmrSharedAtomic />
70+
<TestHmrMixedServer />
71+
<TestHmrMixedClient />
6872
<TestTemporaryReference />
6973
<TestServerActionError />
7074
<TestReplayConsoleLogs url={props.url} />

packages/plugin-rsc/src/plugin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,7 @@ function vitePluginUseClient(
10831083
})
10841084
if (!result) return
10851085
const { output, exportNames } = result
1086+
// TODO
10861087
manager.clientReferenceMetaMap[id] = {
10871088
importId,
10881089
referenceKey,

0 commit comments

Comments
 (0)