Skip to content

fix: topology graph empty after async fetch - #113

Merged
reloadfast merged 1 commit into
mainfrom
fix/topology-empty-109
Mar 2, 2026
Merged

reloadfast merged 1 commit into
mainfrom
fix/topology-empty-109

Conversation

@reloadfast

Copy link
Copy Markdown
Owner

Root cause

useNodesState(initialNodes) and useEdgesState(initialEdges) from @xyflow/react only use their argument as the initial value at mount. The topology data is fetched asynchronously in a useEffect, so when React Flow initialised, both arrays were empty — and never updated when the fetch resolved.

There was an existing synced workaround (lines 216–222) that set a boolean flag but never called setNodes or setEdges, making it completely inert.

Fix

Capture setNodes and setEdges from the hooks and push updates via useEffect whenever initialNodes/initialEdges change:

const [rfNodes, setNodes, onNodesChange] = useNodesState(initialNodes);
const [rfEdges, setEdges, onEdgesChange] = useEdgesState(initialEdges);

useEffect(() => { setNodes(initialNodes); }, [initialNodes, setNodes]);
useEffect(() => { setEdges(initialEdges); }, [initialEdges, setEdges]);

Removes the dead synced state.

Testing

  • 146 frontend tests pass
  • ESLint + Prettier clean

Closes #109

useNodesState/useEdgesState only consume their argument as an
initial value at mount time. Since topology is fetched async,
the nodes/edges arrays were always empty when React Flow initialised.

Fix: capture setNodes/setEdges from the hooks and sync them via
useEffect whenever initialNodes/initialEdges change (i.e. when
the fetch resolves).

Also removes the inert 'synced' state that was added as a failed
workaround but never called setNodes/setEdges.

Closes #109

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@reloadfast
reloadfast merged commit 5784c5d into main Mar 2, 2026
7 checks passed
@reloadfast
reloadfast deleted the fix/topology-empty-109 branch March 2, 2026 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: topology graph is empty

1 participant