@@ -1216,7 +1216,26 @@ export function attach(
1216
1216
}
1217
1217
1218
1218
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
+
1220
1239
return false;
1221
1240
}
1222
1241
@@ -2446,6 +2465,10 @@ export function attach(
2446
2465
continue ;
2447
2466
}
2448
2467
const componentInfo : ReactComponentInfo = ( debugEntry : any ) ;
2468
+ if ( shouldFilterVirtual ( componentInfo ) ) {
2469
+ // Skip.
2470
+ continue ;
2471
+ }
2449
2472
if ( level === virtualLevel ) {
2450
2473
if (
2451
2474
previousVirtualInstance === null ||
@@ -2864,6 +2887,9 @@ export function attach(
2864
2887
continue ;
2865
2888
}
2866
2889
const componentInfo : ReactComponentInfo = ( debugEntry : any ) ;
2890
+ if ( shouldFilterVirtual ( componentInfo ) ) {
2891
+ continue ;
2892
+ }
2867
2893
if ( level === virtualLevel ) {
2868
2894
if (
2869
2895
previousVirtualInstance === null ||
@@ -3686,19 +3712,16 @@ export function attach(
3686
3712
}
3687
3713
// We couldn't use this Fiber but we might have a VirtualInstance
3688
3714
// 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 ;
3701
3722
}
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.
3702
3725
}
3703
3726
fiber = fiber . return ;
3704
3727
}
0 commit comments