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 }}