fix: prevent race condition where links load before nodes

Combined the separate useEffect hooks for adding nodes and links into
a single effect that ensures nodes are added first. Previously, links
could be processed before nodes existed in the store, causing all
connections to be silently filtered out.

Fixes: Sentry bug prediction about race condition on graph load
This commit is contained in:
Otto
2026-02-15 05:49:59 +00:00
parent 79748ca7fa
commit 2be589c95f

View File

@@ -133,22 +133,21 @@ export const useFlow = () => {
}
}, [availableGraphs, setAvailableSubGraphs]);
// adding nodes
// adding nodes and links together to avoid race condition
// Links depend on nodes existing, so we must add nodes first
useEffect(() => {
if (customNodes.length > 0) {
useNodeStore.getState().setNodes([]);
useNodeStore.getState().clearResolutionState();
addNodes(customNodes);
}
}, [customNodes, addNodes]);
// adding links
useEffect(() => {
if (graph?.links) {
useEdgeStore.getState().setEdges([]);
addLinks(graph.links);
// Only add links after nodes are in the store
if (graph?.links) {
useEdgeStore.getState().setEdges([]);
addLinks(graph.links);
}
}
}, [graph?.links, addLinks]);
}, [customNodes, graph?.links, addNodes, addLinks]);
useEffect(() => {
if (customNodes.length > 0 && graph?.links) {