Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: react 18, streaming SSR, rsc with new apis #33986

Merged
merged 17 commits into from Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/advanced-features/react-18/server-components.md
Expand Up @@ -4,18 +4,19 @@ Server Components allow us to render React components on the server. This is fun

### Enable React Server Components

To use React Server Components, ensure you have React 18 installed. Then, turn on the `concurrentFeatures` and `serverComponents` options in `next.config.js`:
To use React Server Components, ensure you have React 18 installed. Then enable the `serverComponents` option and specify the global `runtime` (can be either `'nodejs'` or `'edge'`) in `next.config.js`:
huozhi marked this conversation as resolved.
Show resolved Hide resolved

```jsx
// next.config.js
module.exports = {
experimental: {
concurrentFeatures: true,
runtime: 'nodejs',
serverComponents: true,
},
}
```

Note that the `runtime` option also enables [Streaming SSR](/docs/advanced-features/react-18/streaming). When setting to `'edge'`, the server will be running entirely in the [Edge Runtime](https://nextjs.org/docs/api-reference/edge-runtime).
huozhi marked this conversation as resolved.
Show resolved Hide resolved

Once you've made this change, you can start using React Server Components. [See our example](https://github.com/vercel/next-rsc-demo) for more information.
huozhi marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
10 changes: 6 additions & 4 deletions docs/advanced-features/react-18/streaming.md
Expand Up @@ -5,19 +5,21 @@ It's worth noting that another experimental feature, React Server Components, is

## Enable Streaming SSR
huozhi marked this conversation as resolved.
Show resolved Hide resolved

Enabling streaming SSR means React renders your components into streams and the client continues receiving updates from these streams even after the initial SSR response is sent. In other words, when any suspended components resolve down the line, they are rendered on the server and streamed to the client. With this strategy, the app can start emitting HTML even before all the data is ready, improving your app's loading performance. As an added bonus, in streaming SSR mode, the client will also use selective hydration strategy to prioritize component hydration which based on user interaction.
Enabling streaming SSR means React renders your components into streams and the client continues receiving updates from these streams even after the initial SSR response is sent. In other words, when any suspended components resolve down the line, they are rendered on the server and streamed to the client. With this strategy, the app can start emitting HTML even before all the data is ready, improving your app's loading performance. As an added bonus, in streaming SSR mode, the client will also use selective hydration strategy to prioritize component hydration which based on user interaction.

To enable streaming SSR, set the experimental flag `concurrentFeatures` to `true`:
To enable streaming SSR, set the experimental option `runtime` to either `'nodejs'` or `'edge'`:

```jsx
// next.config.js
module.exports = {
experimental: {
concurrentFeatures: true,
runtime: 'nodejs',
},
}
```

This option determines the environment that streaming SSR will be happening. When setting to `'edge'`, the server will be running entirely in the [Edge Runtime](https://nextjs.org/docs/api-reference/edge-runtime).
shuding marked this conversation as resolved.
Show resolved Hide resolved

## Streaming Features

### next/dynamic
Expand Down Expand Up @@ -58,7 +60,7 @@ Check out [next/streaming](/docs/api-reference/next/streaming.md) for more detai

#### `next/head` and `next/script`

Using resource tags (e.g. scripts or stylesheets) in `next/head` won't work as intended with streaming, as the loading order and timing of `next/head` tags can no longer be guaranteed once you add Suspense boundaries. For this reason, we suggest moving resource tags to `next/script` with the `afterInteractive` or `lazyOnload` strategy, or the `_document`. For similar reasons, we suggest migrating `next/script` instances with the `beforeInteractive` strategy to the `_document` as well.
Using resource tags (e.g. scripts or stylesheets) in `next/head` won't work as intended with streaming, as the loading order and timing of `next/head` tags can no longer be guaranteed once you add Suspense boundaries. For this reason, we suggest moving resource tags to `next/script` with the `afterInteractive` or `lazyOnload` strategy, or the `_document`. For similar reasons, we suggest migrating `next/script` instances with the `beforeInteractive` strategy to the `_document` as well.
leerob marked this conversation as resolved.
Show resolved Hide resolved

#### Data Fetching

Expand Down