Skip to content

Commit e6d7392

Browse files
hi-ogawaclaude
andauthored
docs(rsc): improve plugin-rsc README organization and clarity (#723)
Co-authored-by: Claude <[email protected]>
1 parent a39d837 commit e6d7392

File tree

1 file changed

+56
-50
lines changed

1 file changed

+56
-50
lines changed

packages/plugin-rsc/README.md

Lines changed: 56 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ This package provides [React Server Components](https://react.dev/reference/rsc/
44

55
## Features
66

7-
- **Framework-less RSC experience**: The plugin implements [RSC conventions](https://react.dev/reference/rsc/server-components) and provides low level `react-server-dom` runtime API without framework-specific abstractions.
8-
- **CSS support**: CSS is automatically code-split both at client and server components and they are injected upon rendering.
7+
- **Framework-agnostic**: The plugin implements [RSC bundler features](https://react.dev/reference/rsc/server-components) and provides low level RSC runtime (`react-server-dom`) API without framework-specific abstractions.
8+
- **Runtime-agnostic**: Built on [Vite environment API](https://vite.dev/guide/api-environment.html) and works with other runtimes (e.g., [`@cloudflare/vite-plugin`](https://github.com/cloudflare/workers-sdk/tree/main/packages/vite-plugin-cloudflare)).
99
- **HMR support**: Enables editing both client and server components without full page reloads.
10-
- **Runtime agnostic**: Built on [Vite environment API](https://vite.dev/guide/api-environment.html) and works with other runtimes (e.g., [`@cloudflare/vite-plugin`](https://github.com/cloudflare/workers-sdk/tree/main/packages/vite-plugin-cloudflare)).
10+
- **CSS support**: CSS is automatically code-split both at client and server components and they are injected upon rendering.
1111

1212
## Getting Started
1313

@@ -19,14 +19,17 @@ npx degit vitejs/vite-plugin-react/packages/plugin-rsc/examples/starter my-app
1919

2020
## Examples
2121

22-
- [`./examples/starter`](./examples/starter)
23-
- This example provides an in-depth overview of API with inline comments to explain how they function within RSC-powered React application.
24-
- [`./examples/react-router`](./examples/react-router)
25-
- This demonstrates how to integrate [experimental React Router RSC API](https://remix.run/blog/rsc-preview). React Router now provides [official RSC support](https://reactrouter.com/how-to/react-server-components), so it's recommended to follow React Router's official documentation for the latest integration.
26-
- [`./examples/basic`](./examples/basic)
27-
- This is mainly used for e2e testing and include various advanced RSC usages (e.g. `"use cache"` example).
28-
- [`./examples/ssg`](./examples/ssg)
29-
- Static site generation (SSG) example with MDX and client components for interactivity.
22+
**Start here:** [`./examples/starter`](./examples/starter) - Recommended for understanding the plugin
23+
24+
- Provides an in-depth overview of API with inline comments to explain how they function within RSC-powered React application.
25+
26+
**Integration examples:**
27+
28+
- [`./examples/basic`](./examples/basic) - Advanced RSC features and testing
29+
- This is mainly used for e2e testing and includes various advanced RSC usages (e.g. `"use cache"` example).
30+
- [`./examples/ssg`](./examples/ssg) - Static site generation with MDX and client components for interactivity.
31+
- [`./examples/react-router`](./examples/react-router) - React Router RSC integration
32+
- Demonstrates how to integrate [experimental React Router RSC API](https://remix.run/blog/rsc-preview). React Router now provides [official RSC support](https://reactrouter.com/how-to/react-server-components), so it's recommended to follow React Router's official documentation for the latest integration.
3033

3134
## Basic Concepts
3235

@@ -132,7 +135,7 @@ import * as ReactServer from '@vitejs/plugin-rsc/rsc' // re-export of react-serv
132135
133136
// the plugin assumes `rsc` entry having default export of request handler
134137
export default async function handler(request: Request): Promise<Response> {
135-
// serialization React VDOM to RSC stream
138+
// serialize React VDOM to RSC stream
136139
const root = (
137140
<html>
138141
<body>
@@ -193,51 +196,26 @@ export async function handleSsr(rscStream: ReadableStream) {
193196
- [`entry.browser.tsx`](./examples/starter/src/framework/entry.browser.tsx)
194197

195198
```tsx
196-
import * as ReactClient from "@vitejs/plugin-rsc/browser"; // re-export of react-server-dom/client.browser
197-
import * as ReactDOMClient from "react-dom/client";
199+
import * as ReactClient from '@vitejs/plugin-rsc/browser' // re-export of react-server-dom/client.browser
200+
import * as ReactDOMClient from 'react-dom/client'
198201

199202
async function main() {
200203
// fetch and deserialize RSC stream back to React VDOM
201-
const rscResponse = await fetch(window.location.href + ".rsc);
202-
const root = await ReactClient.createFromReadableStream(rscResponse.body);
204+
const rscResponse = await fetch(window.location.href + '.rsc')
205+
const root = await ReactClient.createFromReadableStream(rscResponse.body)
203206

204207
// hydration (traditional CSR)
205-
ReactDOMClient.hydrateRoot(document, root);
208+
ReactDOMClient.hydrateRoot(document, root)
206209
}
207210

208-
main();
211+
main()
209212
```
210213

211-
## `react-server-dom` API
212-
213-
### `@vitejs/plugin-rsc/rsc`
214-
215-
This module re-exports RSC runtime API provided by `react-server-dom/server.edge` and `react-server-dom/client.edge` such as:
216-
217-
- `renderToReadableStream`: RSC serialization (React VDOM -> RSC stream)
218-
- `createFromReadableStream`: RSC deserialization (RSC stream -> React VDOM). This is also available on rsc environment itself. For example, it allows saving serailized RSC and deserializing it for later use.
219-
- `decodeAction/decodeReply/decodeFormState/loadServerAction/createTemporaryReferenceSet`
220-
- `encodeReply/createClientTemporaryReferenceSet`
221-
222-
### `@vitejs/plugin-rsc/ssr`
223-
224-
This module re-exports RSC runtime API provided by `react-server-dom/client.edge`
225-
226-
- `createFromReadableStream`: RSC deserialization (RSC stream -> React VDOM)
227-
228-
### `@vitejs/plugin-rsc/browser`
229-
230-
This module re-exports RSC runtime API provided by `react-server-dom/client.browser`
231-
232-
- `createFromReadableStream`: RSC deserialization (RSC stream -> React VDOM)
233-
- `createFromFetch`: a robust way of `createFromReadableStream((await fetch("...")).body)`
234-
- `encodeReply/setServerCallback`: server function related...
235-
236214
## Environment helper API
237215

238216
The plugin provides an additional helper for multi environment interaction.
239217

240-
### available on `rsc` or `ssr` environment
218+
### Available on `rsc` or `ssr` environment
241219

242220
#### `import.meta.viteRsc.loadModule`
243221

@@ -260,7 +238,7 @@ ssrModule.renderHTML(...);
260238
export function renderHTML(...) {}
261239
```
262240

263-
### available on `rsc` environment
241+
### Available on `rsc` environment
264242

265243
#### `import.meta.viteRsc.loadCss`
266244

@@ -287,7 +265,7 @@ export function ServerPage() {
287265
}
288266
```
289267

290-
Where specifying `loadCss(<id>)`, it will collect css through the server module resolved by `<id>`.
268+
When specifying `loadCss(<id>)`, it will collect css through the server module resolved by `<id>`.
291269

292270
```tsx
293271
// virtual:my-framework-helper
@@ -324,7 +302,7 @@ export function Page(props) {
324302
return <div>...</div>
325303
}
326304

327-
// my-route.css?vite-rsc-css-export=Page
305+
// my-route.tsx?vite-rsc-css-export=Page
328306
function Page(props) {
329307
return <div>...</div>
330308
}
@@ -341,14 +319,13 @@ function __Page(props) {
341319
export { __Page as Page }
342320
```
343321

344-
### available on `ssr` environment
322+
### Available on `ssr` environment
345323

346324
#### `import.meta.viteRsc.loadBootstrapScriptContent("index")`
347325

348326
This provides a raw js code to execute a browser entry file specified by `environments.client.build.rollupOptions.input.index`. This is intended to be used with React DOM SSR API, such as [`renderToReadableStream`](https://react.dev/reference/react-dom/server/renderToReadableStream)
349327

350328
```js
351-
import bootstrapScriptContent from 'virtual:vite-rsc/bootstrap-script-content'
352329
import { renderToReadableStream } from 'react-dom/server.edge'
353330

354331
const bootstrapScriptContent =
@@ -358,7 +335,7 @@ const htmlStream = await renderToReadableStream(reactNode, {
358335
})
359336
```
360337

361-
### available on `client` environment
338+
### Available on `client` environment
362339

363340
#### `rsc:update` event
364341

@@ -420,6 +397,31 @@ export default defineConfig({
420397
})
421398
```
422399

400+
## RSC runtime (react-server-dom) API
401+
402+
### `@vitejs/plugin-rsc/rsc`
403+
404+
This module re-exports RSC runtime API provided by `react-server-dom/server.edge` and `react-server-dom/client.edge` such as:
405+
406+
- `renderToReadableStream`: RSC serialization (React VDOM -> RSC stream)
407+
- `createFromReadableStream`: RSC deserialization (RSC stream -> React VDOM). This is also available on rsc environment itself. For example, it allows saving serialized RSC and deserializing it for later use.
408+
- `decodeAction/decodeReply/decodeFormState/loadServerAction/createTemporaryReferenceSet`
409+
- `encodeReply/createClientTemporaryReferenceSet`
410+
411+
### `@vitejs/plugin-rsc/ssr`
412+
413+
This module re-exports RSC runtime API provided by `react-server-dom/client.edge`
414+
415+
- `createFromReadableStream`: RSC deserialization (RSC stream -> React VDOM)
416+
417+
### `@vitejs/plugin-rsc/browser`
418+
419+
This module re-exports RSC runtime API provided by `react-server-dom/client.browser`
420+
421+
- `createFromReadableStream`: RSC deserialization (RSC stream -> React VDOM)
422+
- `createFromFetch`: a robust way of `createFromReadableStream((await fetch("...")).body)`
423+
- `encodeReply/setServerCallback`: server function related...
424+
423425
## High level API
424426

425427
> [!NOTE]
@@ -473,6 +475,10 @@ export function Page() {
473475
}
474476
```
475477

478+
## Canary and Experimental channel releases
479+
480+
See https://github.com/vitejs/vite-plugin-react/pull/524 for how to install the package for React [canary](https://react.dev/community/versioning-policy#canary-channel) and [experimental](https://react.dev/community/versioning-policy#all-release-channels) usages.
481+
476482
## Credits
477483

478484
This project builds on fundamental techniques and insights from pioneering Vite RSC implementations.

0 commit comments

Comments
 (0)