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.
This commit is contained in:
Cursor Agent committed 2026-02-18 18:28:25 +00:00
1 parent de9c059a64
commit 141f6d2ed9
5 files changed
+27 -50

No files matched your search

+3 -3
View File
@@ -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;
+9 -3
View File
@@ -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]);
+4 -2
View File
@@ -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;
+11 -1
View File
@@ -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) };
-41
View File
@@ -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,
},
});