You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/reference/react/Suspense.md
+25-25Lines changed: 25 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -38,6 +38,30 @@ title: <Suspense>
38
38
39
39
---
40
40
41
+
### What activates a Suspense boundary {/*what-activates-a-suspense-boundary*/}
42
+
43
+
A Suspense boundary waits for its content to be ready before revealing it. Any of the following blocks a boundary's content from being revealed:
44
+
45
+
- Lazy-loading component code with [`lazy`](/reference/react/lazy).
46
+
- Reading a Promise with [`use`](/reference/react/use), including data streamed from [Server Components](/reference/rsc/server-components) or provided by a [Suspense-enabled framework](#suspense-enabled-frameworks).
47
+
- Loading a stylesheet rendered with [`<link rel="stylesheet">` and a `precedence` prop.](/reference/react-dom/components/link#special-rendering-behavior) React blocks the boundary until the stylesheet loads, up to a timeout.
48
+
- Loading fonts. When a boundary is revealed by streamed SSR content, React waits for [`document.fonts.ready`](https://developer.mozilla.org/en-US/docs/Web/API/FontFaceSet/ready) before showing it, up to a timeout, so text doesn't flash with a fallback font. Fonts also block a [`<ViewTransition>`](/reference/react/ViewTransition) update.
49
+
- Streaming a large boundary's HTML during server rendering. React reveals the content as the HTML arrives.
50
+
- Loading an image, where the `src` blocks the boundary until the image loads. This behavior is not enabled by default. When enabled, an `onLoad` handler opts an image out, and images in a [`<ViewTransition>`](/reference/react/ViewTransition) update opt in automatically.
51
+
- <ExperimentalBadge /> Performing CPU-bound render work inside a `<Suspense>` boundary marked with the `defer` prop.
A *Suspense-enabled framework* gives you a way to read data in your component that calls [`use`](/reference/react/use) under the hood, so reading that data activates the nearest boundary. The exact way you load your data depends on your framework, and you'll find the details in its documentation.
58
+
59
+
Without a framework, you can read a Promise with `use` directly, as long as the Promise is [cached so the same instance is reused across renders.](/reference/react/use#caching-promises-for-client-components)
60
+
61
+
</Note>
62
+
63
+
---
64
+
41
65
## Usage {/*usage*/}
42
66
43
67
### Displaying a fallback while content is loading {/*displaying-a-fallback-while-content-is-loading*/}
@@ -205,32 +229,8 @@ async function getAlbums() {
205
229
206
230
</Sandpack>
207
231
208
-
---
209
-
210
-
### What activates a Suspense boundary {/*what-activates-a-suspense-boundary*/}
211
-
212
-
A Suspense boundary waits for its content to be ready before revealing it. Any of the following blocks a boundary's content from being revealed:
213
-
214
-
- Lazy-loading component code with [`lazy`](/reference/react/lazy).
215
-
- Reading a Promise with [`use`](/reference/react/use), including data streamed from [Server Components](/reference/rsc/server-components).
216
-
- Data fetching through a [Suspense-enabled framework](#suspense-enabled-frameworks) like [Relay](https://relay.dev/docs/guided-tour/rendering/loading-states/), which integrates its own data source with Suspense.
217
-
- Loading a stylesheet rendered with [`<link rel="stylesheet">` and a `precedence` prop.](/reference/react-dom/components/link#special-rendering-behavior) React blocks the boundary until the stylesheet loads, up to a timeout.
218
-
- Loading fonts. When a boundary is revealed by streamed SSR content, React waits for [`document.fonts.ready`](https://developer.mozilla.org/en-US/docs/Web/API/FontFaceSet/ready) before showing it, up to a timeout, so text doesn't flash with a fallback font. Fonts also block a [`<ViewTransition>`](/reference/react/ViewTransition) update.
219
-
- Streaming a large boundary's HTML during server rendering. React reveals the content as the HTML arrives.
220
-
- Loading an image, where the `src` blocks the boundary until the image loads. This behavior is not enabled by default. When enabled, an `onLoad` handler opts an image out, and images in a [`<ViewTransition>`](/reference/react/ViewTransition) update opt in automatically.
221
-
- <ExperimentalBadge /> Performing CPU-bound render work inside a `<Suspense>` boundary marked with the `defer` prop.
A *Suspense-enabled framework* integrates its data fetching with Suspense, so that reading data in a component activates the nearest boundary. Some frameworks build on Server Components and [`use`](/reference/react/use), like Next.js, while others provide a custom integration, like Relay. The exact way you load your data depends on your framework, and you'll find the details in its documentation.
228
-
229
-
Without a framework, you can read a Promise with `use` directly, as long as the Promise is [cached so the same instance is reused across renders.](/reference/react/use#caching-promises-for-client-components)
230
-
231
-
</Note>
232
+
By contrast, code that fetches data outside of `use`, such as inside an Effect, does not activate the boundary:
232
233
233
-
Fetching data inside an Effect does not activate the boundary. Suspense can't detect the fetch, so the `fallback` never appears and the list stays empty until the data arrives:
0 commit comments