@@ -12,7 +12,7 @@ import type {
1212 GestureProvider ,
1313 GestureOptions ,
1414} from 'shared/ReactTypes' ;
15- import type { Lanes } from './ReactFiberLane' ;
15+ import { NoLane , type Lanes } from './ReactFiberLane' ;
1616import type { StackCursor } from './ReactFiberStack' ;
1717import type { Cache , SpawnedCachePool } from './ReactFiberCacheComponent' ;
1818import type { Transition } from 'react/src/ReactStartTransition' ;
@@ -34,10 +34,17 @@ import {
3434 retainCache ,
3535 CacheContext ,
3636} from './ReactFiberCacheComponent' ;
37- import { queueTransitionTypes } from './ReactFiberTransitionTypes' ;
37+ import {
38+ queueTransitionTypes ,
39+ entangleAsyncTransitionTypes ,
40+ entangledTransitionTypes ,
41+ } from './ReactFiberTransitionTypes' ;
3842
3943import ReactSharedInternals from 'shared/ReactSharedInternals' ;
40- import { entangleAsyncAction } from './ReactFiberAsyncAction' ;
44+ import {
45+ entangleAsyncAction ,
46+ peekEntangledActionLane ,
47+ } from './ReactFiberAsyncAction' ;
4148import { startAsyncTransitionTimer } from './ReactProfilerTimer' ;
4249import { firstScheduledRoot } from './ReactFiberRootScheduler' ;
4350import {
@@ -88,15 +95,31 @@ ReactSharedInternals.S = function onStartTransitionFinishForReconciler(
8895 const thenable : Thenable < mixed > = (returnValue: any);
8996 entangleAsyncAction(transition, thenable);
9097 }
91- if ( enableViewTransition && transition . types !== null ) {
92- // Within this Transition we should've now scheduled any roots we have updates
93- // to work on. If there are no updates on a root, then the Transition type won't
94- // be applied to that root.
95- // TODO: The exception is if we're to an async action, the updates might come in later.
96- let root = firstScheduledRoot ;
97- while ( root !== null ) {
98- queueTransitionTypes ( root , transition . types ) ;
99- root = root . next ;
98+ if ( enableViewTransition ) {
99+ if ( entangledTransitionTypes !== null ) {
100+ // If we scheduled work on any new roots, we need to add any entangled async
101+ // transition types to those roots too.
102+ let root = firstScheduledRoot ;
103+ while ( root !== null ) {
104+ queueTransitionTypes ( root , entangledTransitionTypes ) ;
105+ root = root . next ;
106+ }
107+ }
108+ const transitionTypes = transition . types ;
109+ if ( transitionTypes !== null ) {
110+ // Within this Transition we should've now scheduled any roots we have updates
111+ // to work on. If there are no updates on a root, then the Transition type won't
112+ // be applied to that root.
113+ let root = firstScheduledRoot ;
114+ while ( root !== null ) {
115+ queueTransitionTypes ( root , transitionTypes ) ;
116+ root = root . next ;
117+ }
118+ if ( peekEntangledActionLane ( ) !== NoLane ) {
119+ // If we have entangled, async actions going on, the update associated with
120+ // these types might come later. We need to save them for later.
121+ entangleAsyncTransitionTypes ( transitionTypes ) ;
122+ }
100123 }
101124 }
102125 if ( prevOnStartTransitionFinish !== null ) {
0 commit comments