diff --git a/packages/contexts/graph.tsx b/packages/contexts/graph.tsx index 687b27f58..ec4f9460d 100644 --- a/packages/contexts/graph.tsx +++ b/packages/contexts/graph.tsx @@ -260,16 +260,22 @@ export function GraphContextProvider({ const dispatch = useCallback( (actionOrActions: GraphActionOrActions) => { - graphRef.current = applyActions(graphRef.current, actionOrActions); - setGraph(graphRef.current); + try { + graphRef.current = applyActions(graphRef.current, actionOrActions); + setGraph(graphRef.current); - isPendingPersistRef.current = true; + isPendingPersistRef.current = true; + } catch (error) { + console.error("Failed to dispatch actions:", error); - if (persistTimeoutRef.current) { - clearTimeout(persistTimeoutRef.current); - } + throw error; + } finally { + if (persistTimeoutRef.current) { + clearTimeout(persistTimeoutRef.current); + } - persistTimeoutRef.current = setTimeout(persist, 500); + persistTimeoutRef.current = setTimeout(persist, 500); + } }, [persist], );