@@ -1094,7 +1094,7 @@ export function attach(
1094
1094
hook.getFiberRoots(rendererID).forEach(root => {
1095
1095
currentRootID = getOrGenerateFiberInstance ( root . current ) . id ;
1096
1096
setRootPseudoKey ( currentRootID , root . current ) ;
1097
- mountChildrenRecursively ( root . current , null , false , false ) ;
1097
+ mountFiberRecursively ( root . current , null , false ) ;
1098
1098
flushPendingEvents ( root ) ;
1099
1099
currentRootID = - 1 ;
1100
1100
} );
@@ -2231,101 +2231,108 @@ export function attach(
2231
2231
function mountChildrenRecursively (
2232
2232
firstChild : Fiber ,
2233
2233
parentInstance : DevToolsInstance | null ,
2234
- traverseSiblings : boolean ,
2235
2234
traceNearestHostComponentUpdate : boolean ,
2236
- ) {
2235
+ ) : void {
2237
2236
// Iterate over siblings rather than recursing.
2238
2237
// This reduces the chance of stack overflow for wide trees (e.g. lists with many items).
2239
2238
let fiber : Fiber | null = firstChild ;
2240
2239
while ( fiber !== null ) {
2241
- // Generate an ID even for filtered Fibers, in case it's needed later (e.g. for Profiling).
2242
- // TODO: Do we really need to do this eagerly?
2243
- getOrGenerateFiberInstance ( fiber ) ;
2240
+ mountFiberRecursively (
2241
+ fiber ,
2242
+ parentInstance ,
2243
+ traceNearestHostComponentUpdate ,
2244
+ ) ;
2245
+ fiber = fiber . sibling ;
2246
+ }
2247
+ }
2244
2248
2245
- if ( __DEBUG__ ) {
2246
- debug ( 'mountChildrenRecursively()' , fiber , parentInstance ) ;
2247
- }
2249
+ function mountFiberRecursively (
2250
+ fiber : Fiber ,
2251
+ parentInstance : DevToolsInstance | null ,
2252
+ traceNearestHostComponentUpdate : boolean ,
2253
+ ) : void {
2254
+ // Generate an ID even for filtered Fibers, in case it's needed later (e.g. for Profiling).
2255
+ // TODO: Do we really need to do this eagerly?
2256
+ getOrGenerateFiberInstance ( fiber ) ;
2248
2257
2249
- // If we have the tree selection from previous reload, try to match this Fiber.
2250
- // Also remember whether to do the same for siblings.
2251
- const mightSiblingsBeOnTrackedPath =
2252
- updateTrackedPathStateBeforeMount ( fiber ) ;
2253
-
2254
- const shouldIncludeInTree = ! shouldFilterFiber ( fiber ) ;
2255
- const newParentInstance = shouldIncludeInTree
2256
- ? recordMount ( fiber , parentInstance )
2257
- : parentInstance ;
2258
-
2259
- if ( traceUpdatesEnabled ) {
2260
- if ( traceNearestHostComponentUpdate ) {
2261
- const elementType = getElementTypeForFiber ( fiber ) ;
2262
- // If an ancestor updated, we should mark the nearest host nodes for highlighting.
2263
- if ( elementType === ElementTypeHostComponent ) {
2264
- traceUpdatesForNodes . add ( fiber . stateNode ) ;
2265
- traceNearestHostComponentUpdate = false ;
2266
- }
2267
- }
2258
+ if ( __DEBUG__ ) {
2259
+ debug ( 'mountChildrenRecursively()' , fiber , parentInstance ) ;
2260
+ }
2261
+
2262
+ // If we have the tree selection from previous reload, try to match this Fiber.
2263
+ // Also remember whether to do the same for siblings.
2264
+ const mightSiblingsBeOnTrackedPath =
2265
+ updateTrackedPathStateBeforeMount ( fiber ) ;
2268
2266
2269
- // We intentionally do not re-enable the traceNearestHostComponentUpdate flag in this branch,
2270
- // because we don't want to highlight every host node inside of a newly mounted subtree.
2267
+ const shouldIncludeInTree = ! shouldFilterFiber ( fiber ) ;
2268
+ const newParentInstance = shouldIncludeInTree
2269
+ ? recordMount ( fiber , parentInstance )
2270
+ : parentInstance ;
2271
+
2272
+ if ( traceUpdatesEnabled ) {
2273
+ if ( traceNearestHostComponentUpdate ) {
2274
+ const elementType = getElementTypeForFiber ( fiber ) ;
2275
+ // If an ancestor updated, we should mark the nearest host nodes for highlighting.
2276
+ if ( elementType === ElementTypeHostComponent ) {
2277
+ traceUpdatesForNodes . add ( fiber . stateNode ) ;
2278
+ traceNearestHostComponentUpdate = false ;
2279
+ }
2271
2280
}
2272
2281
2273
- if ( fiber . tag = = = SuspenseComponent ) {
2274
- const isTimedOut = fiber . memoizedState !== null ;
2275
- if ( isTimedOut ) {
2276
- // Special case: if Suspense mounts in a timed-out state,
2277
- // get the fallback child from the inner fragment and mount
2278
- // it as if it was our own child. Updates handle this too.
2279
- const primaryChildFragment = fiber . child ;
2280
- const fallbackChildFragment = primaryChildFragment
2281
- ? primaryChildFragment . sibling
2282
- : null ;
2283
- const fallbackChild = fallbackChildFragment
2284
- ? fallbackChildFragment . child
2285
- : null ;
2286
- if ( fallbackChild !== null ) {
2287
- mountChildrenRecursively (
2288
- fallbackChild ,
2289
- newParentInstance ,
2290
- true ,
2291
- traceNearestHostComponentUpdate ,
2292
- ) ;
2293
- }
2294
- } else {
2295
- let primaryChild : Fiber | null = null ;
2296
- const areSuspenseChildrenConditionallyWrapped =
2297
- OffscreenComponent === - 1 ;
2298
- if ( areSuspenseChildrenConditionallyWrapped ) {
2299
- primaryChild = fiber . child ;
2300
- } else if ( fiber . child !== null ) {
2301
- primaryChild = fiber . child . child ;
2302
- }
2303
- if ( primaryChild !== null ) {
2304
- mountChildrenRecursively (
2305
- primaryChild ,
2306
- newParentInstance ,
2307
- true ,
2308
- traceNearestHostComponentUpdate ,
2309
- ) ;
2310
- }
2282
+ // We intentionally do not re-enable the traceNearestHostComponentUpdate flag in this branch,
2283
+ // because we don't want to highlight every host node inside of a newly mounted subtree.
2284
+ }
2285
+
2286
+ if ( fiber . tag = = = SuspenseComponent ) {
2287
+ const isTimedOut = fiber . memoizedState !== null ;
2288
+ if ( isTimedOut ) {
2289
+ // Special case: if Suspense mounts in a timed-out state,
2290
+ // get the fallback child from the inner fragment and mount
2291
+ // it as if it was our own child. Updates handle this too.
2292
+ const primaryChildFragment = fiber . child ;
2293
+ const fallbackChildFragment = primaryChildFragment
2294
+ ? primaryChildFragment . sibling
2295
+ : null ;
2296
+ const fallbackChild = fallbackChildFragment
2297
+ ? fallbackChildFragment . child
2298
+ : null ;
2299
+ if ( fallbackChild !== null ) {
2300
+ mountChildrenRecursively (
2301
+ fallbackChild ,
2302
+ newParentInstance ,
2303
+ traceNearestHostComponentUpdate ,
2304
+ ) ;
2311
2305
}
2312
2306
} else {
2313
- if ( fiber . child !== null ) {
2307
+ let primaryChild : Fiber | null = null ;
2308
+ const areSuspenseChildrenConditionallyWrapped =
2309
+ OffscreenComponent === - 1 ;
2310
+ if ( areSuspenseChildrenConditionallyWrapped ) {
2311
+ primaryChild = fiber . child ;
2312
+ } else if ( fiber . child !== null ) {
2313
+ primaryChild = fiber . child . child ;
2314
+ }
2315
+ if ( primaryChild !== null ) {
2314
2316
mountChildrenRecursively (
2315
- fiber . child ,
2317
+ primaryChild ,
2316
2318
newParentInstance ,
2317
- true ,
2318
2319
traceNearestHostComponentUpdate ,
2319
2320
) ;
2320
2321
}
2321
2322
}
2322
-
2323
- // We're exiting this Fiber now, and entering its siblings.
2324
- // If we have selection to restore, we might need to re-activate tracking.
2325
- updateTrackedPathStateAfterMount ( mightSiblingsBeOnTrackedPath ) ;
2326
-
2327
- fiber = traverseSiblings ? fiber . sibling : null ;
2323
+ } else {
2324
+ if ( fiber . child !== null ) {
2325
+ mountChildrenRecursively (
2326
+ fiber . child ,
2327
+ newParentInstance ,
2328
+ traceNearestHostComponentUpdate ,
2329
+ ) ;
2330
+ }
2328
2331
}
2332
+
2333
+ // We're exiting this Fiber now, and entering its siblings.
2334
+ // If we have selection to restore, we might need to re-activate tracking.
2335
+ updateTrackedPathStateAfterMount ( mightSiblingsBeOnTrackedPath ) ;
2329
2336
}
2330
2337
2331
2338
// We use this to simulate unmounting for Suspense trees
@@ -2533,10 +2540,9 @@ export function attach(
2533
2540
shouldResetChildren = true ;
2534
2541
}
2535
2542
} else {
2536
- mountChildrenRecursively (
2543
+ mountFiberRecursively (
2537
2544
nextChild ,
2538
2545
parentInstance,
2539
- false,
2540
2546
traceNearestHostComponentUpdate,
2541
2547
) ;
2542
2548
shouldResetChildren = true ;
@@ -2642,7 +2648,6 @@ export function attach(
2642
2648
mountChildrenRecursively (
2643
2649
nextFallbackChildSet ,
2644
2650
newParentInstance ,
2645
- true ,
2646
2651
traceNearestHostComponentUpdate ,
2647
2652
) ;
2648
2653
@@ -2671,7 +2676,6 @@ export function attach(
2671
2676
mountChildrenRecursively (
2672
2677
nextPrimaryChildSet ,
2673
2678
newParentInstance ,
2674
- true ,
2675
2679
traceNearestHostComponentUpdate ,
2676
2680
) ;
2677
2681
}
@@ -2691,7 +2695,6 @@ export function attach(
2691
2695
mountChildrenRecursively (
2692
2696
nextFallbackChildSet ,
2693
2697
newParentInstance ,
2694
- true ,
2695
2698
traceNearestHostComponentUpdate ,
2696
2699
) ;
2697
2700
shouldResetChildren = true ;
@@ -2819,7 +2822,7 @@ export function attach(
2819
2822
} ;
2820
2823
}
2821
2824
2822
- mountChildrenRecursively (root.current, null, false , false);
2825
+ mountFiberRecursively (root.current, null, false);
2823
2826
flushPendingEvents(root);
2824
2827
currentRootID = -1;
2825
2828
} ) ;
@@ -2918,7 +2921,7 @@ export function attach(
2918
2921
if ( ! wasMounted && isMounted ) {
2919
2922
// Mount a new root.
2920
2923
setRootPseudoKey ( currentRootID , current ) ;
2921
- mountChildrenRecursively ( current , null , false , false ) ;
2924
+ mountFiberRecursively ( current , null , false ) ;
2922
2925
} else if ( wasMounted && isMounted ) {
2923
2926
// Update an existing root.
2924
2927
updateFiberRecursively ( current , alternate , null , false ) ;
@@ -2930,7 +2933,7 @@ export function attach(
2930
2933
} else {
2931
2934
// Mount a new root.
2932
2935
setRootPseudoKey ( currentRootID , current ) ;
2933
- mountChildrenRecursively ( current , null , false , false ) ;
2936
+ mountFiberRecursively ( current , null , false ) ;
2934
2937
}
2935
2938
2936
2939
if ( isProfiling && isProfilingSupported ) {
0 commit comments