Skip to content

Commit d3b411a

Browse files
committed
wip: client component
1 parent 743eaed commit d3b411a

File tree

6 files changed

+21
-22
lines changed

6 files changed

+21
-22
lines changed

packages/plugin-rsc/examples/browser-mode/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
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>

packages/plugin-rsc/examples/browser-mode/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
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",

packages/plugin-rsc/examples/browser-mode/src/framework/client.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ import * as ReactDOMClient from 'react-dom/client'
33
import * as ReactClient from '@vitejs/plugin-rsc/react/browser'
44
import type { RscPayload } from './server'
55

6+
export function initialize() {
7+
ReactClient.setRequireModule({
8+
load: (id) => import(/* @vite-ignore */ id),
9+
})
10+
}
11+
612
export function render(rscStream: ReadableStream<Uint8Array>) {
713
let rscPaylod: Promise<RscPayload>
814

packages/plugin-rsc/examples/browser-mode/src/framework/main.tsx

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/plugin-rsc/examples/browser-mode/src/framework/server.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
1-
import { renderToReadableStream } from '@vitejs/plugin-rsc/react/rsc'
1+
import {
2+
renderToReadableStream,
3+
setRequireModule,
4+
} from '@vitejs/plugin-rsc/react/rsc'
25
import type React from 'react'
36
import { ESModulesEvaluator, ModuleRunner } from 'vite/module-runner'
7+
import { Root } from '../root'
48

59
export type RscPayload = {
610
root: React.ReactNode
711
}
812

913
async 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

packages/plugin-rsc/examples/browser-mode/src/root.tsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import './index.css' // css import is automatically injected in exported server components
22
import viteLogo from '/vite.svg'
3-
import { getServerCounter, updateServerCounter } from './action.tsx'
3+
// import { getServerCounter, updateServerCounter } from './action.tsx'
44
import reactLogo from './assets/react.svg'
55
import { 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
}

0 commit comments

Comments
 (0)