Skip to content

[Fizz] Suspensey Images for View Transition Reveals #33433

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -4860,8 +4860,9 @@ export function writeCompletedSegmentInstruction(
const completeBoundaryScriptFunctionOnly = stringToPrecomputedChunk(
completeBoundaryFunction,
);
const completeBoundaryUpgradeToViewTransitionsInstruction =
stringToPrecomputedChunk(upgradeToViewTransitionsInstruction);
const completeBoundaryUpgradeToViewTransitionsInstruction = stringToChunk(
upgradeToViewTransitionsInstruction,
);
const completeBoundaryScript1Partial = stringToPrecomputedChunk('$RC("');

const completeBoundaryWithStylesScript1FullPartial = stringToPrecomputedChunk(
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const SUSPENSE_PENDING_START_DATA = '$?';
const SUSPENSE_QUEUED_START_DATA = '$~';
const SUSPENSE_FALLBACK_START_DATA = '$!';

const SUSPENSEY_FONT_TIMEOUT = 500;
const SUSPENSEY_FONT_AND_IMAGE_TIMEOUT = 500;

// TODO: Symbols that are referenced outside this module use dynamic accessor
// notation instead of dot notation to prevent Closure's advanced compilation
Expand Down Expand Up @@ -136,6 +136,7 @@ export function revealCompletedBoundariesWithViewTransitions(
);
}
}
const suspenseyImages = [];
// Next we'll find the nodes that we're going to animate and apply names to them..
for (let i = 0; i < batch.length; i += 2) {
const suspenseIdNode = batch[i];
Expand Down Expand Up @@ -248,21 +249,50 @@ export function revealCompletedBoundariesWithViewTransitions(
ancestorElement.nodeType === ELEMENT_NODE &&
ancestorElement.getAttribute('vt-update') !== 'none'
);

// Find the appearing Suspensey Images inside the new content.
const appearingImages = contentNode.querySelectorAll(
'img[src]:not([loading="lazy"])',
);
// TODO: Consider marking shouldStartViewTransition if we found any images.
// But only once we can disable the root animation for that case.
suspenseyImages.push.apply(suspenseyImages, appearingImages);
}
if (shouldStartViewTransition) {
const transition = (document['__reactViewTransition'] = document[
'startViewTransition'
]({
update: () => {
revealBoundaries(
batch,
// Force layout to trigger font loading, we pass the actual value to trick minifiers.
revealBoundaries(batch);
const blockingPromises = [
// Force layout to trigger font loading, we stash the actual value to trick minifiers.
document.documentElement.clientHeight,
);
return Promise.race([
// Block on fonts finishing loading before revealing these boundaries.
document.fonts.ready,
new Promise(resolve => setTimeout(resolve, SUSPENSEY_FONT_TIMEOUT)),
];
for (let i = 0; i < suspenseyImages.length; i++) {
const suspenseyImage = suspenseyImages[i];
if (!suspenseyImage.complete) {
const rect = suspenseyImage.getBoundingClientRect();
const inViewport =
rect.bottom > 0 &&
rect.right > 0 &&
rect.top < window.innerHeight &&
rect.left < window.innerWidth;
if (inViewport) {
const loadingImage = new Promise(resolve => {
suspenseyImage.addEventListener('load', resolve);
suspenseyImage.addEventListener('error', resolve);
});
blockingPromises.push(loadingImage);
}
}
}
return Promise.race([
Promise.all(blockingPromises),
new Promise(resolve =>
setTimeout(resolve, SUSPENSEY_FONT_AND_IMAGE_TIMEOUT),
),
]);
},
types: [], // TODO: Add a hard coded type for Suspense reveals.
Expand Down
Loading