@@ -12,7 +12,7 @@ import type {
12
12
GestureProvider ,
13
13
GestureOptions ,
14
14
} from 'shared/ReactTypes' ;
15
- import type { Lanes } from './ReactFiberLane' ;
15
+ import { NoLane , type Lanes } from './ReactFiberLane' ;
16
16
import type { StackCursor } from './ReactFiberStack' ;
17
17
import type { Cache , SpawnedCachePool } from './ReactFiberCacheComponent' ;
18
18
import type { Transition } from 'react/src/ReactStartTransition' ;
@@ -34,10 +34,17 @@ import {
34
34
retainCache ,
35
35
CacheContext ,
36
36
} from './ReactFiberCacheComponent' ;
37
- import { queueTransitionTypes } from './ReactFiberTransitionTypes' ;
37
+ import {
38
+ queueTransitionTypes ,
39
+ entangleAsyncTransitionTypes ,
40
+ entangledTransitionTypes ,
41
+ } from './ReactFiberTransitionTypes' ;
38
42
39
43
import ReactSharedInternals from 'shared/ReactSharedInternals' ;
40
- import { entangleAsyncAction } from './ReactFiberAsyncAction' ;
44
+ import {
45
+ entangleAsyncAction ,
46
+ peekEntangledActionLane ,
47
+ } from './ReactFiberAsyncAction' ;
41
48
import { startAsyncTransitionTimer } from './ReactProfilerTimer' ;
42
49
import { firstScheduledRoot } from './ReactFiberRootScheduler' ;
43
50
import {
@@ -88,15 +95,31 @@ ReactSharedInternals.S = function onStartTransitionFinishForReconciler(
88
95
const thenable : Thenable < mixed > = (returnValue: any);
89
96
entangleAsyncAction(transition, thenable);
90
97
}
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
+ }
100
123
}
101
124
}
102
125
if ( prevOnStartTransitionFinish !== null ) {
0 commit comments