14
ComponentFilterElementType,
15
ComponentFilterHOC,
16
ComponentFilterLocation,
17
+ ComponentFilterEnvironmentName,
18
ElementTypeClass,
19
ElementTypeContext,
20
ElementTypeFunction,
722
};
723
}
724
725
+// All environment names we've seen so far. This lets us create a list of filters to apply.
726
+// This should ideally include env of filtered Components too so that you can add those as
727
+// filters at the same time as removing some other filter.
728
+const knownEnvironmentNames: Set<string> = new Set();
729
+
730
// Map of one or more Fibers in a pair to their unique id number.
731
// We track both Fibers to support Fast Refresh,
732
// which may forcefully replace one of the pair as part of hot reloading.
1105
const hideElementsWithDisplayNames: Set<RegExp> = new Set();
1106
const hideElementsWithPaths: Set<RegExp> = new Set();
1107
const hideElementsWithTypes: Set<ElementType> = new Set();
1108
+ const hideElementsWithEnvs: Set<string> = new Set();
1109
1110
// Highlight updates
1111
let traceUpdatesEnabled: boolean = false;
1115
hideElementsWithTypes.clear();
1116
hideElementsWithDisplayNames.clear();
1117
hideElementsWithPaths.clear();
1118
+ hideElementsWithEnvs.clear();
1119
1120
componentFilters.forEach(componentFilter => {
1121
if (!componentFilter.isEnabled) {
1141
case ComponentFilterHOC:
1142
hideElementsWithDisplayNames.add(new RegExp('\\('));
1143
break;
1144
+ case ComponentFilterEnvironmentName:
1145
+ hideElementsWithEnvs.add(componentFilter.value);
1146
+ break;
1147
default:
1148
console.warn(
1149
`Invalid component filter type "${componentFilter.type}"`,
1226
flushPendingEvents();
1227
}
1228
1218
- function shouldFilterVirtual(data: ReactComponentInfo): boolean {
1229
+ function getEnvironmentNames(): Array<string> {
1230
+ return Array.from(knownEnvironmentNames);
1231
+ }
1232
+
1233
+ function shouldFilterVirtual(
1234
+ data: ReactComponentInfo,
1235
+ secondaryEnv: null | string,
1236
+ ): boolean {
1237
// For purposes of filtering Server Components are always Function Components.
1238
// Environment will be used to filter Server vs Client.
1239
// Technically they can be forwardRef and memo too but those filters will go away
1254
}
1255
}
1256
1257
+ if (
1258
+ (data.env == null || hideElementsWithEnvs.has(data.env)) &&
1259
+ (secondaryEnv === null || hideElementsWithEnvs.has(secondaryEnv))
1260
+ ) {
1261
+ // If a Component has two environments, you have to filter both for it not to appear.
1262
+ return true;
1263
+ }
1264
+
1265
return false;
1266
}
1267
1320
}
1321
}
1322
1323
+ if (hideElementsWithEnvs.has('Client')) {
1324
+ // If we're filtering out the Client environment we should filter out all
1325
+ // "Client Components". Technically that also includes the built-ins but
1326
+ // since that doesn't actually include any additional code loading it's
1327
+ // useful to not filter out the built-ins. Those can be filtered separately.
1328
+ // There's no other way to filter out just Function components on the Client.
1329
+ // Therefore, this only filters Class and Function components.
1330
+ switch (tag) {
1331
+ case ClassComponent:
1332
+ case IncompleteClassComponent:
1333
+ case IncompleteFunctionComponent:
1334
+ case FunctionComponent:
1335
+ case IndeterminateComponent:
1336
+ case ForwardRef:
1337
+ case MemoComponent:
1338
+ case SimpleMemoComponent:
1339
+ return true;
1340
+ }
1341
+ }
1342
+
1343
/* DISABLED: https://github.com/facebook/react/pull/28417
1344
if (hideElementsWithPaths.size > 0) {
1345
const source = getSourceForFiber(fiber);
2535
}
2536
// Scan up until the next Component to see if this component changed environment.
2537
const componentInfo: ReactComponentInfo = (debugEntry: any);
2492
- if (shouldFilterVirtual(componentInfo)) {
2538
+ const secondaryEnv = getSecondaryEnvironmentName(fiber._debugInfo, i);
2539
+ if (componentInfo.env != null) {
2540
+ knownEnvironmentNames.add(componentInfo.env);
2541
+ }
2542
+ if (secondaryEnv !== null) {
2543
+ knownEnvironmentNames.add(secondaryEnv);
2544
+ }
2545
+ if (shouldFilterVirtual(componentInfo, secondaryEnv)) {
2546
// Skip.
2547
continue;
2548
}
2564
);
2565
}
2566
previousVirtualInstance = createVirtualInstance(componentInfo);
2514
- const secondaryEnv = getSecondaryEnvironmentName(
2515
- fiber._debugInfo,
2516
- i,
2517
- );
2567
recordVirtualMount(
2568
previousVirtualInstance,
2569
reconcilingParent,
2968
continue;
2969
}
2970
const componentInfo: ReactComponentInfo = (debugEntry: any);
2922
- if (shouldFilterVirtual(componentInfo)) {
2971
+ const secondaryEnv = getSecondaryEnvironmentName(
2972
+ nextChild._debugInfo,
2973
+ i,
2974
+ );
2975
+ if (componentInfo.env != null) {
2976
+ knownEnvironmentNames.add(componentInfo.env);
2977
+ }
2978
+ if (secondaryEnv !== null) {
2979
+ knownEnvironmentNames.add(secondaryEnv);
2980
+ }
2981
+ if (shouldFilterVirtual(componentInfo, secondaryEnv)) {
2982
continue;
2983
}
2984
if (level === virtualLevel) {
3042
} else {
3043
// Otherwise we create a new instance.
3044
const newVirtualInstance = createVirtualInstance(componentInfo);
2986
- const secondaryEnv = getSecondaryEnvironmentName(
2987
- nextChild._debugInfo,
2988
- i,
2989
- );
3045
recordVirtualMount(
3046
newVirtualInstance,
3047
reconcilingParent,
3980
owner = ownerFiber._debugOwner;
3981
} else {
3982
const ownerInfo: ReactComponentInfo = (owner: any); // Refined
3928
- if (!shouldFilterVirtual(ownerInfo)) {
3983
+ if (!shouldFilterVirtual(ownerInfo, null)) {
3984
return ownerInfo;
3985
}
3986
owner = ownerInfo.owner;
5805
storeAsGlobal,
5806
unpatchConsoleForStrictMode,
5807
updateComponentFilters,
5808
+ getEnvironmentNames,
5809
};
5810
}