7
7
* @flow
8
8
*/
9
9
10
- import type { ReactComponentInfo } from 'shared/ReactTypes' ;
10
+ import type { ReactComponentInfo , ReactDebugInfo } from 'shared/ReactTypes' ;
11
11
12
12
import {
13
13
ComponentFilterDisplayName ,
@@ -2226,6 +2226,7 @@ export function attach(
2226
2226
function recordVirtualMount (
2227
2227
instance : VirtualInstance ,
2228
2228
parentInstance : DevToolsInstance | null ,
2229
+ secondaryEnv : null | string ,
2229
2230
) : void {
2230
2231
const id = instance . id ;
2231
2232
@@ -2239,6 +2240,9 @@ export function attach(
2239
2240
let displayName = componentInfo . name || '' ;
2240
2241
if ( typeof env === 'string' ) {
2241
2242
// We model environment as an HoC name for now.
2243
+ if ( secondaryEnv !== null ) {
2244
+ displayName = secondaryEnv + '(' + displayName + ')' ;
2245
+ }
2242
2246
displayName = env + '(' + displayName + ')' ;
2243
2247
}
2244
2248
const elementType = ElementTypeVirtual ;
@@ -2444,6 +2448,25 @@ export function attach(
2444
2448
pendingRealUnmountedIDs . push ( id ) ;
2445
2449
}
2446
2450
2451
+ function getSecondaryEnvironmentName (
2452
+ debugInfo : ?ReactDebugInfo ,
2453
+ index : number ,
2454
+ ) : null | string {
2455
+ if ( debugInfo != null ) {
2456
+ const componentInfo : ReactComponentInfo = ( debugInfo [ index ] : any ) ;
2457
+ for ( let i = index + 1 ; i < debugInfo . length ; i ++ ) {
2458
+ const debugEntry = debugInfo [ i ] ;
2459
+ if ( typeof debugEntry . env === 'string' ) {
2460
+ // If the next environment is different then this component was the boundary
2461
+ // and it changed before entering the next component. So we assign this
2462
+ // component a secondary environment.
2463
+ return componentInfo . env !== debugEntry. env ? debugEntry . env : null ;
2464
+ }
2465
+ }
2466
+ }
2467
+ return null ;
2468
+ }
2469
+
2447
2470
function mountVirtualChildrenRecursively (
2448
2471
firstChild : Fiber ,
2449
2472
lastChild : null | Fiber , // non-inclusive
@@ -2464,6 +2487,7 @@ export function attach(
2464
2487
// Not a Component. Some other Debug Info.
2465
2488
continue ;
2466
2489
}
2490
+ // Scan up until the next Component to see if this component changed environment.
2467
2491
const componentInfo : ReactComponentInfo = ( debugEntry : any ) ;
2468
2492
if ( shouldFilterVirtual ( componentInfo ) ) {
2469
2493
// Skip.
@@ -2487,7 +2511,15 @@ export function attach(
2487
2511
) ;
2488
2512
}
2489
2513
previousVirtualInstance = createVirtualInstance ( componentInfo ) ;
2490
- recordVirtualMount ( previousVirtualInstance , reconcilingParent ) ;
2514
+ const secondaryEnv = getSecondaryEnvironmentName (
2515
+ fiber . _debugInfo ,
2516
+ i ,
2517
+ ) ;
2518
+ recordVirtualMount (
2519
+ previousVirtualInstance ,
2520
+ reconcilingParent ,
2521
+ secondaryEnv ,
2522
+ ) ;
2491
2523
insertChild ( previousVirtualInstance ) ;
2492
2524
previousVirtualInstanceFirstFiber = fiber ;
2493
2525
}
@@ -2951,7 +2983,15 @@ export function attach(
2951
2983
} else {
2952
2984
// Otherwise we create a new instance.
2953
2985
const newVirtualInstance = createVirtualInstance ( componentInfo ) ;
2954
- recordVirtualMount ( newVirtualInstance , reconcilingParent ) ;
2986
+ const secondaryEnv = getSecondaryEnvironmentName (
2987
+ nextChild . _debugInfo ,
2988
+ i ,
2989
+ ) ;
2990
+ recordVirtualMount (
2991
+ newVirtualInstance ,
2992
+ reconcilingParent ,
2993
+ secondaryEnv ,
2994
+ ) ;
2955
2995
insertChild ( newVirtualInstance ) ;
2956
2996
previousVirtualInstance = newVirtualInstance ;
2957
2997
previousVirtualInstanceWasMount = true ;
0 commit comments