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
{{ message }}
Repository navigation
Commit d56099a
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: src/content/reference/react/Suspense.md
+67-22Lines changed: 67 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -47,7 +47,7 @@ A Suspense boundary waits for its content to be ready before revealing it. Any o
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
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 a [`<ViewTransition>`](/reference/react/ViewTransition) update waits for its images to load, up to a timeout. Adding an `onLoad` handler opts a specific image out. [See an example below.](#waiting-for-an-image-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)
51
51
- <ExperimentalBadge /> Performing CPU-bound render work inside a `<Suspense>` boundary marked with the `defer` prop.
52
52
53
53
<Note>
@@ -2261,16 +2261,33 @@ During a Transition, React avoids hiding already revealed content. However, when
2261
2261
2262
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.
2263
2263
2264
-
In the example below, the `key` resets the boundary when you switch profiles, 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. 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:
@@ -2668,37 +2685,50 @@ Where you place the `<ViewTransition>` relative to the boundary determines wheth
2668
2685
2669
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>`.
2670
2687
2671
-
In the example below, the quote uses a new font. The browser only starts downloading a font when text first uses it, so rendering the quote starts the download. React holds the animated reveal until the font has loaded:
2688
+
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:
// Note: the way you would do data fetching depends on
2742
+
// the framework that you use together with Suspense.
2743
+
// Normally, the caching logic would be inside a framework.
2744
+
2745
+
let cache =null;
2746
+
2747
+
exportfunctionfetchQuote() {
2748
+
if (!cache) {
2749
+
cache =newPromise((resolve) => {
2750
+
// Add a fake delay to make waiting noticeable.
2751
+
setTimeout(() => {
2752
+
resolve(
2753
+
'The best way to predict the future is to invent it.'
2754
+
);
2755
+
}, 1500);
2756
+
});
2757
+
}
2758
+
return cache;
2717
2759
}
2760
+
```
2761
+
2762
+
```css
2718
2763
#root {
2719
2764
min-height:100px;
2720
2765
}
@@ -2745,7 +2790,7 @@ export default function App() {
2745
2790
2746
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>`.
2747
2792
2748
-
In the example below, React holds the animated reveal until the portrait has loaded:
2793
+
In the example below, the boundary shows its fallback until the portrait has loaded:
0 commit comments