fix(ui): failed draft save is retried, then shown — never dropped silently (#1731)
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.
This commit is contained in:
1 file changed
+11
-5
@@ -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<typeof setTimeout> | undefined;
|
||||
async function persistDraft(target: string, value: string): Promise<void> {
|
||||
async function persistDraft(target: string, value: string, attempt = 0): Promise<void> {
|
||||
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<void> {
|
||||
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());
|
||||
</div>
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
<Alert v-if="localError || state.error" variant="destructive"><AlertDescription>
|
||||
{{ localError || state.error }}
|
||||
<Alert v-if="localError || workflows.draftState.error || state.error" variant="destructive"><AlertDescription>
|
||||
{{ localError || workflows.draftState.error || state.error }}
|
||||
</AlertDescription></Alert>
|
||||
<Dialog :open="draftOpen && changes.length > 0" @update:open="(open) => (draftOpen = open)">
|
||||
<DialogContent class="sm:max-w-lg">
|
||||
|
||||
Reference in new issue
Block a user