Skip to content

Commit d3bc60c

Browse files
committed
Limit the scope of cancellations to documentElement
This is in preparation for nested View Transitions. In that case we shouldn't cancel other nested View Transitions than the one we started.
1 parent 33a135f commit d3bc60c

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,16 +1550,20 @@ export function hasInstanceAffectedParent(
15501550
return oldRect.height !== newRect.height || oldRect.width !== newRect.width;
15511551
}
15521552

1553-
function cancelAllViewTransitionAnimations(ownerDocument: Document) {
1553+
function cancelAllViewTransitionAnimations(scope: Element) {
15541554
// In Safari, we need to manually cancel all manually start animations
15551555
// or it'll block or interfer with future transitions.
1556-
const animations = ownerDocument.getAnimations();
1556+
const animations = scope.getAnimations({subtree: true});
15571557
for (let i = 0; i < animations.length; i++) {
15581558
const anim = animations[i];
15591559
const effect: KeyframeEffect = (anim.effect: any);
15601560
// $FlowFixMe
15611561
const pseudo: ?string = effect.pseudoElement;
1562-
if (pseudo != null && pseudo.startsWith('::view-transition')) {
1562+
if (
1563+
pseudo != null &&
1564+
pseudo.startsWith('::view-transition') &&
1565+
effect.target === scope
1566+
) {
15631567
anim.cancel();
15641568
}
15651569
}
@@ -1655,7 +1659,7 @@ export function startViewTransition(
16551659
}
16561660
transition.ready.then(spawnedWorkCallback, spawnedWorkCallback);
16571661
transition.finished.then(() => {
1658-
cancelAllViewTransitionAnimations(ownerDocument);
1662+
cancelAllViewTransitionAnimations((ownerDocument.documentElement: any));
16591663
// $FlowFixMe[prop-missing]
16601664
if (ownerDocument.__reactViewTransition === transition) {
16611665
// $FlowFixMe[prop-missing]
@@ -1932,7 +1936,7 @@ export function startGestureTransition(
19321936
: readyCallback;
19331937
transition.ready.then(readyForAnimations, readyCallback);
19341938
transition.finished.then(() => {
1935-
cancelAllViewTransitionAnimations(ownerDocument);
1939+
cancelAllViewTransitionAnimations((ownerDocument.documentElement: any));
19361940
// $FlowFixMe[prop-missing]
19371941
if (ownerDocument.__reactViewTransition === transition) {
19381942
// $FlowFixMe[prop-missing]

0 commit comments

Comments
 (0)