From f37bfbdc561422b7487dd7f3acb7d61cea8894b3 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Thu, 7 May 2026 17:52:50 +0000 Subject: [PATCH] Revert "Reduce timeline active-turn rerenders" This reverts commit 5bf11eac5517894c0b04e6f89eca6550f7718a76. --- .../chat/MessagesTimeline.logic.test.ts | 75 ------------------- .../components/chat/MessagesTimeline.logic.ts | 11 +-- .../src/components/chat/MessagesTimeline.tsx | 17 +++-- 3 files changed, 12 insertions(+), 91 deletions(-) diff --git a/apps/web/src/components/chat/MessagesTimeline.logic.test.ts b/apps/web/src/components/chat/MessagesTimeline.logic.test.ts index 2a79e457e7..633fb5d6be 100644 --- a/apps/web/src/components/chat/MessagesTimeline.logic.test.ts +++ b/apps/web/src/components/chat/MessagesTimeline.logic.test.ts @@ -252,8 +252,6 @@ describe("deriveMessagesTimelineRows", () => { ], completionDividerBeforeEntryId: "assistant-final-entry", isWorking: false, - activeTurnInProgress: false, - activeTurnId: null, activeTurnStartedAt: null, turnDiffSummaryByAssistantMessageId: new Map(), revertTurnCountByUserMessageId: new Map(), @@ -311,8 +309,6 @@ describe("deriveMessagesTimelineRows", () => { ], completionDividerBeforeEntryId: null, isWorking: false, - activeTurnInProgress: false, - activeTurnId: null, activeTurnStartedAt: null, turnDiffSummaryByAssistantMessageId: new Map([ ["assistant-1" as never, assistantTurnDiffSummary], @@ -370,8 +366,6 @@ describe("computeStableMessagesTimelineRows", () => { ], completionDividerBeforeEntryId: null, isWorking: false, - activeTurnInProgress: false, - activeTurnId: null, activeTurnStartedAt: null, turnDiffSummaryByAssistantMessageId: new Map(), revertTurnCountByUserMessageId: new Map(), @@ -388,71 +382,6 @@ describe("computeStableMessagesTimelineRows", () => { expect(repeated.result).toBe(initial.result); }); - it("keeps inactive assistant rows stable when the active turn changes", () => { - const firstAssistantMessage = { - id: "assistant-1" as never, - role: "assistant" as const, - text: "First", - turnId: "turn-1" as never, - createdAt: "2026-01-01T00:00:00Z", - completedAt: "2026-01-01T00:00:01Z", - streaming: false, - }; - const secondAssistantMessage = { - id: "assistant-2" as never, - role: "assistant" as const, - text: "Second", - turnId: "turn-2" as never, - createdAt: "2026-01-01T00:00:10Z", - completedAt: "2026-01-01T00:00:11Z", - streaming: false, - }; - const timelineEntries = [ - { - id: "entry-assistant-1", - kind: "message" as const, - createdAt: firstAssistantMessage.createdAt, - message: firstAssistantMessage, - }, - { - id: "entry-assistant-2", - kind: "message" as const, - createdAt: secondAssistantMessage.createdAt, - message: secondAssistantMessage, - }, - ]; - - const inactiveRows = deriveMessagesTimelineRows({ - timelineEntries, - completionDividerBeforeEntryId: null, - isWorking: false, - activeTurnInProgress: false, - activeTurnId: null, - activeTurnStartedAt: null, - turnDiffSummaryByAssistantMessageId: new Map(), - revertTurnCountByUserMessageId: new Map(), - }); - const initial = computeStableMessagesTimelineRows(inactiveRows, { - byId: new Map(), - result: [], - }); - - const activeRows = deriveMessagesTimelineRows({ - timelineEntries, - completionDividerBeforeEntryId: null, - isWorking: false, - activeTurnInProgress: true, - activeTurnId: "turn-2" as never, - activeTurnStartedAt: null, - turnDiffSummaryByAssistantMessageId: new Map(), - revertTurnCountByUserMessageId: new Map(), - }); - const repeated = computeStableMessagesTimelineRows(activeRows, initial); - - expect(repeated.result[0]).toBe(initial.result[0]); - expect(repeated.result[1]).not.toBe(initial.result[1]); - }); - it("reuses work rows when equivalent timeline derivations create new grouped arrays", () => { const firstWorkEntry = { id: "work-1", @@ -487,8 +416,6 @@ describe("computeStableMessagesTimelineRows", () => { ], completionDividerBeforeEntryId: null, isWorking: false, - activeTurnInProgress: false, - activeTurnId: null, activeTurnStartedAt: null, turnDiffSummaryByAssistantMessageId: new Map(), revertTurnCountByUserMessageId: new Map(), @@ -544,8 +471,6 @@ describe("computeStableMessagesTimelineRows", () => { ], completionDividerBeforeEntryId: null, isWorking: false, - activeTurnInProgress: false, - activeTurnId: null, activeTurnStartedAt: null, turnDiffSummaryByAssistantMessageId: new Map(), revertTurnCountByUserMessageId: new Map(), diff --git a/apps/web/src/components/chat/MessagesTimeline.logic.ts b/apps/web/src/components/chat/MessagesTimeline.logic.ts index 5256aaa13e..c99f0b98a6 100644 --- a/apps/web/src/components/chat/MessagesTimeline.logic.ts +++ b/apps/web/src/components/chat/MessagesTimeline.logic.ts @@ -1,7 +1,7 @@ import * as Equal from "effect/Equal"; import { type TimelineEntry, type WorkLogEntry } from "../../session-logic"; import { type ChatMessage, type ProposedPlan, type TurnDiffSummary } from "../../types"; -import { type MessageId, type TurnId } from "@t3tools/contracts"; +import { type MessageId } from "@t3tools/contracts"; export const MAX_VISIBLE_WORK_LOG_ENTRIES = 6; @@ -27,7 +27,6 @@ export type MessagesTimelineRow = durationStart: string; showCompletionDivider: boolean; showAssistantCopyButton: boolean; - assistantTurnStillInProgress: boolean; assistantTurnDiffSummary?: TurnDiffSummary | undefined; revertTurnCount?: number | undefined; } @@ -113,8 +112,6 @@ export function deriveMessagesTimelineRows(input: { timelineEntries: ReadonlyArray; completionDividerBeforeEntryId: string | null; isWorking: boolean; - activeTurnInProgress: boolean; - activeTurnId: TurnId | null | undefined; activeTurnStartedAt: string | null; turnDiffSummaryByAssistantMessageId: ReadonlyMap; revertTurnCountByUserMessageId: ReadonlyMap; @@ -173,11 +170,6 @@ export function deriveMessagesTimelineRows(input: { showAssistantCopyButton: timelineEntry.message.role === "assistant" && terminalAssistantMessageIds.has(timelineEntry.message.id), - assistantTurnStillInProgress: - timelineEntry.message.role === "assistant" && - input.activeTurnInProgress && - input.activeTurnId != null && - timelineEntry.message.turnId === input.activeTurnId, assistantTurnDiffSummary: timelineEntry.message.role === "assistant" ? input.turnDiffSummaryByAssistantMessageId.get(timelineEntry.message.id) @@ -241,7 +233,6 @@ function isRowUnchanged(a: MessagesTimelineRow, b: MessagesTimelineRow): boolean a.durationStart === bm.durationStart && a.showCompletionDivider === bm.showCompletionDivider && a.showAssistantCopyButton === bm.showAssistantCopyButton && - a.assistantTurnStillInProgress === bm.assistantTurnStillInProgress && a.assistantTurnDiffSummary === bm.assistantTurnDiffSummary && a.revertTurnCount === bm.revertTurnCount ); diff --git a/apps/web/src/components/chat/MessagesTimeline.tsx b/apps/web/src/components/chat/MessagesTimeline.tsx index c44dabe68b..dafa8161bd 100644 --- a/apps/web/src/components/chat/MessagesTimeline.tsx +++ b/apps/web/src/components/chat/MessagesTimeline.tsx @@ -82,6 +82,8 @@ interface TimelineRowSharedState { } interface TimelineRowActivityState { + activeTurnInProgress: boolean; + activeTurnId: TurnId | null; isWorking: boolean; isRevertingCheckpoint: boolean; completionSummary: string | null; @@ -153,8 +155,6 @@ export const MessagesTimeline = memo(function MessagesTimeline({ timelineEntries, completionDividerBeforeEntryId, isWorking, - activeTurnInProgress, - activeTurnId, activeTurnStartedAt, turnDiffSummaryByAssistantMessageId, revertTurnCountByUserMessageId, @@ -163,8 +163,6 @@ export const MessagesTimeline = memo(function MessagesTimeline({ timelineEntries, completionDividerBeforeEntryId, isWorking, - activeTurnInProgress, - activeTurnId, activeTurnStartedAt, turnDiffSummaryByAssistantMessageId, revertTurnCountByUserMessageId, @@ -223,11 +221,13 @@ export const MessagesTimeline = memo(function MessagesTimeline({ ); const activityState = useMemo( () => ({ + activeTurnInProgress, + activeTurnId: activeTurnId ?? null, isWorking, isRevertingCheckpoint, completionSummary, }), - [completionSummary, isRevertingCheckpoint, isWorking], + [activeTurnInProgress, activeTurnId, completionSummary, isRevertingCheckpoint, isWorking], ); // Stable renderItem — no closure deps. Row components read shared state @@ -450,10 +450,15 @@ function AssistantCompletionDivider() { } function AssistantCopyButton({ row }: { row: Extract }) { + const activity = use(TimelineRowActivityCtx); + const assistantTurnStillInProgress = + activity.activeTurnInProgress && + activity.activeTurnId !== null && + row.message.turnId === activity.activeTurnId; const assistantCopyState = resolveAssistantMessageCopyState({ text: row.message.text ?? null, showCopyButton: row.showAssistantCopyButton, - streaming: row.message.streaming || row.assistantTurnStillInProgress, + streaming: row.message.streaming || assistantTurnStillInProgress, }); if (!assistantCopyState.visible) {