@@ -172,6 +172,7 @@ import type {
172172} from '../types' ;
173173import type {
174174 ComponentFilter ,
175+ FocusedFiberFilter ,
175176 ElementType ,
176177 Plugins ,
177178} from 'react-devtools-shared/src/frontend/types' ;
@@ -870,6 +871,9 @@ const idToDevToolsInstanceMap: Map<
870871 FiberInstance | VirtualInstance,
871872> = new Map();
872873
874+ let focusedFiberID: null | FiberInstance['id'] = null;
875+ let focusedFiber: null | Fiber = null;
876+
873877const idToSuspenseNodeMap: Map<FiberInstance['id'], SuspenseNode> = new Map();
874878
875879// Map of canonical HostInstances to the nearest parent DevToolsInstance.
@@ -1437,8 +1441,6 @@ export function attach(
14371441 const hideElementsWithPaths: Set<RegExp> = new Set();
14381442 const hideElementsWithTypes: Set<ElementType> = new Set();
14391443 const hideElementsWithEnvs: Set<string> = new Set();
1440- let focusedFiberID: null | FiberInstance['id'] = null;
1441- let focusedFiber: null | Fiber = null;
14421444 let isInFocusedFiber: boolean = true;
14431445
14441446 // Highlight updates
@@ -1447,15 +1449,16 @@ export function attach(
14471449
14481450 function applyComponentFilters(
14491451 componentFilters: Array<ComponentFilter>,
1450- nextFocusedFiber: null | Fiber = null ,
1452+ nextFocusedFiber: null | Fiber,
14511453 ) {
14521454 hideElementsWithTypes.clear();
14531455 hideElementsWithDisplayNames.clear();
14541456 hideElementsWithPaths.clear();
14551457 hideElementsWithEnvs.clear();
1456- // Consider everything in the slice by default
1458+ const previousFocusedFiberID = focusedFiberID;
14571459 focusedFiberID = null;
14581460 focusedFiber = null;
1461+ // Consider everything in the slice by default
14591462 isInFocusedFiber = true;
14601463
14611464 componentFilters.forEach(componentFilter => {
@@ -1492,6 +1495,12 @@ export function attach(
14921495 ) {
14931496 focusedFiber = nextFocusedFiber;
14941497 isInFocusedFiber = false;
1498+ if (componentFilter.rendererID !== rendererID) {
1499+ // We filtered a Fiber from another renderer.
1500+ // We need to restore the instance ID since we won't be mounting it
1501+ // in this renderer.
1502+ focusedFiberID = previousFocusedFiberID;
1503+ }
14951504 } else {
14961505 // We're not focusing after all.
14971506 // Don't mark the filter as disabled here.
@@ -1513,15 +1522,15 @@ export function attach(
15131522 if (window.__REACT_DEVTOOLS_COMPONENT_FILTERS__ != null) {
15141523 const restoredComponentFilters: Array<ComponentFilter> =
15151524 persistableComponentFilters(window.__REACT_DEVTOOLS_COMPONENT_FILTERS__);
1516- applyComponentFilters(restoredComponentFilters);
1525+ applyComponentFilters(restoredComponentFilters, null );
15171526 } else {
15181527 // Unfortunately this feature is not expected to work for React Native for now.
15191528 // It would be annoying for us to spam YellowBox warnings with unactionable stuff,
15201529 // so for now just skip this message...
15211530 //console.warn('⚛ DevTools: Could not locate saved component filters');
15221531
15231532 // Fallback to assuming the default filters in this case.
1524- applyComponentFilters(getDefaultComponentFilters());
1533+ applyComponentFilters(getDefaultComponentFilters(), null );
15251534 }
15261535
15271536 // If necessary, we can revisit optimizing this operation.
@@ -1544,9 +1553,11 @@ export function attach(
15441553 // that ID before we unmount everything. We set the focused ID once
15451554 // we mount it again.
15461555 let nextFocusedFiber: null | Fiber = null;
1556+ let focusedFiberFilter: null | FocusedFiberFilter = null;
15471557 for (let i = 0; i < componentFilters.length; i++) {
15481558 const filter = componentFilters[i];
15491559 if (filter.type === ComponentFilterFocusedFiber && filter.isEnabled) {
1560+ focusedFiberFilter = filter;
15501561 const instance = idToDevToolsInstanceMap.get(filter.fiberID);
15511562 if (instance !== undefined && instance.kind === FIBER_INSTANCE) {
15521563 nextFocusedFiber = instance.data;
@@ -1569,7 +1580,11 @@ export function attach(
15691580 currentRoot = (null: any);
15701581 });
15711582
1572- if (nextFocusedFiber !== focusedFiber) {
1583+ if (
1584+ nextFocusedFiber !== focusedFiber &&
1585+ (focusedFiberFilter === null ||
1586+ focusedFiberFilter.rendererID === rendererID)
1587+ ) {
15731588 // When we find the applied instance during mount we will send the actual ID.
15741589 // Otherwise 0 will indicate that we unfocused the Fiber slice.
15751590 pushOperation(TREE_OPERATION_FOCUSED_FIBER_CHANGE);
@@ -1635,6 +1650,13 @@ export function attach(
16351650 currentRoot = (null: any);
16361651 });
16371652
1653+ // We need to write back the new ID for the focused Fiber.
1654+ // Otherwise subsequent filter applications will try to focus based on the old ID.
1655+ // This is also relevant to filter across renderers.
1656+ if (focusedFiberFilter !== null && focusedFiberID !== null) {
1657+ focusedFiberFilter.fiberID = focusedFiberID;
1658+ }
1659+
16381660 flushPendingEvents();
16391661
16401662 needsToFlushComponentLogs = false;
0 commit comments