Skip to content

Commit 596c76b

Browse files
authored
fix(rsc): isolate plugin state per plugin instance (#747)
1 parent 1ab2666 commit 596c76b

File tree

2 files changed

+162
-72
lines changed

2 files changed

+162
-72
lines changed

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { expect, test } from '@playwright/test'
22
import { setupInlineFixture, useFixture, type Fixture } from './fixture'
33
import { defineStarterTest } from './starter'
44
import { expectNoPageError, waitForHydration } from './helper'
5+
import { x } from 'tinyexec'
56

67
test.describe('dev-default', () => {
78
const f = useFixture({ root: 'examples/starter', mode: 'dev' })
@@ -94,3 +95,49 @@ test.describe('duplicate loadCss', () => {
9495
})
9596
}
9697
})
98+
99+
test.describe('isolated build', () => {
100+
const root = 'examples/e2e/temp/isolated-build'
101+
102+
test.beforeAll(async () => {
103+
// build twice programmatically to verify two plugin states are independent
104+
async function testFn() {
105+
const vite = await import('vite')
106+
const fs = await import('node:fs')
107+
108+
console.log('======== first build ========')
109+
const builder1 = await vite.createBuilder()
110+
await builder1.buildApp()
111+
112+
// edit files to remove client references
113+
fs.rmSync(`src/client.tsx`)
114+
fs.writeFileSync(
115+
`src/root.tsx`,
116+
fs
117+
.readFileSync(`src/root.tsx`, 'utf-8')
118+
.replace(`import { ClientCounter } from './client.tsx'`, '')
119+
.replace(`<ClientCounter />`, ''),
120+
)
121+
122+
console.log('======== second build ========')
123+
const builder2 = await vite.createBuilder()
124+
await builder2.buildApp()
125+
}
126+
127+
await setupInlineFixture({
128+
src: 'examples/starter',
129+
dest: root,
130+
files: {
131+
'test.js': `await (${testFn.toString()})();\n`,
132+
},
133+
})
134+
})
135+
136+
test('build', async () => {
137+
const result = await x('node', ['./test.js'], {
138+
nodeOptions: { cwd: root },
139+
})
140+
expect(result.stderr).not.toContain('Build failed')
141+
expect(result.exitCode).toBe(0)
142+
})
143+
})

0 commit comments

Comments
 (0)