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, + } + : {}), }; }