diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index bdd2c87dac..361ac9267e 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -764,8 +764,11 @@ export default function ChatView({ threadId }: ChatViewProps) { const hasReachedTerminalLimit = (activeThread?.terminalIds.length ?? 0) >= MAX_THREAD_TERMINAL_COUNT; + const prevSyncedThreadIdRef = useRef(undefined); + useEffect(() => { if (!api || !activeThread) return; + if (prevSyncedThreadIdRef.current !== activeThread.id) return; void api.threads .updateTitle({ threadId: activeThread.id, @@ -776,6 +779,7 @@ export default function ChatView({ threadId }: ChatViewProps) { useEffect(() => { if (!api || !activeThread) return; + if (prevSyncedThreadIdRef.current !== activeThread.id) return; void api.threads .updateModel({ threadId: activeThread.id, @@ -786,6 +790,7 @@ export default function ChatView({ threadId }: ChatViewProps) { useEffect(() => { if (!api || !activeThread) return; + if (prevSyncedThreadIdRef.current !== activeThread.id) return; void api.threads .updateBranch({ threadId: activeThread.id, @@ -797,6 +802,7 @@ export default function ChatView({ threadId }: ChatViewProps) { useEffect(() => { if (!api || !activeThread) return; + if (prevSyncedThreadIdRef.current !== activeThread.id) return; void api.threads .updateTerminalState({ threadId: activeThread.id, @@ -819,6 +825,10 @@ export default function ChatView({ threadId }: ChatViewProps) { api, ]); + useEffect(() => { + prevSyncedThreadIdRef.current = activeThread?.id; + }, [activeThread?.id]); + const revokePreviewUrls = useCallback((images: Array<{ previewUrl?: string }>) => { for (const image of images) { if (!image.previewUrl) continue; diff --git a/apps/web/src/store.ts b/apps/web/src/store.ts index 87d09d5bbb..d51820784f 100644 --- a/apps/web/src/store.ts +++ b/apps/web/src/store.ts @@ -649,9 +649,9 @@ export function reducer(state: AppState, action: Action): AppState { ...(threadPayload as unknown as Omit), messages: existingStateMessages, turnDiffSummaries: - (threadPayload?.turnDiffSummaries as Thread["turnDiffSummaries"] | undefined) ?? - existing?.turnDiffSummaries ?? - [], + (threadPayload?.turnDiffSummaries as Thread["turnDiffSummaries"] | undefined)?.length + ? (threadPayload!.turnDiffSummaries as Thread["turnDiffSummaries"]) + : (existing?.turnDiffSummaries ?? []), }; const nextThread = hydrateThreadFromBootstrap(bootstrapThread, existing); const nextThreads = existing