Skip to content

Commit d654680

Browse files
committed
Merge branch 'navigation-vite' of https://github.com/grahammendick/vite-plugin-react into navigation-vite
2 parents 8a8b362 + 3ad94b4 commit d654680

File tree

22 files changed

+119
-41
lines changed

22 files changed

+119
-41
lines changed

packages/plugin-rsc/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This package provides [React Server Components](https://react.dev/reference/rsc/
1111

1212
## Getting Started
1313

14-
You can start a project by copying an example locally by:
14+
You can create a starter project by:
1515

1616
```sh
1717
npx degit vitejs/vite-plugin-react/packages/plugin-rsc/examples/starter my-app

packages/plugin-rsc/e2e/fixture.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,11 @@ export async function setupInlineFixture(options: {
213213

214214
// write additional files
215215
if (options.files) {
216-
for (const [filename, contents] of Object.entries(options.files)) {
216+
for (let [filename, contents] of Object.entries(options.files)) {
217217
let filepath = path.join(options.dest, filename)
218218
fs.mkdirSync(path.dirname(filepath), { recursive: true })
219219
// strip indent
220+
contents = contents.replace(/^\n/, '')
220221
const indent = contents.match(/^\s*/)?.[0] ?? ''
221222
const strippedContents = contents
222223
.split('\n')

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

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,66 @@ test.describe(() => {
143143
})
144144
})
145145

146+
test.describe(() => {
147+
const root = 'examples/e2e/temp/module-runner-hmr-false'
148+
149+
test.beforeAll(async () => {
150+
await setupInlineFixture({
151+
src: 'examples/starter',
152+
dest: root,
153+
files: {
154+
'vite.config.ts': /* js */ `
155+
import rsc from '@vitejs/plugin-rsc'
156+
import react from '@vitejs/plugin-react'
157+
import { defineConfig, createRunnableDevEnvironment } from 'vite'
158+
159+
export default defineConfig({
160+
plugins: [
161+
react(),
162+
rsc({
163+
entries: {
164+
client: './src/framework/entry.browser.tsx',
165+
ssr: './src/framework/entry.ssr.tsx',
166+
rsc: './src/framework/entry.rsc.tsx',
167+
}
168+
}),
169+
],
170+
environments: {
171+
ssr: {
172+
dev: {
173+
createEnvironment(name, config) {
174+
return createRunnableDevEnvironment(name, config, {
175+
runnerOptions: {
176+
hmr: false,
177+
},
178+
})
179+
},
180+
},
181+
},
182+
rsc: {
183+
dev: {
184+
createEnvironment(name, config) {
185+
return createRunnableDevEnvironment(name, config, {
186+
runnerOptions: {
187+
hmr: false,
188+
},
189+
})
190+
},
191+
},
192+
},
193+
},
194+
})
195+
`,
196+
},
197+
})
198+
})
199+
200+
test.describe('dev-module-runner-hmr-false', () => {
201+
const f = useFixture({ root, mode: 'dev' })
202+
defineTest(f)
203+
})
204+
})
205+
146206
function defineTest(f: Fixture, variant?: 'no-ssr') {
147207
const waitForHydration: typeof waitForHydration_ = (page) =>
148208
waitForHydration_(page, variant === 'no-ssr' ? '#root' : 'body')

packages/plugin-rsc/examples/basic/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"@vitejs/test-dep-client-in-server2": "file:./test-dep/client-in-server2",
2626
"@vitejs/test-dep-server-in-client": "file:./test-dep/server-in-client",
2727
"@vitejs/test-dep-server-in-server": "file:./test-dep/server-in-server",
28+
"rsc-html-stream": "^0.0.7",
2829
"tailwindcss": "^4.1.11",
2930
"vite": "^7.0.4",
3031
"vite-plugin-inspect": "^11.3.0",

packages/plugin-rsc/examples/basic/src/framework/entry.browser.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as ReactClient from '@vitejs/plugin-rsc/browser'
2-
import { getRscStreamFromHtml } from '@vitejs/plugin-rsc/rsc-html-stream/browser'
32
import React from 'react'
43
import * as ReactDOMClient from 'react-dom/client'
4+
import { rscStream } from 'rsc-html-stream/client'
55
import type { RscPayload } from './entry.rsc'
66

77
async function main() {
@@ -12,7 +12,7 @@ async function main() {
1212
// deserialize RSC stream back to React VDOM for CSR
1313
const initialPayload = await ReactClient.createFromReadableStream<RscPayload>(
1414
// initial RSC stream is injected in SSR stream as <script>...FLIGHT_DATA...</script>
15-
getRscStreamFromHtml(),
15+
rscStream,
1616
)
1717

1818
// browser root component to (re-)render RSC payload as state

packages/plugin-rsc/examples/basic/src/framework/entry.ssr.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { injectRscStreamToHtml } from '@vitejs/plugin-rsc/rsc-html-stream/ssr' // helper API
21
import * as ReactClient from '@vitejs/plugin-rsc/ssr' // RSC API
32
import React from 'react'
43
import type { ReactFormState } from 'react-dom/client'
54
import * as ReactDOMServer from 'react-dom/server.edge'
5+
import { injectRSCPayload } from 'rsc-html-stream/server'
66
import type { RscPayload } from './entry.rsc'
77

88
export async function renderHTML(
@@ -42,8 +42,9 @@ export async function renderHTML(
4242
let responseStream: ReadableStream<Uint8Array> = htmlStream
4343
if (!options?.debugNojs) {
4444
// initial RSC stream is injected in HTML stream as <script>...FLIGHT_DATA...</script>
45+
// using utility made by devongovett https://github.com/devongovett/rsc-html-stream
4546
responseStream = responseStream.pipeThrough(
46-
injectRscStreamToHtml(rscStream2, {
47+
injectRSCPayload(rscStream2, {
4748
nonce: options?.nonce,
4849
}),
4950
)

packages/plugin-rsc/examples/navigation/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@vitejs/plugin-rsc-examples-basic",
2+
"name": "@vitejs/plugin-rsc-examples-navigation",
33
"private": true,
44
"license": "MIT",
55
"type": "module",

packages/plugin-rsc/examples/no-ssr/src/framework/entry.rsc.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ export default async function handler(request: Request): Promise<Response> {
3232
}
3333
}
3434

35-
const rscStream = ReactServer.renderToReadableStream<RscPayload>({
36-
root: <Root />,
37-
returnValue,
38-
formState,
39-
})
35+
const rscPayload: RscPayload = { root: <Root />, formState, returnValue }
36+
const rscOptions = { temporaryReferences }
37+
const rscStream = ReactServer.renderToReadableStream<RscPayload>(
38+
rscPayload,
39+
rscOptions,
40+
)
4041

4142
return new Response(rscStream, {
4243
headers: {

packages/plugin-rsc/examples/ssg/src/framework/entry.browser.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as ReactClient from '@vitejs/plugin-rsc/browser'
2-
import { getRscStreamFromHtml } from '@vitejs/plugin-rsc/rsc-html-stream/browser'
32
import React from 'react'
43
import ReactDomClient from 'react-dom/client'
4+
import { rscStream } from 'rsc-html-stream/client'
55
import { RSC_POSTFIX, type RscPayload } from './shared'
66

77
async function hydrate(): Promise<void> {
@@ -12,9 +12,8 @@ async function hydrate(): Promise<void> {
1212
setPayload(payload)
1313
}
1414

15-
const initialPayload = await ReactClient.createFromReadableStream<RscPayload>(
16-
getRscStreamFromHtml(),
17-
)
15+
const initialPayload =
16+
await ReactClient.createFromReadableStream<RscPayload>(rscStream)
1817

1918
let setPayload: (v: RscPayload) => void
2019

packages/plugin-rsc/examples/ssg/src/framework/entry.ssr.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { injectRscStreamToHtml } from '@vitejs/plugin-rsc/rsc-html-stream/ssr'
21
import * as ReactClient from '@vitejs/plugin-rsc/ssr'
32
import React from 'react'
43
import * as ReactDomServer from 'react-dom/server.edge'
4+
import { injectRSCPayload } from 'rsc-html-stream/server'
55
import type { RscPayload } from './shared'
66

77
export async function renderHtml(rscStream: ReadableStream<Uint8Array>) {
@@ -24,6 +24,6 @@ export async function renderHtml(rscStream: ReadableStream<Uint8Array>) {
2424
await htmlStream.allReady
2525

2626
let responseStream: ReadableStream<Uint8Array> = htmlStream
27-
responseStream = responseStream.pipeThrough(injectRscStreamToHtml(rscStream2))
27+
responseStream = responseStream.pipeThrough(injectRSCPayload(rscStream2))
2828
return responseStream
2929
}

0 commit comments

Comments
 (0)