File tree Expand file tree Collapse file tree 6 files changed +21
-22
lines changed
packages/plugin-rsc/examples/browser-mode Expand file tree Collapse file tree 6 files changed +21
-22
lines changed Original file line number Diff line number Diff line change 44 < meta charset ="UTF-8 " />
55 < meta name ="viewport " content ="width=device-width, initial-scale=1 " />
66 < link rel ="icon " type ="image/svg+xml " href ="/vite.svg " />
7- < script async type ="module " src ="/src/framework/main .tsx "> </ script >
7+ < script async type ="module " src ="/src/framework/server .tsx "> </ script >
88 </ head >
99 < body >
1010 < div id ="root "> </ div >
Original file line number Diff line number Diff line change 66 "type" : " module" ,
77 "scripts" : {
88 "dev" : " vite" ,
9- "build" : " vite build" ,
10- "preview" : " vite preview"
9+ "build" : " false && vite build" ,
10+ "preview" : " false && vite preview"
1111 },
1212 "dependencies" : {
1313 "@vitejs/plugin-rsc" : " latest" ,
Original file line number Diff line number Diff line change @@ -3,6 +3,12 @@ import * as ReactDOMClient from 'react-dom/client'
33import * as ReactClient from '@vitejs/plugin-rsc/react/browser'
44import type { RscPayload } from './server'
55
6+ export function initialize ( ) {
7+ ReactClient . setRequireModule ( {
8+ load : ( id ) => import ( /* @vite -ignore */ id ) ,
9+ } )
10+ }
11+
612export function render ( rscStream : ReadableStream < Uint8Array > ) {
713 let rscPaylod : Promise < RscPayload >
814
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1- import { renderToReadableStream } from '@vitejs/plugin-rsc/react/rsc'
1+ import {
2+ renderToReadableStream ,
3+ setRequireModule ,
4+ } from '@vitejs/plugin-rsc/react/rsc'
25import type React from 'react'
36import { ESModulesEvaluator , ModuleRunner } from 'vite/module-runner'
7+ import { Root } from '../root'
48
59export type RscPayload = {
610 root : React . ReactNode
711}
812
913async function main ( ) {
10- const rscRoot = (
11- < div >
12- < h1 > RSC Browser Mode</ h1 >
13- </ div >
14- )
14+ setRequireModule ( { load : ( id ) => import ( /* @vite -ignore */ id ) } )
15+
1516 const rscStream = renderToReadableStream < RscPayload > ( {
16- root : rscRoot ,
17+ root : < Root /> ,
1718 } )
1819
1920 const clientRunner = createClientRunner ( )
2021 const clientEntry = await clientRunner . import < typeof import ( './client' ) > (
2122 '/src/framework/client.tsx' ,
2223 )
24+ clientEntry . initialize ( )
2325 clientEntry . render ( rscStream )
2426}
2527
Original file line number Diff line number Diff line change 11import './index.css' // css import is automatically injected in exported server components
22import viteLogo from '/vite.svg'
3- import { getServerCounter , updateServerCounter } from './action.tsx'
3+ // import { getServerCounter, updateServerCounter } from './action.tsx'
44import reactLogo from './assets/react.svg'
55import { ClientCounter } from './client.tsx'
66
@@ -26,19 +26,11 @@ function App() {
2626 < div className = "card" >
2727 < ClientCounter />
2828 </ div >
29- < div className = "card" >
29+ { /* <div className="card">
3030 <form action={updateServerCounter.bind(null, 1)}>
3131 <button>Server Counter: {getServerCounter()}</button>
3232 </form>
33- </ div >
34- < ul className = "read-the-docs" >
35- < li >
36- Edit < code > src/client.tsx</ code > to test client HMR.
37- </ li >
38- < li >
39- Edit < code > src/root.tsx</ code > to test server HMR.
40- </ li >
41- </ ul >
33+ </div> */ }
4234 </ div >
4335 )
4436}
You can’t perform that action at this time.
0 commit comments