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
+22-24Lines changed: 22 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,8 +46,8 @@ A Suspense boundary waits for its content to be ready before revealing it. Any o
46
46
- Reading a Promise with [`use`](/reference/react/use), including data streamed from [Server Components](/reference/rsc/server-components) or loaded through a [Suspense-enabled framework](#suspense-enabled-frameworks).
47
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. [See an example below.](#waiting-for-a-stylesheet-to-load)
48
48
- Waiting for a large boundary's HTML to arrive during streaming server rendering. Sending HTML takes time, so a boundary with enough content activates even when nothing in it suspends. React reveals the content as the HTML arrives.
49
-
- Loading fonts. This doesn't happen by default, but a [`<ViewTransition>`](/reference/react/ViewTransition) update waits for new fonts to load, up to a timeout, so text doesn't flash with a fallback font. [See an example below.](#waiting-for-a-font-to-load)
50
-
- Loading images. This doesn't happen by default, but during a [`<ViewTransition>`](/reference/react/ViewTransition) update, an image's `src` blocks the boundary until the image loads, up to a timeout. Adding an `onLoad` handler opts a specific image out. [See an example below.](#waiting-for-an-image-to-load)
49
+
-<CanaryBadge /> Loading fonts. Suspense doesn't wait for fonts by default, but a [`<ViewTransition>`](/reference/react/ViewTransition) update waits for new fonts to load, up to a timeout, so text doesn't flash with a fallback font. [See an example below.](#waiting-for-a-font-to-load)
50
+
-<CanaryBadge /> Loading images. Suspense doesn't wait for images by default, but during a [`<ViewTransition>`](/reference/react/ViewTransition) update, React blocks the boundary until the image loads, up to a timeout. Adding an `onLoad` handler opts a specific image out. [See an example below.](#waiting-for-an-image-to-load)
51
51
- <ExperimentalBadge /> Performing CPU-bound render work inside a `<Suspense>` boundary marked with the `defer` prop.
52
52
53
53
<Note>
@@ -437,7 +437,7 @@ function ProfilePage() {
437
437
<body>
438
438
<h1>Alice</h1>
439
439
<p>Photographer and traveler.</p>
440
-
<Suspense fallback={<p>Loading posts...</p>}>
440
+
<Suspense fallback={<p>⌛ Loading posts...</p>}>
441
441
<Posts />
442
442
</Suspense>
443
443
</body>
@@ -2259,9 +2259,9 @@ During a Transition, React avoids hiding already revealed content. However, when
2259
2259
<ProfilePage key={queryParams.id} />
2260
2260
```
2261
2261
2262
-
With a different `key`, React treats the profiles as different components and resets the Suspense boundary during navigation. Suspense-integrated routers do this automatically.
2262
+
With a different `key`, React treats the profiles as different content and resets the Suspense boundary during navigation. The `key` can go on the boundary itself or on a component above it. Suspense-integrated routers should do this automatically.
2263
2263
2264
-
In the example below, opening the profile page loads the first profile. Switching tabs navigates to a different profile, and the `key` resets the boundary, so the fallback shows instead of the previous user's bio. Try removing the `key`: the previous bio stays visible while the next one loads:
2264
+
In the example below, opening the profile page loads the first profile. Pressing "Bob" navigates to a different profile, and the `key` resets the boundary, so the fallback shows instead of the previous user's bio. Try removing the `key`: the previous bio stays visible while the next one loads:
// Note: the way you would do data fetching depends on
2327
2327
// the framework that you use together with Suspense.
2328
-
// Normally, the caching logic would be inside a framework.
2329
2328
2330
2329
exportasyncfunctionfetchBio(userId) {
2331
2330
// Add a fake delay to make waiting noticeable.
@@ -2376,7 +2375,7 @@ The server HTML will include the loading indicator. It will be replaced by the `
2376
2375
2377
2376
### Waiting for a stylesheet to load {/*waiting-for-a-stylesheet-to-load*/}
2378
2377
2379
-
A stylesheet rendered with [`<link rel="stylesheet">` and a `precedence` prop](/reference/react-dom/components/link#special-rendering-behavior) blocks the boundary until the stylesheet loads, up to a timeout, so the content never appears unstyled.
2378
+
A stylesheet rendered with [`<link rel="stylesheet">` and a `precedence` prop](/reference/react-dom/components/link#special-rendering-behavior) blocks the boundary until the stylesheet loads, up to a timeout, so the content doesn't appear unstyled.
2380
2379
2381
2380
In the example below, the `Card` component renders a stylesheet with `precedence`. Press "Show card": React shows the fallback until the stylesheet has loaded, and then reveals the card with its styles applied:
<div className="fancy-card">This card is styled by the stylesheet.</div>
2394
+
<div className="fancy-card">This card uses a font from the stylesheet.</div>
2396
2395
</>
2397
2396
);
2398
2397
}
@@ -2683,7 +2682,7 @@ Where you place the `<ViewTransition>` relative to the boundary determines wheth
2683
2682
2684
2683
### Waiting for a font to load {/*waiting-for-a-font-to-load*/}
2685
2684
2686
-
<CanaryBadge /> When a [`<ViewTransition>`](/reference/react/ViewTransition) animates a boundary's reveal, React also waits for new fonts the content introduces, up to a timeout, so the text doesn't flash with a fallback font. This doesn't happen by default outside a `<ViewTransition>`.
2685
+
<CanaryBadge /> When a [`<ViewTransition>`](/reference/react/ViewTransition) animates a boundary's reveal, React also waits for new fonts the content introduces, up to a timeout, so the text doesn't flash with a fallback font. This only happens during a `<ViewTransition>` update.
2687
2686
2688
2687
In the example below, the `Quote` component suspends while its data loads. Rendering the quote starts its font download, so React keeps the fallback visible until the font has loaded, and the quote appears already in its font:
2689
2688
@@ -2700,7 +2699,7 @@ function Quote({ fontSrc }) {
2700
2699
constquote=use(fetchQuote());
2701
2700
return (
2702
2701
<>
2703
-
<style href="fancy-font" precedence="default">
2702
+
<style href={fontSrc} precedence="default">
2704
2703
{`@font-face {
2705
2704
font-family: 'Fancy';
2706
2705
src: url(${fontSrc}) format('truetype');
@@ -2727,7 +2726,7 @@ export default function App() {
@@ -2788,7 +2787,7 @@ export function fetchQuote() {
2788
2787
2789
2788
### Waiting for an image to load {/*waiting-for-an-image-to-load*/}
2790
2789
2791
-
<CanaryBadge /> Images work the same way: when a [`<ViewTransition>`](/reference/react/ViewTransition) animates a boundary's reveal, React waits for visible images in the content to load before revealing the content, so the animation doesn't finish on a half-loaded image. This doesn't happen by default outside a `<ViewTransition>`. Adding an `onLoad` handler opts a specific image out, even inside a `<ViewTransition>`.
2790
+
<CanaryBadge /> Images work the same way: when a [`<ViewTransition>`](/reference/react/ViewTransition) animates a boundary's reveal, React waits for visible images to load, up to a timeout, so the animation doesn't start with a half-loaded image. This only happens during a `<ViewTransition>` update. Adding an `onLoad` handler opts a specific image out, even inside a `<ViewTransition>`.
2792
2791
2793
2792
In the example below, the boundary shows its fallback until the portrait has loaded:
2794
2793
@@ -2797,36 +2796,35 @@ In the example below, the boundary shows its fallback until the portrait has loa
0 commit comments