Unverified Commit 6bf5a8ab authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

docs: document the next/dynamic case with ssr: false option (#69741)

parent 38e62069
...@@ -59,6 +59,8 @@ export default function ClientComponentExample() { ...@@ -59,6 +59,8 @@ export default function ClientComponentExample() {
When using `React.lazy()` and Suspense, Client Components will be pre-rendered (SSR) by default. When using `React.lazy()` and Suspense, Client Components will be pre-rendered (SSR) by default.
> **Note:** `ssr: false` option will only work for client components, move it into client components ensure the client code-splitting working properly.
If you want to disable pre-rendering for a Client Component, you can use the `ssr` option set to `false`: If you want to disable pre-rendering for a Client Component, you can use the `ssr` option set to `false`:
```jsx ```jsx
...@@ -68,6 +70,9 @@ const ComponentC = dynamic(() => import('../components/C'), { ssr: false }) ...@@ -68,6 +70,9 @@ const ComponentC = dynamic(() => import('../components/C'), { ssr: false })
### Importing Server Components ### Importing Server Components
If you dynamically import a Server Component, only the Client Components that are children of the Server Component will be lazy-loaded - not the Server Component itself. If you dynamically import a Server Component, only the Client Components that are children of the Server Component will be lazy-loaded - not the Server Component itself.
It will also help preload the static assets such as CSS when you're using it in Server Components.
> **Note:** `ssr: false` option is not supported in Server Components.
```jsx filename="app/page.js" ```jsx filename="app/page.js"
import dynamic from 'next/dynamic' import dynamic from 'next/dynamic'
...@@ -202,6 +207,8 @@ const DynamicComponent = dynamic(() => ...@@ -202,6 +207,8 @@ const DynamicComponent = dynamic(() =>
To dynamically load a component on the client side, you can use the `ssr` option to disable server-rendering. This is useful if an external dependency or component relies on browser APIs like `window`. To dynamically load a component on the client side, you can use the `ssr` option to disable server-rendering. This is useful if an external dependency or component relies on browser APIs like `window`.
```jsx ```jsx
'use client'
import dynamic from 'next/dynamic' import dynamic from 'next/dynamic'
const DynamicHeader = dynamic(() => import('../components/header'), { const DynamicHeader = dynamic(() => import('../components/header'), {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment