Skip to content

Commit 2b0bf46

Browse files
committed
Fix Suspense resource demos
1 parent 1fde845 commit 2b0bf46

1 file changed

Lines changed: 30 additions & 13 deletions

File tree

‎src/content/reference/react/Suspense.md‎

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2903,7 +2903,7 @@ Where you place the `<ViewTransition>` relative to the boundary determines wheth
29032903
29042904
When a [`<ViewTransition>`](/reference/react/ViewTransition) animates a Suspense boundary's reveal, React waits up to 500 ms for new fonts the content introduces so the text doesn't flash with a fallback font. This only happens during a `<ViewTransition>` update.
29052905
2906-
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.
2906+
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 while the font loads. If it loads within the 500 ms limit, the quote appears already in its font.
29072907
29082908
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:
29092909
@@ -2922,7 +2922,7 @@ function Quote({ fontSrc }) {
29222922
<style href={fontSrc} precedence="default">
29232923
{`@font-face {
29242924
font-family: 'Fancy';
2925-
src: url(${fontSrc}) format('truetype');
2925+
src: url(${fontSrc}) format('woff2');
29262926
font-display: swap;
29272927
}`}
29282928
</style>
@@ -2967,7 +2967,7 @@ export default function VanillaQuote() {
29672967
const style = document.createElement('style');
29682968
style.textContent = `@font-face {
29692969
font-family: 'VanillaFancy';
2970-
src: url(${freshFontUrl()}) format('truetype');
2970+
src: url(${freshFontUrl()}) format('woff2');
29712971
font-display: swap;
29722972
}`;
29732973
document.head.appendChild(style);
@@ -2987,7 +2987,7 @@ export default function VanillaQuote() {
29872987
// and every run shows the loading state.
29882988
export function freshFontUrl() {
29892989
return (
2990-
'https://raw.githubusercontent.com/google/fonts/main/ofl/caveat/Caveat%5Bwght%5D.ttf' +
2990+
'https://fonts.gstatic.com/s/caveat/v23/WnznHAc5bAfYB2QRah7pcpNvOx-pjfJ9eIWpYT5Kmgq3sw.woff2' +
29912991
'?t=' +
29922992
Date.now()
29932993
);
@@ -3038,8 +3038,8 @@ hr {
30383038
```json package.json hidden
30393039
{
30403040
"dependencies": {
3041-
"react": "19.3.0-canary-f1f7ed2a-20260904",
3042-
"react-dom": "19.3.0-canary-f1f7ed2a-20260904",
3041+
"react": "19.3.0",
3042+
"react-dom": "19.3.0",
30433043
"react-scripts": "latest"
30443044
}
30453045
}
@@ -3260,7 +3260,6 @@ import { freshStylesheetUrl, freshImageUrl } from './resources.js';
32603260
export default function VanillaProfileCard() {
32613261
const ref = useRef(null);
32623262
async function show() {
3263-
const quote = await fetchQuote();
32643263
const doc = ref.current.contentWindow.document;
32653264
doc.open();
32663265
doc.write(`
@@ -3270,17 +3269,34 @@ export default function VanillaProfileCard() {
32703269
.profile-card img { border-radius: 50%; background: #dfe3e9; }
32713270
.name { margin: 0 0 4px; font-family: 'Caveat', sans-serif; font-size: 22px; line-height: 28px; font-weight: bold; }
32723271
.bio { margin: 0; font-family: 'Caveat', sans-serif; font-size: 20px; line-height: 26px; }
3272+
.avatar-placeholder { width: 80px; height: 80px; border-radius: 50%; background: #dfe3e9; }
3273+
.name-placeholder, .bio-placeholder { border-radius: 4px; background: #dfe3e9; color: transparent; }
3274+
.name-placeholder { width: 90px; }
3275+
.bio-placeholder { width: 220px; height: 52px; }
32733276
</style>
32743277
<div class="profile-card">
3275-
<img src="${freshImageUrl()}" alt="Jack Pope" width="80" height="80" />
3278+
<div class="avatar-placeholder"></div>
32763279
<div>
3277-
<p class="name">Jack Pope</p>
3278-
<p class="bio">${quote}</p>
3280+
<p class="name name-placeholder">&nbsp;</p>
3281+
<p class="bio bio-placeholder">&nbsp;</p>
32793282
</div>
32803283
</div>
3281-
<link rel="stylesheet" href="${freshStylesheetUrl()}">
32823284
`);
32833285
doc.close();
3286+
3287+
const quote = await fetchQuote();
3288+
doc.body.innerHTML = `
3289+
<div class="profile-card">
3290+
<img src="${freshImageUrl()}" alt="Jack Pope" width="80" height="80" />
3291+
<div>
3292+
<p class="name">Jack Pope</p>
3293+
<p class="bio">${quote}</p>
3294+
</div>
3295+
</div>`;
3296+
const stylesheet = doc.createElement('link');
3297+
stylesheet.rel = 'stylesheet';
3298+
stylesheet.href = freshStylesheetUrl();
3299+
doc.head.appendChild(stylesheet);
32843300
}
32853301
return (
32863302
<>
@@ -3373,6 +3389,7 @@ hr {
33733389
}
33743390
.bio-placeholder {
33753391
width: 220px;
3392+
height: 52px;
33763393
}
33773394
.vanilla-frame {
33783395
display: block;
@@ -3386,8 +3403,8 @@ hr {
33863403
```json package.json hidden
33873404
{
33883405
"dependencies": {
3389-
"react": "19.3.0-canary-f1f7ed2a-20260904",
3390-
"react-dom": "19.3.0-canary-f1f7ed2a-20260904",
3406+
"react": "19.3.0",
3407+
"react-dom": "19.3.0",
33913408
"react-scripts": "latest"
33923409
}
33933410
}

0 commit comments

Comments
 (0)