@@ -1550,6 +1550,21 @@ export function hasInstanceAffectedParent(
1550
1550
return oldRect . height !== newRect . height || oldRect . width !== newRect . width ;
1551
1551
}
1552
1552
1553
+ function cancelAllViewTransitionAnimations ( ownerDocument : Document ) {
1554
+ // In Safari, we need to manually cancel all manually start animations
1555
+ // or it'll block or interfer with future transitions.
1556
+ const animations = ownerDocument . getAnimations ( ) ;
1557
+ for ( let i = 0 ; i < animations . length ; i ++ ) {
1558
+ const anim = animations [ i ] ;
1559
+ const effect : KeyframeEffect = ( anim . effect : any ) ;
1560
+ // $FlowFixMe
1561
+ const pseudo : ?string = effect . pseudoElement ;
1562
+ if ( pseudo != null && pseudo . startsWith ( '::view-transition' ) ) {
1563
+ anim . cancel ( ) ;
1564
+ }
1565
+ }
1566
+ }
1567
+
1553
1568
// How long to wait for new fonts to load before just committing anyway.
1554
1569
// This freezes the screen. It needs to be short enough that it doesn't cause too much of
1555
1570
// an issue when it's a new load and slow, yet long enough that you have a chance to load
@@ -1640,6 +1655,7 @@ export function startViewTransition(
1640
1655
}
1641
1656
transition . ready . then ( spawnedWorkCallback , spawnedWorkCallback ) ;
1642
1657
transition . finished . then ( ( ) => {
1658
+ cancelAllViewTransitionAnimations ( ownerDocument ) ;
1643
1659
// $FlowFixMe[prop-missing]
1644
1660
if ( ownerDocument . __reactViewTransition === transition ) {
1645
1661
// $FlowFixMe[prop-missing]
@@ -1817,6 +1833,9 @@ export function startGestureTransition(
1817
1833
}
1818
1834
for ( let i = 0 ; i < animations . length ; i ++ ) {
1819
1835
const anim = animations [ i ] ;
1836
+ if ( anim . playState !== 'running' ) {
1837
+ continue ;
1838
+ }
1820
1839
const effect : KeyframeEffect = ( anim . effect : any ) ;
1821
1840
// $FlowFixMe
1822
1841
const pseudoElement : ?string = effect . pseudoElement ;
@@ -1913,19 +1932,7 @@ export function startGestureTransition(
1913
1932
: readyCallback ;
1914
1933
transition . ready . then ( readyForAnimations , readyCallback ) ;
1915
1934
transition . finished . then ( ( ) => {
1916
- // In Safari, we need to manually cancel all manually start animations
1917
- // or it'll block future transitions.
1918
- const documentElement : Element = ( ownerDocument . documentElement : any ) ;
1919
- const animations = documentElement . getAnimations ( { subtree : true } ) ;
1920
- for ( let i = 0 ; i < animations . length ; i ++ ) {
1921
- const anim = animations [ i ] ;
1922
- const effect : KeyframeEffect = ( anim . effect : any ) ;
1923
- // $FlowFixMe
1924
- const pseudo : ?string = effect . pseudoElement ;
1925
- if ( pseudo != null && pseudo . startsWith ( '::view-transition' ) ) {
1926
- anim . cancel ( ) ;
1927
- }
1928
- }
1935
+ cancelAllViewTransitionAnimations ( ownerDocument ) ;
1929
1936
// $FlowFixMe[prop-missing]
1930
1937
if ( ownerDocument . __reactViewTransition === transition ) {
1931
1938
// $FlowFixMe[prop-missing]
0 commit comments