@@ -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]
@@ -1841,7 +1845,8 @@ export function startGestureTransition(
18411845 const pseudoElement : ?string = effect . pseudoElement ;
18421846 if (
18431847 pseudoElement != null &&
1844- pseudoElement . startsWith ( '::view-transition' )
1848+ pseudoElement . startsWith ( '::view-transition' ) &&
1849+ effect . target === documentElement
18451850 ) {
18461851 // Ideally we could mutate the existing animation but unfortunately
18471852 // the mutable APIs seem less tested and therefore are lacking or buggy.
@@ -1932,7 +1937,7 @@ export function startGestureTransition(
19321937 : readyCallback ;
19331938 transition . ready . then ( readyForAnimations , readyCallback ) ;
19341939 transition . finished . then ( ( ) => {
1935- cancelAllViewTransitionAnimations ( ownerDocument ) ;
1940+ cancelAllViewTransitionAnimations ( ( ownerDocument . documentElement : any ) ) ;
19361941 // $FlowFixMe[prop-missing]
19371942 if ( ownerDocument . __reactViewTransition === transition ) {
19381943 // $FlowFixMe[prop-missing]
0 commit comments