File tree Expand file tree Collapse file tree 16 files changed +37
-21
lines changed Expand file tree Collapse file tree 16 files changed +37
-21
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ This package provides [React Server Components](https://react.dev/reference/rsc/
11
11
12
12
## Getting Started
13
13
14
- You can start a project by copying an example locally by:
14
+ You can create a starter project by:
15
15
16
16
``` sh
17
17
npx degit vitejs/vite-plugin-react/packages/plugin-rsc/examples/starter my-app
Original file line number Diff line number Diff line change 25
25
"@vitejs/test-dep-client-in-server2" : " file:./test-dep/client-in-server2" ,
26
26
"@vitejs/test-dep-server-in-client" : " file:./test-dep/server-in-client" ,
27
27
"@vitejs/test-dep-server-in-server" : " file:./test-dep/server-in-server" ,
28
+ "rsc-html-stream" : " ^0.0.7" ,
28
29
"tailwindcss" : " ^4.1.11" ,
29
30
"vite" : " ^7.0.4" ,
30
31
"vite-plugin-inspect" : " ^11.3.0" ,
Original file line number Diff line number Diff line change 1
1
import * as ReactClient from '@vitejs/plugin-rsc/browser'
2
- import { getRscStreamFromHtml } from '@vitejs/plugin-rsc/rsc-html-stream/browser'
3
2
import React from 'react'
4
3
import * as ReactDOMClient from 'react-dom/client'
4
+ import { rscStream } from 'rsc-html-stream/client'
5
5
import type { RscPayload } from './entry.rsc'
6
6
7
7
async function main ( ) {
@@ -12,7 +12,7 @@ async function main() {
12
12
// deserialize RSC stream back to React VDOM for CSR
13
13
const initialPayload = await ReactClient . createFromReadableStream < RscPayload > (
14
14
// initial RSC stream is injected in SSR stream as <script>...FLIGHT_DATA...</script>
15
- getRscStreamFromHtml ( ) ,
15
+ rscStream ,
16
16
)
17
17
18
18
// browser root component to (re-)render RSC payload as state
Original file line number Diff line number Diff line change 1
- import { injectRscStreamToHtml } from '@vitejs/plugin-rsc/rsc-html-stream/ssr' // helper API
2
1
import * as ReactClient from '@vitejs/plugin-rsc/ssr' // RSC API
3
2
import React from 'react'
4
3
import type { ReactFormState } from 'react-dom/client'
5
4
import * as ReactDOMServer from 'react-dom/server.edge'
5
+ import { injectRSCPayload } from 'rsc-html-stream/server'
6
6
import type { RscPayload } from './entry.rsc'
7
7
8
8
export async function renderHTML (
@@ -42,8 +42,9 @@ export async function renderHTML(
42
42
let responseStream : ReadableStream < Uint8Array > = htmlStream
43
43
if ( ! options ?. debugNojs ) {
44
44
// 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
45
46
responseStream = responseStream . pipeThrough (
46
- injectRscStreamToHtml ( rscStream2 , {
47
+ injectRSCPayload ( rscStream2 , {
47
48
nonce : options ?. nonce ,
48
49
} ) ,
49
50
)
Original file line number Diff line number Diff line change 1
1
import * as ReactClient from '@vitejs/plugin-rsc/browser'
2
- import { getRscStreamFromHtml } from '@vitejs/plugin-rsc/rsc-html-stream/browser'
3
2
import React from 'react'
4
3
import ReactDomClient from 'react-dom/client'
4
+ import { rscStream } from 'rsc-html-stream/client'
5
5
import { RSC_POSTFIX , type RscPayload } from './shared'
6
6
7
7
async function hydrate ( ) : Promise < void > {
@@ -12,9 +12,8 @@ async function hydrate(): Promise<void> {
12
12
setPayload ( payload )
13
13
}
14
14
15
- const initialPayload = await ReactClient . createFromReadableStream < RscPayload > (
16
- getRscStreamFromHtml ( ) ,
17
- )
15
+ const initialPayload =
16
+ await ReactClient . createFromReadableStream < RscPayload > ( rscStream )
18
17
19
18
let setPayload : ( v : RscPayload ) => void
20
19
Original file line number Diff line number Diff line change 1
- import { injectRscStreamToHtml } from '@vitejs/plugin-rsc/rsc-html-stream/ssr'
2
1
import * as ReactClient from '@vitejs/plugin-rsc/ssr'
3
2
import React from 'react'
4
3
import * as ReactDomServer from 'react-dom/server.edge'
4
+ import { injectRSCPayload } from 'rsc-html-stream/server'
5
5
import type { RscPayload } from './shared'
6
6
7
7
export async function renderHtml ( rscStream : ReadableStream < Uint8Array > ) {
@@ -24,6 +24,6 @@ export async function renderHtml(rscStream: ReadableStream<Uint8Array>) {
24
24
await htmlStream . allReady
25
25
26
26
let responseStream : ReadableStream < Uint8Array > = htmlStream
27
- responseStream = responseStream . pipeThrough ( injectRscStreamToHtml ( rscStream2 ) )
27
+ responseStream = responseStream . pipeThrough ( injectRSCPayload ( rscStream2 ) )
28
28
return responseStream
29
29
}
Original file line number Diff line number Diff line change 1
1
import * as ReactClient from '@vitejs/plugin-rsc/browser'
2
- import { getRscStreamFromHtml } from '@vitejs/plugin-rsc/rsc-html-stream/browser'
3
2
import React from 'react'
4
3
import * as ReactDOMClient from 'react-dom/client'
4
+ import { rscStream } from 'rsc-html-stream/client'
5
5
import type { RscPayload } from './entry.rsc'
6
6
7
7
async function main ( ) {
@@ -12,7 +12,7 @@ async function main() {
12
12
// deserialize RSC stream back to React VDOM for CSR
13
13
const initialPayload = await ReactClient . createFromReadableStream < RscPayload > (
14
14
// initial RSC stream is injected in SSR stream as <script>...FLIGHT_DATA...</script>
15
- getRscStreamFromHtml ( ) ,
15
+ rscStream ,
16
16
)
17
17
18
18
// browser root component to (re-)render RSC payload as state
Original file line number Diff line number Diff line change 1
- import { injectRscStreamToHtml } from '@vitejs/plugin-rsc/rsc-html-stream/ssr' // helper API
2
1
import * as ReactClient from '@vitejs/plugin-rsc/ssr' // RSC API
3
2
import React from 'react'
4
3
import type { ReactFormState } from 'react-dom/client'
5
4
import * as ReactDOMServer from 'react-dom/server.edge'
5
+ import { injectRSCPayload } from 'rsc-html-stream/server'
6
6
import type { RscPayload } from './entry.rsc'
7
7
8
8
export type RenderHTML = typeof renderHTML
@@ -45,7 +45,7 @@ export async function renderHTML(
45
45
if ( ! options ?. debugNojs ) {
46
46
// initial RSC stream is injected in HTML stream as <script>...FLIGHT_DATA...</script>
47
47
responseStream = responseStream . pipeThrough (
48
- injectRscStreamToHtml ( rscStream2 , {
48
+ injectRSCPayload ( rscStream2 , {
49
49
nonce : options ?. nonce ,
50
50
} ) ,
51
51
)
Original file line number Diff line number Diff line change @@ -35,6 +35,9 @@ export default defineConfig({
35
35
platform : 'neutral' ,
36
36
} ,
37
37
} ,
38
+ optimizeDeps : {
39
+ include : [ 'turbo-stream' ] ,
40
+ } ,
38
41
} ,
39
42
ssr : {
40
43
keepProcessEnv : false ,
@@ -43,6 +46,9 @@ export default defineConfig({
43
46
// wrangler can deploy self-contained `dist/rsc`
44
47
outDir : './dist/rsc/ssr' ,
45
48
} ,
49
+ resolve : {
50
+ noExternal : true ,
51
+ } ,
46
52
} ,
47
53
} ,
48
54
} )
Original file line number Diff line number Diff line change @@ -24,11 +24,11 @@ See [`@vitejs/plugin-rsc`](https://github.com/vitejs/vite-plugin-react/tree/main
24
24
- ` import.meta.viteRsc.loadModule `
25
25
- [ ` ./src/framework/entry.ssr.tsx ` ] ( ./src/framework/entry.ssr.tsx )
26
26
- ` @vitejs/plugin-rsc/ssr `
27
- - ` @vitejs/plugin-rsc/rsc-html-stream/ssr `
28
27
- ` import.meta.viteRsc.loadBootstrapScriptContent `
28
+ - ` rsc-html-stream/server `
29
29
- [ ` ./src/framework/entry.browser.tsx ` ] ( ./src/framework/entry.browser.tsx )
30
30
- ` @vitejs/plugin-rsc/browser `
31
- - ` @vitejs/plugin- rsc/rsc -html-stream/browser `
31
+ - ` rsc-html-stream/client `
32
32
33
33
## Notes
34
34
You can’t perform that action at this time.
0 commit comments