7
* @flow
8
*/
9
10
-import type {ReactComponentInfo} from 'shared/ReactTypes';
10
+import type {ReactComponentInfo, ReactDebugInfo} from 'shared/ReactTypes';
11
12
import {
13
ComponentFilterDisplayName,
2226
function recordVirtualMount(
2227
instance: VirtualInstance,
2228
parentInstance: DevToolsInstance | null,
2229
+ secondaryEnv: null | string,
2230
): void {
2231
const id = instance.id;
2232
2240
let displayName = componentInfo.name || '';
2241
if (typeof env === 'string') {
2242
// We model environment as an HoC name for now.
2243
+ if (secondaryEnv !== null) {
2244
+ displayName = secondaryEnv + '(' + displayName + ')';
2245
+ }
2246
displayName = env + '(' + displayName + ')';
2247
}
2248
const elementType = ElementTypeVirtual;
2448
pendingRealUnmountedIDs.push(id);
2449
}
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
+
2470
function mountVirtualChildrenRecursively(
2471
firstChild: Fiber,
2472
lastChild: null | Fiber, // non-inclusive
2487
// Not a Component. Some other Debug Info.
2488
continue;
2489
}
2490
+ // Scan up until the next Component to see if this component changed environment.
2491
const componentInfo: ReactComponentInfo = (debugEntry: any);
2492
if (shouldFilterVirtual(componentInfo)) {
2493
// Skip.
2511
);
2512
}
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
+ );
2523
insertChild(previousVirtualInstance);
2524
previousVirtualInstanceFirstFiber = fiber;
2525
}
2983
} else {
2984
// Otherwise we create a new instance.
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
+ );
2995
insertChild(newVirtualInstance);
2996
previousVirtualInstance = newVirtualInstance;
2997
previousVirtualInstanceWasMount = true;