Skip to content

Commit c0464ae

Browse files
authored
[Fizz] Block on Suspensey Fonts during reveal (facebook#33342)
This is the same technique we do for the client except we don't check whether this is newly created font loading to keep code small. Unfortunately, we can't use this technique for Suspensey images. They'll need to block before we call `startViewTransition` in a separate refactor. This is due to a bug in Chrome where `img.decode()` doesn't resolve until `startViewTransition` does.
1 parent 6a1dfe3 commit c0464ae

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

packages/react-dom-bindings/src/server/fizz-instruction-set/ReactDOMFizzInstructionSetInlineCodeStrings.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/react-dom-bindings/src/server/fizz-instruction-set/ReactDOMFizzInstructionSetShared.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const SUSPENSE_PENDING_START_DATA = '$?';
1313
const SUSPENSE_QUEUED_START_DATA = '$~';
1414
const SUSPENSE_FALLBACK_START_DATA = '$!';
1515

16+
const SUSPENSEY_FONT_TIMEOUT = 500;
17+
1618
// TODO: Symbols that are referenced outside this module use dynamic accessor
1719
// notation instead of dot notation to prevent Closure's advanced compilation
1820
// mode from renaming. We could use extern files instead, but I couldn't get it
@@ -251,7 +253,18 @@ export function revealCompletedBoundariesWithViewTransitions(
251253
const transition = (document['__reactViewTransition'] = document[
252254
'startViewTransition'
253255
]({
254-
update: revealBoundaries.bind(null, batch),
256+
update: () => {
257+
revealBoundaries(
258+
batch,
259+
// Force layout to trigger font loading, we pass the actual value to trick minifiers.
260+
document.documentElement.clientHeight,
261+
);
262+
return Promise.race([
263+
// Block on fonts finishing loading before revealing these boundaries.
264+
document.fonts.ready,
265+
new Promise(resolve => setTimeout(resolve, SUSPENSEY_FONT_TIMEOUT)),
266+
]);
267+
},
255268
types: [], // TODO: Add a hard coded type for Suspense reveals.
256269
}));
257270
transition.ready.finally(() => {

0 commit comments

Comments
 (0)