From ef33a833b82139f0432c8255f720e4e5ee5e5937 Mon Sep 17 00:00:00 2001 From: Diego Imbert Date: Mon, 8 Jun 2026 01:30:18 +0200 Subject: [PATCH] fix(drafts): wait for the fork POST to land before navigating MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit OtherUsersDraftsModal's Fork action called UserDraft.save, which routes through the autosave debouncer (1500ms). The subsequent goto fired within the same tick, so the destination editor's get_draft=true read ran before the POST landed and 404'd — refreshing worked because by then the debounced save had fired. Call UserDraftDbSyncer.save with immediate: true and await it. The syncer cancels any queued debouncer task for the key and resolves the promise only after the POST completes, so the route load can find the forked draft on the first try. --- .../OtherUsersDraftsModal.svelte | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/frontend/src/lib/components/common/confirmationModal/OtherUsersDraftsModal.svelte b/frontend/src/lib/components/common/confirmationModal/OtherUsersDraftsModal.svelte index f49132a425..0609f16bef 100644 --- a/frontend/src/lib/components/common/confirmationModal/OtherUsersDraftsModal.svelte +++ b/frontend/src/lib/components/common/confirmationModal/OtherUsersDraftsModal.svelte @@ -18,7 +18,7 @@ import Modal2 from '$lib/components/common/modal/Modal2.svelte' import Button from '$lib/components/common/button/Button.svelte' import Tooltip from '$lib/components/Tooltip.svelte' - import { UserDraft } from '$lib/userDraft.svelte' + import { UserDraftDbSyncer } from '$lib/userDraftDbSyncer.svelte' export type OtherDraftUser = { username?: string | null } @@ -94,7 +94,19 @@ try { const value = await fetchDraft(owner) const target = forkPath(owner) - UserDraft.save(itemKind, target, value, { workspace }) + // Bypass the autosave debouncer so the fork lands on the + // server BEFORE we navigate. The destination route loads + // via `getDraft=true` and 404s if no draft yet exists at + // the fork path — the prior `UserDraft.save` call + // scheduled a debounced POST 1.5s out, so a fresh nav was + // always too early. + await UserDraftDbSyncer.save({ + workspace, + itemKind, + path: target, + value, + immediate: true + }) isOpen = false goto(editPathFor(target)) } catch (e) {