Skip to content

fix(editor): stop autosave refetch from deselecting node mid-edit#509

Merged
TerrifiedBug merged 1 commit into
mainfrom
fix/edit-panel-autosave-deselect
Jun 15, 2026
Merged

fix(editor): stop autosave refetch from deselecting node mid-edit#509
TerrifiedBug merged 1 commit into
mainfrom
fix/edit-panel-autosave-deselect

Conversation

@TerrifiedBug

Copy link
Copy Markdown
Owner

Problem

Editing a pipeline component's config kicked the user out of the detail/edit panel every ~2 seconds. Symptom: components keep "refreshing off" the edit section.

Root cause

Auto-save invalidation loop:

  1. Edit config → isDirty = true
  2. 2s timer fires saveGraph (editor-client.tsx:449)
  3. onSuccessmarkClean() sets isDirty = false (flow-store.ts:1094) and invalidates pipeline.get (editor-client.tsx:292)
  4. Refetch produces a new pipelineQuery.data ref → hydration effect reruns
  5. Guard if (hasLoadedRef.current && isDirty) return; fails because isDirty is now falseloadGraph() runs again
  6. loadGraph resets selectedNodeId: null (flow-store.ts:1169) → detail panel deselects the node

Server data was identical to the store, so the reload was pointless and destroyed the selection. The clean-state reload guard backfired: save makes the store clean, then the refetch reloads.

Fix

Hydrate the store once per mount. Refetches no longer re-run loadGraph. A remount (navigate away/back) resets hasLoadedRef and re-hydrates from fresh data; while mounted the store remains the source of truth.

Test plan

  • Edit a pipeline component config, wait >2s for autosave, confirm the detail panel stays open on the selected node
  • Navigate away and back, confirm graph re-hydrates from server
  • Confirm undo/redo and dirty-state save still work

Follow-up (not in this PR)

detail-panel.tsx:418 runs a duplicate pipeline.get query (same key as parent), causing extra refetches/flicker on invalidate. Consider passing pipeline data down as a prop.

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.
@github-actions github-actions Bot added the fix label Jun 15, 2026
@TerrifiedBug TerrifiedBug merged commit 7f41aa7 into main Jun 15, 2026
7 checks passed
@TerrifiedBug TerrifiedBug deleted the fix/edit-panel-autosave-deselect branch June 15, 2026 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant