From 1f7fcb707ee60a72594bc6daece30d83180c21f1 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Wed, 18 Feb 2026 18:07:38 +0000 Subject: [PATCH] Fix race condition navigating to stale thread on Electron app launch In Electron mode, readPersistedState() was setting threadsHydrated: true immediately when restoring threads from localStorage, before DesktopProjectBootstrap could run SYNC_PROJECTS to filter out threads whose projects no longer exist. This caused a flash where users would briefly see a stale thread view before being redirected to /. Two changes: - readPersistedState() now always sets threadsHydrated: false, deferring to the bootstrap components to set it true after validation. - _chat.tsx layout effect now checks threadsHydrated before navigating to the persisted activeThreadId, preventing premature navigation. --- apps/web/src/routes/_chat.tsx | 4 ++-- apps/web/src/store.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/web/src/routes/_chat.tsx b/apps/web/src/routes/_chat.tsx index d903f06056..045a82ea53 100644 --- a/apps/web/src/routes/_chat.tsx +++ b/apps/web/src/routes/_chat.tsx @@ -12,13 +12,13 @@ function ChatRouteLayout() { const routeThreadId = typeof params.threadId === "string" ? params.threadId : null; useEffect(() => { - if (routeThreadId || !state.activeThreadId) return; + if (routeThreadId || !state.activeThreadId || !state.threadsHydrated) return; void navigate({ to: "/$threadId", params: { threadId: state.activeThreadId }, replace: true, }); - }, [navigate, routeThreadId, state.activeThreadId]); + }, [navigate, routeThreadId, state.activeThreadId, state.threadsHydrated]); return (
diff --git a/apps/web/src/store.ts b/apps/web/src/store.ts index bedf813044..764fb31094 100644 --- a/apps/web/src/store.ts +++ b/apps/web/src/store.ts @@ -125,7 +125,7 @@ function readPersistedState(): AppState { ...hydrated, threads, activeThreadId, - threadsHydrated: threads.length > 0, + threadsHydrated: false, diffOpen: false, }; } catch {