Skip to content

Commit 8e0e8b6

Browse files
authored
chore(rsc): deprecate rsc-html-stream re-exports (#602)
1 parent 7223093 commit 8e0e8b6

File tree

16 files changed

+37
-21
lines changed

16 files changed

+37
-21
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/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/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
}

packages/plugin-rsc/examples/starter-cf-single/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/starter-cf-single/src/framework/entry.ssr.tsx

Lines changed: 2 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 type RenderHTML = typeof renderHTML
@@ -45,7 +45,7 @@ export async function renderHTML(
4545
if (!options?.debugNojs) {
4646
// initial RSC stream is injected in HTML stream as <script>...FLIGHT_DATA...</script>
4747
responseStream = responseStream.pipeThrough(
48-
injectRscStreamToHtml(rscStream2, {
48+
injectRSCPayload(rscStream2, {
4949
nonce: options?.nonce,
5050
}),
5151
)

packages/plugin-rsc/examples/starter-cf-single/vite.config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ export default defineConfig({
3535
platform: 'neutral',
3636
},
3737
},
38+
optimizeDeps: {
39+
include: ['turbo-stream'],
40+
},
3841
},
3942
ssr: {
4043
keepProcessEnv: false,
@@ -43,6 +46,9 @@ export default defineConfig({
4346
// wrangler can deploy self-contained `dist/rsc`
4447
outDir: './dist/rsc/ssr',
4548
},
49+
resolve: {
50+
noExternal: true,
51+
},
4652
},
4753
},
4854
})

packages/plugin-rsc/examples/starter/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ See [`@vitejs/plugin-rsc`](https://github.com/vitejs/vite-plugin-react/tree/main
2424
- `import.meta.viteRsc.loadModule`
2525
- [`./src/framework/entry.ssr.tsx`](./src/framework/entry.ssr.tsx)
2626
- `@vitejs/plugin-rsc/ssr`
27-
- `@vitejs/plugin-rsc/rsc-html-stream/ssr`
2827
- `import.meta.viteRsc.loadBootstrapScriptContent`
28+
- `rsc-html-stream/server`
2929
- [`./src/framework/entry.browser.tsx`](./src/framework/entry.browser.tsx)
3030
- `@vitejs/plugin-rsc/browser`
31-
- `@vitejs/plugin-rsc/rsc-html-stream/browser`
31+
- `rsc-html-stream/client`
3232

3333
## Notes
3434

0 commit comments

Comments
 (0)