From 9d705932e62cd6ae56899045660efbd025d83c96 Mon Sep 17 00:00:00 2001 From: Guilhem Lemouel Date: Wed, 23 Sep 2026 18:49:52 +0200 Subject: [PATCH] fix: drop a workspace switch superseded while its item check was in flight Co-Authored-By: Claude Opus 5.5 (1M context) --- frontend/src/lib/components/sidebar/workspaceSwitchUrl.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/frontend/src/lib/components/sidebar/workspaceSwitchUrl.ts b/frontend/src/lib/components/sidebar/workspaceSwitchUrl.ts index 7c668e5cc3..ed4d2f3243 100644 --- a/frontend/src/lib/components/sidebar/workspaceSwitchUrl.ts +++ b/frontend/src/lib/components/sidebar/workspaceSwitchUrl.ts @@ -131,6 +131,8 @@ function editorHasUnsavedEdits(): boolean { }) } +let latestSwitch = 0 + function switchTo(id: string) { workspaceAIClients.init(id) switchWorkspace(id) @@ -149,7 +151,10 @@ export async function switchWorkspaceAndPage( href?: string } ): Promise { + const request = ++latestSwitch const missing = !opts?.landOnHome && (await itemPageMissingIn(id)) + // A switch picked while this lookup was in flight wins. + if (request !== latestSwitch) return // Read after the lookup: the user can edit while it is in flight. const unsavedEdits = editorHasUnsavedEdits() if (opts?.landOnHome || unsavedEdits || missing) {