mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-02-15 01:05:13 -05:00
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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user