@@ -107,15 +107,27 @@ const markerInstanceStack: StackCursor<Array<TracingMarkerInstance> | null> = cr
107
107
108
108
export function pushRootMarkerInstance ( workInProgress : Fiber ) : void {
109
109
if ( enableTransitionTracing ) {
110
+ // On the root, every transition gets mapped to it's own map of
111
+ // suspense boundaries. The transition is marked as complete when
112
+ // the suspense boundaries map is empty. We do this because every
113
+ // transition completes at different times and depends on different
114
+ // suspense boundaries to complete. We store all the transitions
115
+ // along with its map of suspense boundaries in the root incomplete
116
+ // transitions map. Each entry in this map functions like a tracing
117
+ // marker does, so we can push it onto the marker instance stack
110
118
const transitions = getWorkInProgressTransitions ( ) ;
111
119
const root = workInProgress . stateNode ;
112
120
let incompleteTransitions = root . incompleteTransitions ;
113
121
if ( transitions !== null ) {
122
+ // Create a mapping from transition to suspense boundaries
123
+ // We instantiate this lazily, only if transitions exist
114
124
if ( incompleteTransitions === null ) {
115
125
root . incompleteTransitions = incompleteTransitions = new Map ( ) ;
116
126
}
117
127
118
128
transitions . forEach ( transition => {
129
+ // We need to create a new map here because we only have access to the
130
+ // object instance in the commit phase
119
131
incompleteTransitions . set ( transition , new Map ( ) ) ;
120
132
} ) ;
121
133
}
@@ -124,6 +136,9 @@ export function pushRootMarkerInstance(workInProgress: Fiber): void {
124
136
push ( markerInstanceStack , null , workInProgress ) ;
125
137
} else {
126
138
const markerInstances = [ ] ;
139
+ // For ever transition on the suspense boundary, we push the transition
140
+ // along with its map of pending suspense boundaries onto the marker
141
+ // instance stack.
127
142
incompleteTransitions . forEach ( ( pendingSuspenseBoundaries , transition ) => {
128
143
markerInstances . push ( {
129
144
transitions : new Set ( [ transition ] ) ,
@@ -143,12 +158,9 @@ export function popRootMarkerInstance(workInProgress: Fiber) {
143
158
144
159
export function pushMarkerInstance (
145
160
workInProgress : Fiber ,
146
- transitions : Set < Transition > | null ,
147
- pendingSuspenseBoundaries : PendingSuspenseBoundaries | null ,
161
+ markerInstance : TracingMarkerInstance ,
148
162
) : void {
149
163
if ( enableTransitionTracing ) {
150
- const markerInstance = { transitions, pendingSuspenseBoundaries} ;
151
-
152
164
if ( markerInstanceStack . current === null ) {
153
165
push ( markerInstanceStack , [ markerInstance ] , workInProgress ) ;
154
166
} else {
0 commit comments