@@ -10,11 +10,15 @@ import type {FiberRoot} from './ReactInternalTypes';
10
10
import type { Lanes } from './ReactFiberLane.new' ;
11
11
import type { StackCursor } from './ReactFiberStack.new' ;
12
12
import type { Cache , SpawnedCachePool } from './ReactFiberCacheComponent.new' ;
13
+ import type { Transition } from './ReactFiberTracingMarkerComponent.new' ;
13
14
14
- import { enableCache } from 'shared/ReactFeatureFlags' ;
15
+ import { enableCache , enableTransitionTracing } from 'shared/ReactFeatureFlags' ;
15
16
import { isPrimaryRenderer } from './ReactFiberHostConfig' ;
16
17
import { createCursor , push , pop } from './ReactFiberStack.new' ;
17
- import { getWorkInProgressRoot } from './ReactFiberWorkLoop.new' ;
18
+ import {
19
+ getWorkInProgressRoot ,
20
+ getWorkInProgressTransitions ,
21
+ } from './ReactFiberWorkLoop.new' ;
18
22
import {
19
23
createCache ,
20
24
retainCache ,
@@ -25,6 +29,15 @@ import {
25
29
// used during the previous render by placing it here, on the stack.
26
30
const resumedCache : StackCursor < Cache | null > = createCursor ( null ) ;
27
31
32
+ // During the render/synchronous commit phase, we don't actually process the
33
+ // transitions. Therefore, we want to lazily combine transitions. Instead of
34
+ // comparing the arrays of transitions when we combine them and storing them
35
+ // and filtering out the duplicates, we will instead store the unprocessed transitions
36
+ // in an array and actually filter them in the passive phase.
37
+ const transitionStack : StackCursor < Array < Transition > | null> = createCursor (
38
+ null ,
39
+ ) ;
40
+
28
41
function peekCacheFromPool ( ) : Cache | null {
29
42
if ( ! enableCache ) {
30
43
return ( null : any ) ;
@@ -75,25 +88,31 @@ export function requestCacheFromPool(renderLanes: Lanes): Cache {
75
88
return freshCache ;
76
89
}
77
90
78
- export function pushRootTransition ( root : FiberRoot ) {
79
- if ( enableCache ) {
80
- return ;
91
+ export function pushRootTransition (
92
+ workInProgress : Fiber ,
93
+ root : FiberRoot ,
94
+ renderLanes : Lanes ,
95
+ ) {
96
+ if ( enableTransitionTracing ) {
97
+ const rootTransitions = getWorkInProgressTransitions ( ) ;
98
+ push ( transitionStack , rootTransitions , workInProgress ) ;
81
99
}
82
- // Note: This function currently does nothing but I'll leave it here for
83
- // code organization purposes in case that changes.
84
100
}
85
101
86
- export function popRootTransition ( root : FiberRoot , renderLanes : Lanes ) {
87
- if ( enableCache ) {
88
- return ;
102
+ export function popRootTransition (
103
+ workInProgress : Fiber ,
104
+ root : FiberRoot ,
105
+ renderLanes : Lanes ,
106
+ ) {
107
+ if ( enableTransitionTracing ) {
108
+ pop ( transitionStack , workInProgress ) ;
89
109
}
90
- // Note: This function currently does nothing but I'll leave it here for
91
- // code organization purposes in case that changes.
92
110
}
93
111
94
112
export function pushTransition (
95
113
offscreenWorkInProgress : Fiber ,
96
114
prevCachePool : SpawnedCachePool | null ,
115
+ newTransitions : Array < Transition > | null ,
97
116
) : void {
98
117
if ( enableCache ) {
99
118
if ( prevCachePool === null ) {
@@ -102,12 +121,40 @@ export function pushTransition(
102
121
push ( resumedCache , prevCachePool . pool , offscreenWorkInProgress ) ;
103
122
}
104
123
}
124
+
125
+ if ( enableTransitionTracing ) {
126
+ if ( transitionStack . current === null ) {
127
+ push ( transitionStack , newTransitions , offscreenWorkInProgress ) ;
128
+ } else if ( newTransitions === null ) {
129
+ push ( transitionStack , transitionStack . current , offscreenWorkInProgress ) ;
130
+ } else {
131
+ push (
132
+ transitionStack ,
133
+ transitionStack . current . concat ( newTransitions ) ,
134
+ offscreenWorkInProgress ,
135
+ ) ;
136
+ }
137
+ }
105
138
}
106
139
107
- export function popTransition ( workInProgress : Fiber ) {
108
- if ( enableCache ) {
109
- pop ( resumedCache , workInProgress ) ;
140
+ export function popTransition ( workInProgress : Fiber , current : Fiber | null ) {
141
+ if ( current !== null ) {
142
+ if ( enableCache ) {
143
+ pop ( resumedCache , workInProgress ) ;
144
+ }
145
+
146
+ if ( enableTransitionTracing ) {
147
+ pop ( transitionStack , workInProgress ) ;
148
+ }
149
+ }
150
+ }
151
+
152
+ export function getSuspendedTransitions ( ) : Array < Transition > | null {
153
+ if ( ! enableTransitionTracing ) {
154
+ return null ;
110
155
}
156
+
157
+ return transitionStack . current ;
111
158
}
112
159
113
160
export function getSuspendedCache ( ) : SpawnedCachePool | null {
0 commit comments