From 14124ed7e37fed4c60546e242b32ef07579a20fe Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Wed, 18 Feb 2026 09:44:16 +0000 Subject: [PATCH] Fix fallback selecting first turn when selectedDiffTurnId is null When selectedDiffTurnId is null (diff panel closed), the find() returns undefined and the ?? fallback incorrectly selects turnDiffSummaries[0]. This can cause selectedTurnMissingPatchBody to be true after persistence restore, triggering an unwanted auto-session-start for diff hydration. Guard against null the same way DiffPanel already does: return undefined when selectedDiffTurnId is null instead of falling through to the fallback. --- apps/web/src/components/ChatView.tsx | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index f01f226cc2..fc86fb1b32 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -307,7 +307,9 @@ const ComposerCommandMenu = memo(function ComposerCommandMenu(props: { { - props.onHighlightedItemChange(typeof highlightedValue === "string" ? highlightedValue : null); + props.onHighlightedItemChange( + typeof highlightedValue === "string" ? highlightedValue : null, + ); }} >
@@ -831,9 +833,7 @@ export default function ChatView() { } const targetCwd = options?.cwd ?? gitCwd ?? activeProject.cwd; const baseTerminalId = - activeThread.activeTerminalId || - activeThread.terminalIds[0] || - DEFAULT_THREAD_TERMINAL_ID; + activeThread.activeTerminalId || activeThread.terminalIds[0] || DEFAULT_THREAD_TERMINAL_ID; const isBaseTerminalBusy = activeThread.runningTerminalIds.includes(baseTerminalId); const wantsNewTerminal = Boolean(options?.preferNewTerminal) || isBaseTerminalBusy; const shouldCreateNewTerminal = @@ -1487,8 +1487,10 @@ export default function ChatView() { const selectedDiffTurnId = state.diffOpen && state.diffThreadId === activeThreadId ? state.diffTurnId : null; const selectedDiffTurn = - turnDiffSummaries.find((summary) => summary.turnId === selectedDiffTurnId) ?? - turnDiffSummaries[0]; + selectedDiffTurnId === null + ? undefined + : (turnDiffSummaries.find((summary) => summary.turnId === selectedDiffTurnId) ?? + turnDiffSummaries[0]); const selectedTurnMissingPatchBody = Boolean( selectedDiffTurn && !selectedDiffTurn.unifiedDiff &&