diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index 92400fedd9b3..8c4f5875281e 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -2166,9 +2166,16 @@ export default function ChatView(props: ChatViewProps) { } return labels; }, [activeThreadKnownSessions]); + // Keyed on ids only: the thread object changes identity on every streamed + // update, and effects keyed on this ref (e.g. the diff scope reset) must not + // re-run mid-turn. + const activeThreadEnvironmentId = activeThread?.environmentId ?? null; const activeThreadRef = useMemo( - () => (activeThread ? scopeThreadRef(activeThread.environmentId, activeThread.id) : null), - [activeThread], + () => + activeThreadEnvironmentId !== null && activeThreadId !== null + ? scopeThreadRef(activeThreadEnvironmentId, activeThreadId) + : null, + [activeThreadEnvironmentId, activeThreadId], ); const activeThreadKey = activeThreadRef ? scopedThreadKey(activeThreadRef) : null; const previewPanelInlineSize = usePreviewPanelInlineSize(undefined, {