From 141f6d2ed9840a3ceca93b6807007995ceaa817a Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Wed, 18 Feb 2026 18:28:25 +0000 Subject: [PATCH] Fix 5 bugs: dropped events, lastVisitedAt, bootstrap thread, duplicate config, delete race - Remove early return guard in EventRouter that silently dropped all provider events when no thread was active (e.g., user on index route). Use a ref for activeThreadId to avoid re-subscribing the event listener on navigation. - Add VISIT_THREAD action to update lastVisitedAt when navigating to a thread, restoring the ability to dismiss the 'Completed' pill in the sidebar. - Restore ADD_THREAD dispatch in AutoProjectBootstrap so first-time browser users get an initial thread instead of a blank placeholder. - Delete duplicate vite.config.js that duplicated the existing vite.config.ts. - Await navigation before dispatching DELETE_THREAD in sidebar to prevent the route guard redirect from racing and overriding the fallback thread navigation. --- apps/web/src/components/Sidebar.tsx | 6 ++-- apps/web/src/routes/__root.tsx | 12 ++++++-- apps/web/src/routes/_chat.$threadId.tsx | 6 ++-- apps/web/src/store.ts | 12 +++++++- apps/web/vite.config.js | 41 ------------------------- 5 files changed, 27 insertions(+), 50 deletions(-) delete mode 100644 apps/web/vite.config.js diff --git a/apps/web/src/components/Sidebar.tsx b/apps/web/src/components/Sidebar.tsx index ed74580e34..c4128d33c5 100644 --- a/apps/web/src/components/Sidebar.tsx +++ b/apps/web/src/components/Sidebar.tsx @@ -310,18 +310,18 @@ export default function Sidebar() { const shouldNavigateToFallback = routeThreadId === threadId; const fallbackThreadId = state.threads.find((entry) => entry.id !== threadId)?.id ?? null; - dispatch({ type: "DELETE_THREAD", threadId }); if (shouldNavigateToFallback) { if (fallbackThreadId) { - void navigate({ + await navigate({ to: "/$threadId", params: { threadId: fallbackThreadId }, replace: true, }); } else { - void navigate({ to: "/", replace: true }); + await navigate({ to: "/", replace: true }); } } + dispatch({ type: "DELETE_THREAD", threadId }); if (!shouldDeleteWorktree || !orphanedWorktreePath || !threadProject) { return; diff --git a/apps/web/src/routes/__root.tsx b/apps/web/src/routes/__root.tsx index 33b578674b..033b3ad95f 100644 --- a/apps/web/src/routes/__root.tsx +++ b/apps/web/src/routes/__root.tsx @@ -8,6 +8,7 @@ import { useNativeApi } from "../hooks/useNativeApi"; import { invalidateGitQueries } from "../lib/gitReactQuery"; import { DEFAULT_MODEL } from "../model-logic"; import { useStore } from "../store"; +import { createThread } from "../threadFactory"; import { onServerWelcome } from "../wsNativeApi"; export const Route = createRootRouteWithContext<{ @@ -50,6 +51,8 @@ function EventRouter() { strict: false, select: (params) => params.threadId, }); + const activeThreadIdRef = useRef(activeThreadId); + activeThreadIdRef.current = activeThreadId; useEffect(() => { if (!api) return; @@ -57,15 +60,14 @@ function EventRouter() { if (event.method === "turn/completed") { void invalidateGitQueries(queryClient); } - if (!activeThreadId) return; dispatch({ type: "APPLY_EVENT", event, activeAssistantItemRef, - activeThreadId, + activeThreadId: activeThreadIdRef.current, }); }); - }, [activeThreadId, api, dispatch, queryClient]); + }, [api, dispatch, queryClient]); useEffect(() => { if (!api) return; @@ -115,6 +117,10 @@ function AutoProjectBootstrap() { scripts: [], }, }); + dispatch({ + type: "ADD_THREAD", + thread: createThread(projectId), + }); dispatch({ type: "SET_THREADS_HYDRATED", hydrated: true }); }); }, [state.projects, dispatch]); diff --git a/apps/web/src/routes/_chat.$threadId.tsx b/apps/web/src/routes/_chat.$threadId.tsx index 066f657ea3..ef6e44771a 100644 --- a/apps/web/src/routes/_chat.$threadId.tsx +++ b/apps/web/src/routes/_chat.$threadId.tsx @@ -5,7 +5,7 @@ import ChatView from "../components/ChatView"; import { useStore } from "../store"; function ChatThreadRouteView() { - const { state } = useStore(); + const { state, dispatch } = useStore(); const navigate = useNavigate(); const { threadId } = Route.useParams(); const threadExists = threadId ? state.threads.some((thread) => thread.id === threadId) : false; @@ -24,7 +24,9 @@ function ChatThreadRouteView() { void navigate({ to: "/", replace: true }); return; } - }, [navigate, state.threadsHydrated, threadExists, threadId]); + + dispatch({ type: "VISIT_THREAD", threadId }); + }, [dispatch, navigate, state.threadsHydrated, threadExists, threadId]); if (!threadId || !state.threadsHydrated || !threadExists) { return null; diff --git a/apps/web/src/store.ts b/apps/web/src/store.ts index f44c82e775..d9a304f3fc 100644 --- a/apps/web/src/store.ts +++ b/apps/web/src/store.ts @@ -67,7 +67,8 @@ type Action = worktreePath: string | null; } | { type: "SET_RUNTIME_MODE"; mode: RuntimeMode } - | { type: "DELETE_THREAD"; threadId: string }; + | { type: "DELETE_THREAD"; threadId: string } + | { type: "VISIT_THREAD"; threadId: string }; // ── State ──────────────────────────────────────────────────────────── @@ -849,6 +850,15 @@ export function reducer(state: AppState, action: Action): AppState { runtimeMode: action.mode, }; + case "VISIT_THREAD": + return { + ...state, + threads: updateThread(state.threads, action.threadId, (t) => ({ + ...t, + lastVisitedAt: new Date().toISOString(), + })), + }; + case "DELETE_THREAD": return { ...state, threads: state.threads.filter((t) => t.id !== action.threadId) }; diff --git a/apps/web/vite.config.js b/apps/web/vite.config.js deleted file mode 100644 index d1e1f60426..0000000000 --- a/apps/web/vite.config.js +++ /dev/null @@ -1,41 +0,0 @@ -import tailwindcss from "@tailwindcss/vite"; -import react from "@vitejs/plugin-react"; -import { tanstackRouter } from "@tanstack/router-plugin/vite"; -import { defineConfig } from "vite"; -const port = Number(process.env.PORT ?? 5173); -export default defineConfig({ - plugins: [ - tanstackRouter(), - react({ - babel: { - plugins: [["babel-plugin-react-compiler", { target: "19" }]], - }, - }), - tailwindcss(), - ], - define: { - // In dev mode, tell the web app where the WebSocket server lives - "import.meta.env.VITE_WS_URL": JSON.stringify(process.env.VITE_WS_URL ?? ""), - }, - experimental: { - enableNativePlugin: true, - }, - resolve: { - tsconfigPaths: true, - }, - server: { - port, - strictPort: true, - hmr: { - // Explicit config so Vite's HMR WebSocket connects reliably - // inside Electron's BrowserWindow. Vite 8 uses console.debug for - // connection logs — enable "Verbose" in DevTools to see them. - protocol: "ws", - host: "localhost", - }, - }, - build: { - outDir: "dist", - emptyOutDir: true, - }, -});