From cbcc66185410945f7cdadd83fc4df15fb096328d Mon Sep 17 00:00:00 2001 From: Brendan Allan Date: Wed, 1 Jul 2026 01:47:48 +0800 Subject: [PATCH] fix(desktop): avoid shared route restore in new windows --- packages/desktop/src/renderer/index.tsx | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/desktop/src/renderer/index.tsx b/packages/desktop/src/renderer/index.tsx index b9e48e7f4c..8a70ed625f 100644 --- a/packages/desktop/src/renderer/index.tsx +++ b/packages/desktop/src/renderer/index.tsx @@ -87,10 +87,12 @@ function windowLastActiveUrlKey(windowID: string) { return `opencode.desktop.window.${windowID}.last-active-url` } -function getLastActiveUrl(windowID: string) { +function getLastActiveUrl(windowID: string, migrateGlobalWindowState: boolean) { if (typeof localStorage !== "object") return "/" try { - const value = localStorage.getItem(windowLastActiveUrlKey(windowID)) ?? localStorage.getItem(lastActiveUrlKey) + const value = + localStorage.getItem(windowLastActiveUrlKey(windowID)) ?? + (migrateGlobalWindowState ? localStorage.getItem(lastActiveUrlKey) : null) if (value?.startsWith("/") && !value.startsWith("//")) return value } catch {} return "/" @@ -103,9 +105,9 @@ function setLastActiveUrl(windowID: string, value: string) { } catch {} } -function DesktopMemoryRouter(props: BaseRouterProps & { windowID: string }) { +function DesktopMemoryRouter(props: BaseRouterProps & { windowID: string; migrateGlobalWindowState: boolean }) { const history = createMemoryHistory() - const initialUrl = getLastActiveUrl(props.windowID) + const initialUrl = getLastActiveUrl(props.windowID, props.migrateGlobalWindowState) if (initialUrl !== "/") history.set({ value: initialUrl, replace: true, scroll: false }) onCleanup(history.listen((value) => setLastActiveUrl(props.windowID, value))) return @@ -347,7 +349,13 @@ function DesktopRoot(props: { windowState: DesktopWindowState }) { const [defaultServer] = createResource(() => platform.getDefaultServer?.()) const [locale] = createResource(loadLocale) - const router = (props: BaseRouterProps) => + const router = (props: BaseRouterProps) => ( + + ) function handleClick(e: MouseEvent) { const link = (e.target as HTMLElement).closest("a.external-link") as HTMLAnchorElement | null