Revert "Reduce timeline active-turn rerenders"

This reverts commit 5bf11eac55.
This commit is contained in:
Cursor Agent committed 2026-05-07 17:52:50 +00:00
1 parent 5bf11eac55
commit f37bfbdc56
3 files changed
+12 -91

No files matched your search

@@ -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(),
@@ -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<TimelineEntry>;
completionDividerBeforeEntryId: string | null;
isWorking: boolean;
activeTurnInProgress: boolean;
activeTurnId: TurnId | null | undefined;
activeTurnStartedAt: string | null;
turnDiffSummaryByAssistantMessageId: ReadonlyMap<MessageId, TurnDiffSummary>;
revertTurnCountByUserMessageId: ReadonlyMap<MessageId, number>;
@@ -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
);
@@ -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<TimelineRowActivityState>(
() => ({
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<TimelineRow, { kind: "message" }> }) {
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) {