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 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# React 18

[React 18](https://reactjs.org/blog/2021/06/08/the-plan-for-react-18.html) adds new features including Suspense, automatic batching of updates, APIs like `startTransition`, and a new streaming API for server rendering with support for `React.lazy`.
Next.js also provides streaming related APIs, please checkout [next/streaming](/docs/api-reference/next/streaming.md) for details.
leerob marked this conversation as resolved.
Show resolved Hide resolved

React 18 is in RC now. Read more about React 18's [release plan](https://reactjs.org/blog/2021/06/08/the-plan-for-react-18.html) and discussions from the [working group](https://github.com/reactwg/react-18/discussions).
React 18 is now in Release Candidate (RC). Read more about React 18's [release plan](https://reactjs.org/blog/2021/06/08/the-plan-for-react-18.html) and discussions from the [working group](https://github.com/reactwg/react-18/discussions).

## Using React 18 with Next.js

Install the Release Candidate version of React 18:
Install the RC version of React 18:

```jsx
npm install next@latest react@rc react-dom@rc
Expand Down
11 changes: 7 additions & 4 deletions docs/advanced-features/react-18/server-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ 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 enable the `serverComponents` option and specify the global `runtime` (can be either `'nodejs'` or `'edge'`) in `next.config.js`:
To use React Server Components, ensure you have React 18 installed.
leerob marked this conversation as resolved.
Show resolved Hide resolved
huozhi marked this conversation as resolved.
Show resolved Hide resolved

```jsx
npm install next@latest react@rc react-dom@rc

```jsx
// next.config.js
Expand All @@ -16,9 +19,9 @@ module.exports = {
}
```

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).
Using `runtime` also enables [Streaming SSR](/docs/advanced-features/react-18/streaming). When setting `runtime` to `'edge'`, the server will be running entirely in the [Edge Runtime](https://nextjs.org/docs/api-reference/edge-runtime).

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.
Now, you can start using React Server Components in Next.js. [See our example](https://github.com/vercel/next-rsc-demo) for more information.

### Server Components Conventions

Expand Down Expand Up @@ -49,7 +52,7 @@ export default function Home() {
}
```

The `<Home>` and `<Profile>` components will always be server-side rendered and streamed to the client, and will not be included by the client runtime. However, `<Content>` will still be hydrated on the client-side, like normal React components.
The `<Home>` and `<Profile>` components will always be server-side rendered and streamed to the client, and will not be included by the client-side JavaScript. However, `<Content>` will still be hydrated on the client-side, like normal React components.

> Make sure you're using default imports and exports for server components (`.server.js`). The support of named exports are a work in progress!

Expand Down
10 changes: 8 additions & 2 deletions docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,14 @@
"title": "React 18",
"routes": [
{
"title": "Basic",
"path": "/docs/advanced-features/react-18/basic.md"
"path": "/docs/advanced-features/react-18",
"redirect": {
"destination": "/docs/advanced-features/react-18/overview"
}
},
{
"title": "Overview",
"path": "/docs/advanced-features/react-18/overview.md"
},
{
"title": "Streaming SSR",
Expand Down