From 04e6a947fc6b5ab6bc5bda101333d974cfb4065c Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Wed, 18 Feb 2026 18:47:11 +0000 Subject: [PATCH] fix: clear stale diff panel targets in DELETE_PROJECT and SYNC_PROJECTS reducers When threads are removed by DELETE_PROJECT or SYNC_PROJECTS, the diff panel state (diffOpen, diffThreadId, diffTurnId, diffFilePath) was not being cleared if the removed threads included the one referenced by diffThreadId. This mirrors the cleanup already done in DELETE_THREAD. --- apps/web/src/store.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/apps/web/src/store.ts b/apps/web/src/store.ts index 06f3e10523..a8d2d7dd7f 100644 --- a/apps/web/src/store.ts +++ b/apps/web/src/store.ts @@ -602,12 +602,22 @@ export function reducer(state: AppState, action: Action): AppState { const activeThreadId = nextThreads.some((thread) => thread.id === state.activeThreadId) ? state.activeThreadId : (nextThreads[0]?.id ?? null); + const shouldClearDiffTarget = + state.diffThreadId !== null && !nextThreads.some((t) => t.id === state.diffThreadId); return { ...state, projects: nextProjects, threads: nextThreads, activeThreadId, + ...(shouldClearDiffTarget + ? { + diffOpen: false, + diffThreadId: null, + diffTurnId: null, + diffFilePath: null, + } + : {}), }; } @@ -629,12 +639,22 @@ export function reducer(state: AppState, action: Action): AppState { const activeThreadId = threads.some((thread) => thread.id === state.activeThreadId) ? state.activeThreadId : (threads[0]?.id ?? null); + const shouldClearDiffTarget = + state.diffThreadId !== null && !threads.some((t) => t.id === state.diffThreadId); return { ...state, projects, threads, activeThreadId, + ...(shouldClearDiffTarget + ? { + diffOpen: false, + diffThreadId: null, + diffTurnId: null, + diffFilePath: null, + } + : {}), }; }