Skip to content

Commit 61739a8

Browse files
authored
[DevTools] Filter Server Components (#30839)
Support filtering Virtual Instances with existing filters. Server Components are considered "Functions". In a follow up I'll a new filter for "Environment" which will let you filter by Client vs Server (and more).
1 parent e33a723 commit 61739a8

File tree

1 file changed

+36
-13
lines changed
  • packages/react-devtools-shared/src/backend/fiber

1 file changed

+36
-13
lines changed

packages/react-devtools-shared/src/backend/fiber/renderer.js

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,26 @@ export function attach(
12161216
}
12171217

12181218
function shouldFilterVirtual(data: ReactComponentInfo): boolean {
1219-
// TODO: Apply filters to VirtualInstances.
1219+
// For purposes of filtering Server Components are always Function Components.
1220+
// Environment will be used to filter Server vs Client.
1221+
// Technically they can be forwardRef and memo too but those filters will go away
1222+
// as those become just plain user space function components like any HoC.
1223+
if (hideElementsWithTypes.has(ElementTypeFunction)) {
1224+
return true;
1225+
}
1226+
1227+
if (hideElementsWithDisplayNames.size > 0) {
1228+
const displayName = data.name;
1229+
if (displayName != null) {
1230+
// eslint-disable-next-line no-for-of-loops/no-for-of-loops
1231+
for (const displayNameRegExp of hideElementsWithDisplayNames) {
1232+
if (displayNameRegExp.test(displayName)) {
1233+
return true;
1234+
}
1235+
}
1236+
}
1237+
}
1238+
12201239
return false;
12211240
}
12221241

@@ -2446,6 +2465,10 @@ export function attach(
24462465
continue;
24472466
}
24482467
const componentInfo: ReactComponentInfo = (debugEntry: any);
2468+
if (shouldFilterVirtual(componentInfo)) {
2469+
// Skip.
2470+
continue;
2471+
}
24492472
if (level === virtualLevel) {
24502473
if (
24512474
previousVirtualInstance === null ||
@@ -2864,6 +2887,9 @@ export function attach(
28642887
continue;
28652888
}
28662889
const componentInfo: ReactComponentInfo = (debugEntry: any);
2890+
if (shouldFilterVirtual(componentInfo)) {
2891+
continue;
2892+
}
28672893
if (level === virtualLevel) {
28682894
if (
28692895
previousVirtualInstance === null ||
@@ -3686,19 +3712,16 @@ export function attach(
36863712
}
36873713
// We couldn't use this Fiber but we might have a VirtualInstance
36883714
// that is the nearest unfiltered instance.
3689-
let parentInstance = fiberInstance.parent;
3690-
while (parentInstance !== null) {
3691-
if (parentInstance.kind === FIBER_INSTANCE) {
3692-
// If we find a parent Fiber, it might not be the nearest parent
3693-
// so we break out and continue walking the Fiber tree instead.
3694-
break;
3695-
} else {
3696-
if (!shouldFilterVirtual(parentInstance.data)) {
3697-
return parentInstance.id;
3698-
}
3699-
}
3700-
parentInstance = parentInstance.parent;
3715+
const parentInstance = fiberInstance.parent;
3716+
if (
3717+
parentInstance !== null &&
3718+
parentInstance.kind === VIRTUAL_INSTANCE
3719+
) {
3720+
// Virtual Instances only exist if they're unfiltered.
3721+
return parentInstance.id;
37013722
}
3723+
// If we find a parent Fiber, it might not be the nearest parent
3724+
// so we break out and continue walking the Fiber tree instead.
37023725
}
37033726
fiber = fiber.return;
37043727
}

0 commit comments

Comments
 (0)