From c116f14e3973c0bf31d50fb5a8907677d278bee4 Mon Sep 17 00:00:00 2001 From: TerrifiedBug Date: Mon, 15 Jun 2026 21:27:33 +0100 Subject: [PATCH] fix(editor): stop autosave refetch from deselecting node mid-edit The pipeline editor hydrated the flow store whenever pipelineQuery.data changed, guarded only by (hasLoadedRef && isDirty). Auto-save's onSuccess both calls markClean() (isDirty=false) and invalidates pipeline.get, so the refetch re-ran loadGraph, which resets selectedNodeId to null and kicked the user out of the detail/edit panel every 2 seconds. Hydrate the store once per mount instead. A remount still re-hydrates from fresh data; while mounted the store is the source of truth. --- src/app/(dashboard)/pipelines/[id]/edit/editor-client.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/app/(dashboard)/pipelines/[id]/edit/editor-client.tsx b/src/app/(dashboard)/pipelines/[id]/edit/editor-client.tsx index 1366f30a..0948a253 100644 --- a/src/app/(dashboard)/pipelines/[id]/edit/editor-client.tsx +++ b/src/app/(dashboard)/pipelines/[id]/edit/editor-client.tsx @@ -198,7 +198,11 @@ function PipelineBuilderInner({ pipelineId }: { pipelineId: string }) { const hasLoadedRef = useRef(false); useEffect(() => { if (!pipelineQuery.data) return; - if (hasLoadedRef.current && useFlowStore.getState().isDirty) return; + // Hydrate the store once per mount. Refetches (e.g. the cache invalidation + // after auto-save) must NOT re-run loadGraph: it resets selectedNodeId and + // would kick the user out of the detail/edit panel mid-edit. The store is + // the source of truth while mounted; a remount re-hydrates from fresh data. + if (hasLoadedRef.current) return; hasLoadedRef.current = true; const flowNodes = dbNodesToFlowNodes(pipelineQuery.data.nodes); const flowEdges = dbEdgesToFlowEdges(pipelineQuery.data.edges);