diff --git a/desktop/plugins/public/ui-debugger/index.tsx b/desktop/plugins/public/ui-debugger/index.tsx index b7a905504..9e1f09d87 100644 --- a/desktop/plugins/public/ui-debugger/index.tsx +++ b/desktop/plugins/public/ui-debugger/index.tsx @@ -12,6 +12,7 @@ import { createState, createDataSource, produce, + Atom, } from 'flipper-plugin'; import { Events, @@ -107,6 +108,7 @@ export function plugin(client: PluginClient) { }); nodes.set(liveClientData.nodes); snapshot.set(liveClientData.snapshotInfo); + checkFocusedNodeStillActive(uiState, nodes.get()); } }; @@ -151,6 +153,8 @@ export function plugin(client: PluginClient) { if (!uiState.isPaused.get()) { nodes.set(liveClientData.nodes); snapshot.set(liveClientData.snapshotInfo); + + checkFocusedNodeStillActive(uiState, nodes.get()); } }); @@ -180,6 +184,52 @@ function setParentPointers( }); } +function checkFocusedNodeStillActive( + uiState: { + isPaused: Atom; + searchTerm: Atom; + isContextMenuOpen: Atom; + hoveredNodes: Atom; + focusedNode: Atom; + treeState: Atom; + }, + nodes: Map, +) { + const focusedNodeId = uiState.focusedNode.get(); + const focusedNode = focusedNodeId && nodes.get(focusedNodeId); + if (focusedNode && !isFocusedNodeAncestryAllActive(focusedNode, nodes)) { + uiState.focusedNode.set(undefined); + } +} + +function isFocusedNodeAncestryAllActive( + focused: UINode, + nodes: Map, +): boolean { + let node = focused; + + while (node != null) { + if (node.parent == null) { + return true; + } + + const parent = nodes.get(node.parent); + + if (parent == null) { + //should also never happen + return false; + } + + if (parent.activeChild != null && parent.activeChild !== node.id) { + return false; + } + + node = parent; + } + //wont happen + return false; +} + function collapseinActiveChildren(node: UINode, draft: TreeState) { if (node.activeChild) { const inactiveChildren = node.children.filter(