diff --git a/src/frontend/src/components/nav/NavigationTree.tsx b/src/frontend/src/components/nav/NavigationTree.tsx index 508b020b88..b1472032f0 100644 --- a/src/frontend/src/components/nav/NavigationTree.tsx +++ b/src/frontend/src/components/nav/NavigationTree.tsx @@ -108,12 +108,20 @@ export default function NavigationTree({ const nodeMap: Record = {}; for (const n of query.data) nodeMap[n.pk] = n; - // Walk from the selected node up to the root, expanding each ancestor + // Collect every ancestor pk into a single object, then apply in one + // setExpandedState call to avoid closure/batching issues with expand(). + const toExpand: Record = {}; let current = nodeMap[selectedId]; while (current?.parent) { - treeState.expand(current.parent.toString()); + toExpand[current.parent.toString()] = true; current = nodeMap[current.parent]; } + if (Object.keys(toExpand).length) { + treeState.setExpandedState({ + ...treeState.expandedState, + ...toExpand + }); + } } } }, [debouncedSearch, query.data, query.isFetching, selectedId]);