From ca107f69775a9d0031b376c73bfee16758703dfc Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Fri, 6 Nov 2026 22:09:56 +1100 Subject: [PATCH] =?UTF-8?q?fix(ui):=20failed=20draft=20save=20is=20retried?= =?UTF-8?q?,=20then=20shown=20=E2=80=94=20never=20dropped=20silently=20(#1?= =?UTF-8?q?731)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit persistDraft retried only while draftState.saving was true, but settings.replace clears saving in its finally before resolving false, so the retry branch could never run and a failed putDraft vanished. It now retries on a bounded schedule (5 attempts, 500ms apart) regardless of the saving flag, and on final failure sets localError so the editor's alert says the draft was not saved while the edit stays in the editor. The alert also reads the draft store's own error (workflows.draftState.error) instead of only the definitions store's. --- ui/src/workflows/WorkflowEditor.vue | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/ui/src/workflows/WorkflowEditor.vue b/ui/src/workflows/WorkflowEditor.vue index ff59acdf0..b3a3c92cb 100644 --- a/ui/src/workflows/WorkflowEditor.vue +++ b/ui/src/workflows/WorkflowEditor.vue @@ -188,7 +188,7 @@ watch([collection, () => workflows.drafts], () => { // survives a reload and nothing reaches the running workflow until Publish. // A draft equal to the published definition is removed. let pending: ReturnType | undefined; -async function persistDraft(target: string, value: string): Promise { +async function persistDraft(target: string, value: string, attempt = 0): Promise { if (!target) return; const published = collection.value.definitions.find((entry) => entry.id === target)?.yaml ?? ""; const current = workflows.drafts.find((draft) => draft.id === target)?.yaml; @@ -196,8 +196,14 @@ async function persistDraft(target: string, value: string): Promise { if (next === current) return; if (await workflows.putDraft(target, next)) { if (target === selected.value && value === yaml.value) loadedYaml.value = value; - } else if (workflows.draftState.saving) { - pending = setTimeout(() => void persistDraft(target, value), 500); + } else if (attempt < 4) { + // replace() clears saving before it resolves, so the failure is retried + // here on a bounded schedule rather than only while a save is in flight. + pending = setTimeout(() => void persistDraft(target, value, attempt + 1), 500); + } else if (target === selected.value) { + // The write failed for good: the edit stays in the editor, and the alert + // says the draft was not saved rather than dropping it silently. + localError.value = workflows.draftState.error || "Draft not saved — your edit is still in the editor."; } } // The last edit not yet written, flushed at once when the editor switches @@ -575,8 +581,8 @@ onBeforeUnmount(() => yamlObserver?.disconnect()); - - {{ localError || state.error }} + + {{ localError || workflows.draftState.error || state.error }}