The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 07:00 UTC
perf(web): chat view redraws no longer re-render the composer or side chat timeline (#28564)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>
Andrei committed
Nov 2, 2026 at 05:55 UTC
bcc6c08d751dec337f41c8684939776b60b3528f
5 files changed
+101
-33
apps/web/src/components/ChatView.tsx
+20
-15
@@ -382,6 +382,7 @@ const EMPTY_FEEDBACK_SUBMISSIONS: ReadonlyArray<CodexFeedbackSubmission> = [];
382
const EMPTY_PROVIDER_SKILLS: ServerProvider["skills"] = [];
383
const EMPTY_TURN_ITEMS: ThreadStructure["turnItems"] = [];
384
const EMPTY_AUTO_UPDATE_ENVIRONMENTS: ReadonlyArray<EnvironmentPresentation> = [];
385
+const EMPTY_COMPOSER_BANNER_ITEMS: ReadonlyArray<ComposerBannerStackItem> = [];
386
387
const EMPTY_PENDING_FILE_SURFACE_IDS: ReadonlySet<string> = new Set();
388
@@ -866,20 +867,18 @@ export default function ChatView(props: ChatViewProps) {
867
const sideChatParent = useQuietThreadShell(sideChatParentRef);
868
const parentThreadLink = (() => {
869
if (sideChatParentRef !== null) {
870
+ const title = sideChatParent?.title ?? "Parent thread";
871
+ // Embedded, the parent is the view around it.
872
+ if (embedded) return { title, sideChat: true };
873
return {
870
- title: sideChatParent?.title ?? "Parent thread",
874
+ title,
875
sideChat: true,
872
- // Embedded, the parent is the view around it.
873
- ...(embedded
874
- ? {}
875
- : {
876
- open: (): void => {
877
- void navigate({
878
- to: "/$environmentId/$threadId",
879
- params: buildThreadRouteParams(sideChatParentRef),
880
- });
881
- },
882
- }),
876
+ open: (): void => {
877
+ void navigate({
878
+ to: "/$environmentId/$threadId",
879
+ params: buildThreadRouteParams(sideChatParentRef),
880
+ });
881
+ },
882
};
883
}
884
if (parentSubagentThreadRef !== null) {
@@ -3586,7 +3585,7 @@ export default function ChatView(props: ChatViewProps) {
3585
activeThreadId={activeThreadId}
3586
activeThread={activeThread}
3587
activeThreadShell={activeThreadShell}
3589
- promptHistoryMessages={timelineMessages}
3588
+ promptHistoryEntries={timelineEntries}
3589
forceExpandedOnMobile={
3590
forceExpandedMobileComposer && isDraftHeroState
3591
}
@@ -3621,7 +3620,11 @@ export default function ChatView(props: ChatViewProps) {
3620
: projectCloneSendBlockReason
3621
}
3622
isPreparingWorktree={isPreparingWorktree && !sendQueuesBehindSetup}
3624
- bannerItems={isDraftHeroState ? [] : composerBannerItems}
3623
+ bannerItems={
3624
+ isDraftHeroState || composerBannerItems.length === 0
3625
+ ? EMPTY_COMPOSER_BANNER_ITEMS
3626
+ : composerBannerItems
3627
+ }
3628
resumeCompactionTokens={resumeCompactionTokens}
3629
keepFullHistory={keepFullHistory}
3630
onToggleKeepFullHistory={toggleKeepFullHistoryStable}
@@ -3661,7 +3664,9 @@ export default function ChatView(props: ChatViewProps) {
3664
}
3665
activeThreadModelSelection={activeThread?.modelSelection}
3666
activeProjectId={activeProject?.id ?? null}
3664
- activeContextWindow={activeContextWindow}
3667
+ contextWindowEntries={serverVisibleTurnItems}
3668
+ contextWindowLiveUsage={activeThreadLiveTokenUsage}
3669
+ contextWindowProviderThread={activeProviderThread}
3670
compactThreadUnavailable={compactThreadUnavailable}
3671
compactDisabled={compactDisabled}
3672
compactDisabledReason={compactDisabledReason}
apps/web/src/components/chat/ChatComposer.tsx
+17
-13
@@ -239,25 +239,20 @@ import { proposedPlanTitle } from "@t3tools/shared/proposedPlanText";
239
import { hasProviderSetup } from "./ProviderStatusBanner";
240
import { type AppModelOption, getAppModelOptionsForInstance } from "../../modelSelection";
241
import type { UnifiedSettings } from "@t3tools/contracts/settings";
242
-import {
243
- isVideoAttachment,
244
- type ChatMessage,
245
- type SessionPhase,
246
- type Thread,
247
- type ThreadShell,
248
-} from "../../types";
242
+import { isVideoAttachment, type SessionPhase, type Thread, type ThreadShell } from "../../types";
243
import { type ComposerPromptHistoryPosition } from "./composerPromptHistory";
244
import type { PendingUserInputDraftAnswer } from "@t3tools/client-runtime/state/pending-user-input";
245
import type {
246
LatestProposedPlanState,
247
PendingApproval,
248
PendingUserInput,
249
+ TimelineEntry,
250
} from "../../session-logic";
251
import {
252
resolveComposerDispatchMode,
253
type ComposerDispatchMode,
254
} from "@t3tools/client-runtime/state/composer-dispatch";
260
-import type { ContextWindowSnapshot } from "../../lib/contextWindow";
255
+import { deriveLatestContextWindowSnapshot } from "../../lib/contextWindow";
256
import {
257
resolveProviderSkillsForCwd,
258
resolveProviderSlashCommandsForCwd,
@@ -371,7 +366,7 @@ export interface ChatComposerProps {
366
activeThreadId: ThreadId | null;
367
activeThread: Thread | undefined;
368
activeThreadShell: ThreadShell | null;
374
- promptHistoryMessages: ReadonlyArray<ChatMessage>;
369
+ promptHistoryEntries: ReadonlyArray<TimelineEntry>;
370
forceExpandedOnMobile: boolean;
371
projectSelectionRequired: boolean;
372
@@ -433,7 +428,9 @@ export interface ChatComposerProps {
428
reportedModelSelection?: ModelSelection | null;
429
activeProjectId: ProjectId | null;
430
436
- activeContextWindow: ContextWindowSnapshot | null;
431
+ contextWindowEntries: Parameters<typeof deriveLatestContextWindowSnapshot>[0];
432
+ contextWindowLiveUsage: Parameters<typeof deriveLatestContextWindowSnapshot>[1];
433
+ contextWindowProviderThread: Parameters<typeof deriveLatestContextWindowSnapshot>[2];
434
compactThreadUnavailable: boolean;
435
compactDisabled: boolean;
436
compactDisabledReason: string | null;
@@ -524,7 +521,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
521
onMultipleModelSelectionsChange: setMultipleModelSelections,
522
activeThreadId,
523
activeThread,
527
- promptHistoryMessages,
524
+ promptHistoryEntries,
525
forceExpandedOnMobile,
526
projectSelectionRequired,
527
phase,
@@ -557,7 +554,9 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
554
activeThreadModelSelection,
555
reportedModelSelection,
556
activeProjectId,
560
- activeContextWindow,
557
+ contextWindowEntries,
558
+ contextWindowLiveUsage,
559
+ contextWindowProviderThread,
560
compactThreadUnavailable,
561
compactDisabled,
562
compactDisabledReason,
@@ -602,6 +601,11 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
601
editingQueuedAttachments,
602
onRemoveEditingQueuedAttachment,
603
} = props;
604
+ const activeContextWindow = deriveLatestContextWindowSnapshot(
605
+ contextWindowEntries,
606
+ contextWindowLiveUsage,
607
+ contextWindowProviderThread,
608
+ );
609
const primaryEnvironmentId = usePrimaryEnvironmentId();
610
const composerDraftTargetKey = composerTargetKey(composerDraftTarget);
611
const {
@@ -2210,7 +2214,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
2214
planModeUiEnabled,
2215
isLiteralPendingAnswer,
2216
pendingUserInputs,
2213
- promptHistoryMessages,
2217
+ promptHistoryEntries,
2218
promptHistoryPositionRef,
2219
composerDraftTarget,
2220
promptRef,
apps/web/src/components/chat/composerCommandKey.ts
+5
-3
@@ -44,7 +44,7 @@ export function composerCommandKeyHandler(input: {
44
readonly planModeUiEnabled: boolean;
45
readonly isLiteralPendingAnswer: boolean;
46
readonly pendingUserInputs: ReadonlyArray<PendingUserInput>;
47
- readonly promptHistoryMessages: ChatComposerProps["promptHistoryMessages"];
47
+ readonly promptHistoryEntries: ChatComposerProps["promptHistoryEntries"];
48
readonly promptHistoryPositionRef: RefObject<{
49
targetKey: string;
50
position: ComposerPromptHistoryPosition;
@@ -96,7 +96,7 @@ export function composerCommandKeyHandler(input: {
96
planModeUiEnabled,
97
isLiteralPendingAnswer,
98
pendingUserInputs,
99
- promptHistoryMessages,
99
+ promptHistoryEntries,
100
promptHistoryPositionRef,
101
composerDraftTarget,
102
promptRef,
@@ -165,7 +165,9 @@ export function composerCommandKeyHandler(input: {
165
const step = stepComposerPromptHistory({
166
direction,
167
// Built on the keypress, not per render: the timeline changes on every streamed delta.
168
- entries: buildComposerPromptHistoryEntries(promptHistoryMessages),
168
+ entries: buildComposerPromptHistoryEntries(
169
+ promptHistoryEntries.flatMap((entry) => (entry.kind === "message" ? [entry.message] : [])),
170
+ ),
171
position,
172
currentPrompt: promptRef.current,
173
});
apps/web/test/appScenarios.renders.tsx
+37
-1
@@ -3,6 +3,7 @@
3
// chat and settings routes, the sidebar and the right panel, through the same stores and
4
// atoms the app reads. See renderScenarios.renders.tsx for the counting rules.
5
import { createMemoryHistory } from "@tanstack/react-router";
6
+import { scopeThreadRef } from "@t3tools/client-runtime/environment";
7
import type { ThreadId } from "@t3tools/contracts";
8
import { DEFAULT_CLIENT_SETTINGS } from "@t3tools/contracts/settings";
9
import type * as Context from "effect/Context";
@@ -13,12 +14,14 @@ import "~/index.css";
14
15
import { AppRoot } from "~/AppRoot";
16
import { __setClientSettingsForTests } from "~/hooks/useSettings";
17
+import { useRightPanelStore } from "~/rightPanelStore";
18
import { getRouter, type AppRouter } from "~/router";
19
import {
20
ENVIRONMENT_ID,
21
assistantItem,
22
emitTerminalMetadata,
23
emitThreadEvent,
24
+ emitVcsStatus,
25
installFakeEnvironment,
26
isThreadSubscribed,
27
runningRun,
@@ -48,6 +51,7 @@ vi.mock(import("~/rpc/requestLatencyState"), async (original) => ({
51
trackRpcRequestSent: () => {},
52
}));
53
54
+const GIT_STATUS_UPDATES = 20;
55
const HISTORY_TURNS = 20;
56
const STREAM_DELTAS = 30;
57
const TYPED_TEXT = "fix the flaky tests!";
@@ -63,7 +67,9 @@ const [WARM, A, B, LIVE] = THREADS.map((thread) => thread.id) as [
67
ThreadId,
68
];
69
66
-installFakeEnvironment(THREADS);
70
+const SIDE_CHAT = { ...threadWithHistory("thread-side", HISTORY_TURNS), sideChatOf: WARM };
71
+
72
+installFakeEnvironment([...THREADS, SIDE_CHAT]);
73
// Desktop-sized, so the sidebar, composer and right panel lay out as they do in the app.
74
await page.viewport(1400, 900);
75
// A returning user: the first-run gate would otherwise wait on onboarding evidence.
@@ -320,3 +326,33 @@ it("app-switch-settings-section", async () => {
326
await measure(openSettings(router, "/settings/appearance")),
327
]);
328
});
329
+
330
+// ChatView re-renders when the tree goes dirty or clean; the composer and side chat timeline should not.
331
+it("app-git-status-updates-with-side-chat", async () => {
332
+ using _clock = frozenClock();
333
+ useRightPanelStore.getState().openSideChat(scopeThreadRef(ENVIRONMENT_ID, WARM), SIDE_CHAT.id);
334
+ await using _app = (await openThread(WARM)).screen;
335
+ await expect.element(lastAnswer(SIDE_CHAT.id)).toBeVisible();
336
+ const local = (insertions: number) => ({
337
+ isRepo: true,
338
+ hasPrimaryRemote: true,
339
+ isDefaultRef: true,
340
+ refName: "main",
341
+ hasWorkingTreeChanges: insertions % 2 === 1,
342
+ workingTree: {
343
+ files: [{ path: "src/app.ts", insertions, deletions: 0 }],
344
+ insertions,
345
+ deletions: 0,
346
+ },
347
+ });
348
+ await act(() => emitVcsStatus({ _tag: "snapshot", local: local(0), remote: null }));
349
+ const counted = await measure(async () => {
350
+ for (let update = 1; update <= GIT_STATUS_UPDATES; update++) {
351
+ await act(() => emitVcsStatus({ _tag: "localUpdated", local: local(update) }));
352
+ }
353
+ });
354
+ expect(counted.components.ChatView).toBe(GIT_STATUS_UPDATES * 2);
355
+ expect(counted.components.ChatComposer).toBeUndefined();
356
+ expect(counted.components.ConversationTimeline).toBeUndefined();
357
+ await report("app-git-status-updates-with-side-chat", [counted]);
358
+});
apps/web/test/fakeEnvironment.ts
+22
-1
@@ -17,6 +17,7 @@ import {
17
TurnItemId,
18
WS_METHODS,
19
WsRpcGroup,
20
+ type VcsStatusStreamEvent,
21
type OrchestrationProjectShell,
22
type OrchestrationV2ProjectedTurnItem,
23
type OrchestrationV2Run,
@@ -182,6 +183,8 @@ function run(threadId: ThreadId, id: RunId, ordinal: number, userMessageId: stri
183
}
184
185
export interface FakeThread {
186
+ /** Makes this a side chat of that thread. */
187
+ readonly sideChatOf?: ThreadId;
188
readonly id: ThreadId;
189
readonly title: string;
190
readonly runs: ReadonlyArray<OrchestrationV2Run>;
@@ -224,7 +227,12 @@ function shellOf(thread: FakeThread): OrchestrationV2ThreadShell {
227
branch: "main",
228
worktreePath: null,
229
activeProviderThreadId: null,
227
- lineage: { rootThreadId: thread.id, parentThreadId: null, relationshipToParent: null },
230
+ lineage: {
231
+ rootThreadId: thread.sideChatOf ?? thread.id,
232
+ parentThreadId: thread.sideChatOf ?? null,
233
+ relationshipToParent: null,
234
+ ...(thread.sideChatOf ? { sideChat: true } : {}),
235
+ },
236
forkedFrom: null,
237
createdBy: "user",
238
creationSource: "web",
@@ -311,6 +319,7 @@ const threadSubscribers = new Map<string, Queue.Queue<OrchestrationV2ThreadStrea
319
let terminalMetadataSubscriber: Queue.Queue<TerminalMetadataStreamEvent> | null = null;
320
let threads: ReadonlyArray<FakeThread> = [];
321
let sequence = 1;
322
+let vcsStatusSubscriber: Queue.Queue<VcsStatusStreamEvent> | null = null;
323
324
const subscribe = <A>(first: ReadonlyArray<A>, register?: (queue: Queue.Queue<A>) => () => void) =>
325
Stream.unwrap(
@@ -365,6 +374,13 @@ const handlers: Record<string, (input: never) => unknown> = {
374
},
375
);
376
},
377
+ [WS_METHODS.subscribeVcsStatus]: () =>
378
+ subscribe<VcsStatusStreamEvent>([], (queue) => {
379
+ vcsStatusSubscriber = queue;
380
+ return () => {
381
+ if (vcsStatusSubscriber === queue) vcsStatusSubscriber = null;
382
+ };
383
+ }),
384
[WS_METHODS.subscribeServerConfig]: () =>
385
subscribe([{ version: 1 as const, type: "snapshot" as const, config: serverConfig }]),
386
};
@@ -482,3 +498,8 @@ export function runningRun(threadId: ThreadId, id: string, ordinal: number, user
498
}
499
500
export { userItem };
501
+
502
+export async function emitVcsStatus(event: VcsStatusStreamEvent): Promise<void> {
503
+ if (vcsStatusSubscriber === null) throw new Error("No VCS status subscription");
504
+ await Effect.runPromise(Queue.offer(vcsStatusSubscriber, event));
505
+}