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.
This commit is contained in:
Cursor Agent committed 2026-02-18 18:07:38 +00:00
1 parent 4444c8845f
commit 1f7fcb707e
2 files changed
+3 -3

No files matched your search

+2 -2
View File
@@ -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 (
<div className="flex h-screen overflow-hidden bg-background text-foreground isolate">
+1 -1
View File
@@ -125,7 +125,7 @@ function readPersistedState(): AppState {
...hydrated,
threads,
activeThreadId,
threadsHydrated: threads.length > 0,
threadsHydrated: false,
diffOpen: false,
};
} catch {