This commit is contained in:
Jarred Sumner
2024-05-05 00:51:51 -07:00
parent 72bc2585e3
commit 9bfeb0a2ae

View File

@@ -2,6 +2,15 @@
name: Server-side render (SSR) a React component
---
To get started, install the canary version of `react` & `react-dom`:
```sh
# Any package manager can be used
$ bun add react@canary react-dom@canary
```
---
To render a React component to an HTML stream server-side (SSR):
```tsx
@@ -39,4 +48,8 @@ Bun.serve({
---
React `18.3` and later includes an [SSR optimization](https://github.com/facebook/react/pull/25597) that takes advantage of Bun's "direct" `ReadableStream` implementation.
React `19` and later includes an [SSR optimization](https://github.com/facebook/react/pull/25597) that takes advantage of Bun's "direct" `ReadableStream` implementation.
---
If you run into an error like `export named 'renderToReadableStream' not found`, please make sure to install the canary version of `react` & `react-dom`, or import from `react-dom/server.browser` instead of `react-dom/server`. See [facebook/react#28941](https://github.com/facebook/react/issues/28941) for more information.