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
[Suspense] Tune demo heights and section copy (#8526)
* Tune Suspense demo heights, data delay, and DOM comparison wording
* Make section openers stand alone and restore demo timing
* Shrink image demo portraits so both cards fit without layout shift
* Name the resources in the combined section opener
* State the ViewTransition condition in the combined section opener
* Align combined section opener with sibling sections
* Frame font and image waiting as Suspense behavior gated on ViewTransition
* Match the combined section opener to its sibling sections
* Document the experimental defer prop
* Reduce the combined example's data delay
* tweak
Copy file name to clipboardExpand all lines: src/content/reference/react/Suspense.md
+19-18Lines changed: 19 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,6 +26,7 @@ title: <Suspense>
26
26
#### Props {/*props*/}
27
27
*`children`: The actual UI you intend to render. If `children` suspends while rendering, the Suspense boundary will switch to rendering `fallback`.
28
28
*`fallback`: An alternate UI to render in place of the actual UI if it has not finished loading. Any valid React node is accepted, though in practice, a fallback is a lightweight placeholder view, such as a loading spinner or skeleton. Suspense will automatically switch to `fallback` when `children` suspends, and back to `children` when the data is ready. If `fallback` suspends while rendering, it will activate the closest parent Suspense boundary.
29
+
* <ExperimentalBadge /> **optional**`defer`: A boolean. When `true`, React may show the `fallback` first and render or stream `children` later, even when nothing in them suspends. Use it for content that is expensive to render. Defaults to `false`.
29
30
30
31
#### Caveats {/*caveats*/}
31
32
@@ -48,7 +49,7 @@ A Suspense boundary waits for its content to be ready before revealing it. Any o
48
49
- 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
50
- <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
51
- <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
-
- <ExperimentalBadge /> Performing CPU-bound render work inside a `<Suspense>` boundary marked with the `defer` prop.
52
+
- <ExperimentalBadge /> Performing CPU-bound render work inside a [`<Suspensedefer>`](#props) boundary.
52
53
53
54
<Note>
54
55
@@ -2379,7 +2380,7 @@ A stylesheet rendered with [`<link rel="stylesheet">` and a `precedence` prop](/
2379
2380
2380
2381
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.
2381
2382
2382
-
For comparison, the second button performs the same update with plain DOM in a separate document, without React. Nothing waits for the stylesheet, so the card's text appears in a fallback font first and then switches:
2383
+
For comparison, the second button performs the same update without React, in a separate document. Nothing waits for the stylesheet, so the card's text appears in a fallback font first and then switches:
2383
2384
2384
2385
<Sandpack>
2385
2386
@@ -2449,7 +2450,7 @@ export default function VanillaCard() {
@@ -2740,11 +2741,11 @@ Where you place the `<ViewTransition>` relative to the boundary determines wheth
2740
2741
2741
2742
### <CanaryBadge /> Waiting for a font to load {/*waiting-for-a-font-to-load*/}
2742
2743
2743
-
When a [`<ViewTransition>`](/reference/react/ViewTransition) animates a Suspense 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.
2744
+
When a [`<ViewTransition>`](/reference/react/ViewTransition) animates a Suspense boundary's reveal, React 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.
2744
2745
2745
2746
In the example below, the Suspense boundary is wrapped in a `<ViewTransition>`, and the `Quote` component suspends while its data loads. Rendering the quote starts its font download. React keeps the fallback visible until the font has loaded, so the quote appears already in its font.
2746
2747
2747
-
For comparison, the second button performs the same update with plain DOM, without React. Nothing waits for the font, so the text appears in a fallback font first and then switches:
2748
+
For comparison, the second button performs the same update without React. Nothing waits for the font, so the text appears in a fallback font first and then switches:
2748
2749
2749
2750
<Sandpack>
2750
2751
@@ -2814,7 +2815,7 @@ export default function VanillaQuote() {
### <CanaryBadge /> Waiting for an image to load {/*waiting-for-an-image-to-load*/}
2892
2893
2893
-
Images work the same way: when a [`<ViewTransition>`](/reference/react/ViewTransition) animates a Suspense 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>`.
2894
+
When a [`<ViewTransition>`](/reference/react/ViewTransition) animates a Suspense 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>`.
2894
2895
2895
2896
In the example below, the Suspense boundary is wrapped in a `<ViewTransition>` and shows a profile skeleton until the portrait has loaded.
2896
2897
2897
-
For comparison, the second button performs the same update with plain DOM, without React. Nothing waits for the image, so the card appears immediately and the image pops in when it loads:
2898
+
For comparison, the second button performs the same update without React. Nothing waits for the image, so the card appears immediately and the image pops in when it loads:
2898
2899
2899
2900
<Sandpack>
2900
2901
@@ -2906,7 +2907,7 @@ import VanillaProfile from './VanillaProfile.js';
@@ -2978,7 +2979,7 @@ export function freshImageUrl() {
2978
2979
2979
2980
```css
2980
2981
#root {
2981
-
min-height:440px;
2982
+
min-height:390px;
2982
2983
}
2983
2984
.card {
2984
2985
margin-top:1em;
@@ -2992,8 +2993,8 @@ export function freshImageUrl() {
2992
2993
font-weight: bold;
2993
2994
}
2994
2995
.avatar-placeholder {
2995
-
width:100px;
2996
-
height:100px;
2996
+
width:80px;
2997
+
height:80px;
2997
2998
border-radius:50%;
2998
2999
background: #dfe3e9;
2999
3000
}
@@ -3023,9 +3024,9 @@ hr {
3023
3024
3024
3025
### <CanaryBadge /> Coordinating fonts, images, and stylesheets {/*coordinating-fonts-images-and-stylesheets*/}
3025
3026
3026
-
All of these waits work together. In the example below, the `ProfileCard` component suspends while its data loads, and renders a stylesheet with `precedence`, text in a new font, and a portrait. React keeps the skeleton visible while the data and the stylesheet load. The `<ViewTransition>` reveal then waits for the font and the image, so the card appears complete.
3027
+
A Suspense boundary can wait for data, stylesheets, fonts, and images at once. Waiting for fonts and images only happens during a [`<ViewTransition>`](/reference/react/ViewTransition) update. In the example below, the `ProfileCard` component suspends while its data loads, and renders a stylesheet with `precedence`, text in a new font, and a portrait. React keeps the skeleton visible while the data and the stylesheet load. The `<ViewTransition>` reveal then waits for the font and the image, so the card appears complete.
3027
3028
3028
-
For comparison, the plain DOM version loads the same data and shows every resource arriving on its own schedule:
3029
+
For comparison, the version without React loads the same data and shows every resource arriving on its own schedule:
3029
3030
3030
3031
<Sandpack>
3031
3032
@@ -3125,7 +3126,7 @@ export default function VanillaProfileCard() {
0 commit comments