@@ -10,11 +10,15 @@ import type {FiberRoot} from './ReactInternalTypes';
1010import type { Lanes } from './ReactFiberLane.new' ;
1111import type { StackCursor } from './ReactFiberStack.new' ;
1212import type { Cache , SpawnedCachePool } from './ReactFiberCacheComponent.new' ;
13+ import type { Transition } from './ReactFiberTracingMarkerComponent.new' ;
1314
14- import { enableCache } from 'shared/ReactFeatureFlags' ;
15+ import { enableCache , enableTransitionTracing } from 'shared/ReactFeatureFlags' ;
1516import { isPrimaryRenderer } from './ReactFiberHostConfig' ;
1617import { createCursor , push , pop } from './ReactFiberStack.new' ;
17- import { getWorkInProgressRoot } from './ReactFiberWorkLoop.new' ;
18+ import {
19+ getWorkInProgressRoot ,
20+ getWorkInProgressTransitions ,
21+ } from './ReactFiberWorkLoop.new' ;
1822import {
1923 createCache ,
2024 retainCache ,
@@ -25,6 +29,15 @@ import {
2529// used during the previous render by placing it here, on the stack.
2630const resumedCache : StackCursor < Cache | null > = createCursor ( null ) ;
2731
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 of arrays and actually filter them in the passive phase.
37+ const transitionStack : StackCursor < Array < Transition > | null> = createCursor (
38+ null ,
39+ ) ;
40+
2841function peekCacheFromPool ( ) : Cache | null {
2942 if ( ! enableCache ) {
3043 return ( null : any ) ;
@@ -75,25 +88,31 @@ export function requestCacheFromPool(renderLanes: Lanes): Cache {
7588 return freshCache ;
7689}
7790
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 ) ;
8199 }
82- // Note: This function currently does nothing but I'll leave it here for
83- // code organization purposes in case that changes.
84100}
85101
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 ) ;
89109 }
90- // Note: This function currently does nothing but I'll leave it here for
91- // code organization purposes in case that changes.
92110}
93111
94112export function pushTransition (
95113 offscreenWorkInProgress : Fiber ,
96114 prevCachePool : SpawnedCachePool | null ,
115+ newTransitions : Array < Transition > | null ,
97116) : void {
98117 if ( enableCache ) {
99118 if ( prevCachePool === null ) {
@@ -102,12 +121,46 @@ export function pushTransition(
102121 push ( resumedCache , prevCachePool . pool , offscreenWorkInProgress ) ;
103122 }
104123 }
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+ }
105138}
106139
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 ;
110155 }
156+
157+ const currentTransitions = transitionStack . current ;
158+
159+ if ( currentTransitions === null ) {
160+ return null ;
161+ }
162+
163+ return currentTransitions ;
111164}
112165
113166export function getSuspendedCache ( ) : SpawnedCachePool | null {
0 commit comments