Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DevTools] Filter Server Components #30839

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 36 additions & 13 deletions packages/react-devtools-shared/src/backend/fiber/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1216,7 +1216,26 @@ export function attach(
}

function shouldFilterVirtual(data: ReactComponentInfo): boolean {
// TODO: Apply filters to VirtualInstances.
// For purposes of filtering Server Components are always Function Components.
// Environment will be used to filter Server vs Client.
// Technically they can be forwardRef and memo too but those filters will go away
// as those become just plain user space function components like any HoC.
if (hideElementsWithTypes.has(ElementTypeFunction)) {
return true;
}

if (hideElementsWithDisplayNames.size > 0) {
const displayName = data.name;
if (displayName != null) {
// eslint-disable-next-line no-for-of-loops/no-for-of-loops
for (const displayNameRegExp of hideElementsWithDisplayNames) {
if (displayNameRegExp.test(displayName)) {
return true;
}
}
}
}

return false;
}

Expand Down Expand Up @@ -2440,6 +2459,10 @@ export function attach(
continue;
}
const componentInfo: ReactComponentInfo = (debugEntry: any);
if (shouldFilterVirtual(componentInfo)) {
// Skip.
continue;
}
if (level === virtualLevel) {
if (
previousVirtualInstance === null ||
Expand Down Expand Up @@ -2853,6 +2876,9 @@ export function attach(
continue;
}
const componentInfo: ReactComponentInfo = (debugEntry: any);
if (shouldFilterVirtual(componentInfo)) {
continue;
}
if (level === virtualLevel) {
if (
previousVirtualInstance === null ||
Expand Down Expand Up @@ -3675,19 +3701,16 @@ export function attach(
}
// We couldn't use this Fiber but we might have a VirtualInstance
// that is the nearest unfiltered instance.
let parentInstance = fiberInstance.parent;
while (parentInstance !== null) {
if (parentInstance.kind === FIBER_INSTANCE) {
// If we find a parent Fiber, it might not be the nearest parent
// so we break out and continue walking the Fiber tree instead.
break;
} else {
if (!shouldFilterVirtual(parentInstance.data)) {
return parentInstance.id;
}
}
parentInstance = parentInstance.parent;
const parentInstance = fiberInstance.parent;
if (
parentInstance !== null &&
parentInstance.kind === VIRTUAL_INSTANCE
) {
// Virtual Instances only exist if they're unfiltered.
return parentInstance.id;
}
// If we find a parent Fiber, it might not be the nearest parent
// so we break out and continue walking the Fiber tree instead.
}
fiber = fiber.return;
}
Expand Down
Loading