From 202b3f69d8bbefebfd1493eb970df1fb996973f5 Mon Sep 17 00:00:00 2001 From: Diego Imbert Date: Fri, 15 May 2026 15:41:26 +0200 Subject: [PATCH] fix(frontend): drop in-memory handle in DiffDrawer restoreDraft/restoreDeployed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Same UserDraft.remove-without-clearing-in-memory bug as the previous two commits, this time in the DiffDrawer's "Restore to draft" / "Restore to deployed" buttons on all four /edit routes. The handler deletes the DB draft (in the deployed case), wipes the localStorage entry, navigates, and reloads — but the route's UserDraft handle still holds the old draft + meta in memory, so the reload's staleness check compares the stale meta against the freshly fetched backend and surfaces a spurious "newer version was deployed" modal. - scripts/edit, flows/edit, apps_raw/edit: route-level handle — `handle.setDraftAndMeta(undefined, {})` before the reload. - apps/edit: the handle lives in the AppEditor child, so force a remount by setting `app = undefined; redraw++` before goto/loadApp (matches the existing pattern from the toast's onResetToDeployed). --- .../(root)/(logged)/apps/edit/[...path]/+page.svelte | 8 ++++++++ .../(root)/(logged)/apps_raw/edit/[...path]/+page.svelte | 6 ++++++ .../(root)/(logged)/flows/edit/[...path]/+page.svelte | 6 ++++++ .../(root)/(logged)/scripts/edit/[...path]/+page.svelte | 6 ++++++ 4 files changed, 26 insertions(+) diff --git a/frontend/src/routes/(root)/(logged)/apps/edit/[...path]/+page.svelte b/frontend/src/routes/(root)/(logged)/apps/edit/[...path]/+page.svelte index 5f4813c75f..bb6989e65b 100644 --- a/frontend/src/routes/(root)/(logged)/apps/edit/[...path]/+page.svelte +++ b/frontend/src/routes/(root)/(logged)/apps/edit/[...path]/+page.svelte @@ -239,6 +239,12 @@ } diffDrawer?.closeDrawer() UserDraft.remove('app', path) + // Force AppEditor to unmount so its UserDraft handle releases — + // otherwise loadApp's `UserDraft.get` would read the stale autosave + // from the still-alive in-memory entry and the staleness check + // would fire a spurious "newer version was deployed" modal. + app = undefined + redraw++ goto(`/apps/edit/${savedApp.draft.path}`) await loadApp() redraw++ @@ -258,6 +264,8 @@ }) } UserDraft.remove('app', path) + app = undefined + redraw++ goto(`/apps/edit/${savedApp.path}`) await loadApp() redraw++ diff --git a/frontend/src/routes/(root)/(logged)/apps_raw/edit/[...path]/+page.svelte b/frontend/src/routes/(root)/(logged)/apps_raw/edit/[...path]/+page.svelte index d8444f0197..a09776a0ee 100644 --- a/frontend/src/routes/(root)/(logged)/apps_raw/edit/[...path]/+page.svelte +++ b/frontend/src/routes/(root)/(logged)/apps_raw/edit/[...path]/+page.svelte @@ -278,6 +278,11 @@ } diffDrawer?.closeDrawer() UserDraft.remove('raw_app', path) + // Drop the in-memory handle state so loadApp sees no local draft + // on the next pass — otherwise the staleness check would compare + // the stale in-memory meta against the freshly fetched backend and + // fire a spurious modal. + draftHandle.setDraftAndMeta(undefined, {}) goto(`/apps/edit/${savedApp.draft.path}`) await loadApp() redraw++ @@ -297,6 +302,7 @@ }) } UserDraft.remove('raw_app', path) + draftHandle.setDraftAndMeta(undefined, {}) goto(`/apps/edit/${savedApp.path}`) await loadApp() redraw++ diff --git a/frontend/src/routes/(root)/(logged)/flows/edit/[...path]/+page.svelte b/frontend/src/routes/(root)/(logged)/flows/edit/[...path]/+page.svelte index b0042e2ebd..a52f3edd95 100644 --- a/frontend/src/routes/(root)/(logged)/flows/edit/[...path]/+page.svelte +++ b/frontend/src/routes/(root)/(logged)/flows/edit/[...path]/+page.svelte @@ -304,6 +304,11 @@ } diffDrawer?.closeDrawer() UserDraft.remove('flow', flowDraftPath) + // Drop the in-memory handle state so loadFlow sees no local draft + // on the next pass — otherwise the staleness check would compare + // the stale in-memory meta against the freshly fetched backend and + // fire a spurious modal. + flowHandle.setDraftAndMeta(undefined, {}) goto(`/flows/edit/${savedFlow.draft.path}`) loadFlow() } @@ -322,6 +327,7 @@ }) } UserDraft.remove('flow', flowDraftPath) + flowHandle.setDraftAndMeta(undefined, {}) goto(`/flows/edit/${savedFlow.path}`) loadFlow() } diff --git a/frontend/src/routes/(root)/(logged)/scripts/edit/[...path]/+page.svelte b/frontend/src/routes/(root)/(logged)/scripts/edit/[...path]/+page.svelte index 0faec2326c..6f18a23e4f 100644 --- a/frontend/src/routes/(root)/(logged)/scripts/edit/[...path]/+page.svelte +++ b/frontend/src/routes/(root)/(logged)/scripts/edit/[...path]/+page.svelte @@ -299,6 +299,11 @@ } diffDrawer?.closeDrawer() UserDraft.remove('script', draftPath) + // Drop the in-memory handle state so loadScript sees no local draft + // on the next pass — otherwise the staleness check would compare the + // stale in-memory meta against the freshly fetched backend and fire + // a spurious modal. + scriptHandle.setDraftAndMeta(undefined, {}) goto(`/scripts/edit/${savedScript.draft.path}`) loadScript() } @@ -317,6 +322,7 @@ }) } UserDraft.remove('script', draftPath) + scriptHandle.setDraftAndMeta(undefined, {}) goto(`/scripts/edit/${savedScript.path}`) loadScript() }