The best way to control Claude Code, Codex and more from any computer or phone
perf(web): changing file counts no longer re-render the chat view (#28571)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>
Andrei committed
Nov 9, 2026 at 22:27 UTC
c1463af2055457c0d80978b6e32af2c9c84cf73d
5 files changed
+136
-6
apps/web/src/components/ChatView.tsx
+8
-5
@@ -227,7 +227,7 @@ import { type TerminalContextDraft } from "../lib/terminalContext";
227
import { collectInlineContextIds } from "../lib/composerContextReferences";
228
import { selectThreadTerminalUiState, useTerminalUiStateStore } from "../terminalUiStateStore";
229
import { useKnownTerminalSessions, useThreadRunningTerminalIds } from "../state/terminalSessions";
230
-import { useEnvironmentQuery } from "../state/query";
230
+import { useEnvironmentQueryRefresh } from "../state/query";
231
import { useEnvironmentScope } from "~/state/session";
232
import {
233
primaryServerAvailableEditorsAtom,
@@ -236,7 +236,7 @@ import {
236
} from "../state/server";
237
import { threadEnvironment } from "../state/threads";
238
import { resolveProviderSkillsForCwd } from "@t3tools/client-runtime/providerSkills";
239
-import { vcsEnvironment } from "../state/vcs";
239
+import { chatGitStatusAtom, NO_CHAT_GIT_STATUS_ATOM, vcsEnvironment } from "../state/vcs";
240
import {
241
type EnvironmentPresentation,
242
useEnvironment,
@@ -1597,14 +1597,17 @@ export default function ChatView(props: ChatViewProps) {
1597
})
1598
: null;
1599
const gitStatusCwd = activeThread?.worktreePath ?? gitCwd;
1600
- const gitStatusQuery = useEnvironmentQuery(
1600
+ const gitStatusAtom =
1601
gitStatusCwd === null
1602
? null
1603
: vcsEnvironment.status({
1604
environmentId,
1605
input: { cwd: gitStatusCwd },
1606
- }),
1607
- );
1606
+ });
1607
+ const gitStatusQuery = {
1608
+ data: useAtomValue(gitStatusAtom ? chatGitStatusAtom(gitStatusAtom) : NO_CHAT_GIT_STATUS_ATOM),
1609
+ refresh: useEnvironmentQueryRefresh(gitStatusAtom).refresh,
1610
+ };
1611
useWorkspaceMutationRefresh({
1612
enabled: gitStatusCwd !== null,
1613
mutationId: workspaceMutationId,
apps/web/src/components/pullRequest/useThreadLinkedPullRequest.ts
+1
-1
@@ -25,7 +25,7 @@ export function useThreadLinkedPullRequest(input: {
25
readonly projectId: ProjectId | null;
26
readonly projectRepository: string | null;
27
readonly threadBranch: string | null;
28
- readonly gitStatus: VcsStatusResult | null;
28
+ readonly gitStatus: Pick<VcsStatusResult, "refName" | "pr"> | null;
29
}) {
30
const { serverThreadRef, persisted, projectId, projectRepository, threadBranch, gitStatus } =
31
input;
apps/web/src/state/vcs.test.ts
new
+68
@@ -0,0 +1,68 @@
1
+import type { VcsStatusResult } from "@t3tools/contracts";
2
+import { AsyncResult, Atom, AtomRegistry } from "effect/reactivity";
3
+import { describe, expect, it, vi } from "vite-plus/test";
4
+
5
+import { chatGitStatusAtom } from "./vcs";
6
+
7
+vi.mock("../connection/runtime", () => ({ connectionAtomRuntime: {} }));
8
+vi.mock("@t3tools/client-runtime/state/vcs", () => ({
9
+ createVcsActionManager: () => ({}),
10
+ createVcsEnvironmentAtoms: () => ({}),
11
+ createVcsStatusRevalidationAtomFamily: () => () => null,
12
+}));
13
+
14
+const status = (changes: Partial<VcsStatusResult> = {}) =>
15
+ AsyncResult.success({
16
+ isRepo: true,
17
+ hasPrimaryRemote: true,
18
+ isDefaultRef: true,
19
+ refName: "main",
20
+ hasWorkingTreeChanges: true,
21
+ workingTree: { files: [], insertions: 1, deletions: 0 },
22
+ hasUpstream: true,
23
+ aheadCount: 0,
24
+ behindCount: 0,
25
+ pr: null,
26
+ ...changes,
27
+ } satisfies VcsStatusResult);
28
+
29
+describe("chatGitStatusAtom", () => {
30
+ it("notifies only when a field the chat view reads changes", () => {
31
+ const registry = AtomRegistry.make();
32
+ const source = Atom.make<AsyncResult.AsyncResult<VcsStatusResult, never>>(status());
33
+ const selected = chatGitStatusAtom(source as never);
34
+ const notified: unknown[] = [];
35
+ const unsubscribe = registry.subscribe(selected, (value) => notified.push(value));
36
+ registry.get(selected);
37
+ notified.length = 0;
38
+
39
+ registry.set(
40
+ source,
41
+ status({ workingTree: { files: [], insertions: 2, deletions: 0 }, aheadCount: 1 }),
42
+ );
43
+ expect(notified).toEqual([]);
44
+
45
+ registry.set(source, status({ refName: "feature" }));
46
+ expect(notified).toHaveLength(1);
47
+
48
+ registry.set(source, status({ refName: "feature", hasWorkingTreeChanges: false }));
49
+ expect(notified).toHaveLength(2);
50
+
51
+ const pr = () => ({
52
+ number: 42,
53
+ title: "Feature PR",
54
+ url: "https://github.com/pingdotgg/t3code/pull/42",
55
+ baseRef: "main",
56
+ headRef: "feature",
57
+ state: "open" as const,
58
+ });
59
+ const linked = { refName: "feature", hasWorkingTreeChanges: false };
60
+ registry.set(source, status({ ...linked, pr: pr() }));
61
+ expect(notified).toHaveLength(3);
62
+
63
+ // A new object with the same data, as each remote status refresh sends.
64
+ registry.set(source, status({ ...linked, pr: pr() }));
65
+ expect(notified).toHaveLength(3);
66
+ unsubscribe();
67
+ });
68
+});
apps/web/src/state/vcs.ts
+13
@@ -3,6 +3,8 @@ import {
3
createVcsEnvironmentAtoms,
4
createVcsStatusRevalidationAtomFamily,
5
} from "@t3tools/client-runtime/state/vcs";
6
+import * as Equal from "effect/Equal";
7
+import { AsyncResult, Atom } from "effect/reactivity";
8
9
import { connectionAtomRuntime } from "../connection/runtime";
10
import { subscribeDocumentReturn } from "../lib/documentActivity";
@@ -10,6 +12,17 @@ import { subscribeDocumentReturn } from "../lib/documentActivity";
12
export const vcsEnvironment = createVcsEnvironmentAtoms(connectionAtomRuntime);
13
export const vcsActionManager = createVcsActionManager(connectionAtomRuntime);
14
15
+/** Only what a chat view reads, so changing file counts don't re-render it on every edit. */
16
+export const chatGitStatusAtom = Atom.family((status: ReturnType<typeof vcsEnvironment.status>) =>
17
+ Atom.map(status, (result) => {
18
+ const data = AsyncResult.getOrElse(result, () => null);
19
+ if (data === null) return null;
20
+ const { isRepo, refName, hasWorkingTreeChanges, pr } = data;
21
+ return { isRepo, refName, hasWorkingTreeChanges, pr };
22
+ }).pipe(Atom.withEquality(Equal.equals)),
23
+);
24
+export const NO_CHAT_GIT_STATUS_ATOM: ReturnType<typeof chatGitStatusAtom> = Atom.make(null);
25
+
26
/**
27
* Refreshes a checkout's status when the user comes back to the window, where
28
* edits made in another app or terminal may be waiting.
apps/web/test/appScenarios.renders.tsx
+46
@@ -7,6 +7,7 @@ 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";
10
+import { AsyncResult } from "effect/reactivity";
11
import { expect, it, vi } from "vite-plus/test";
12
import { commands, page, userEvent } from "vite-plus/test/browser";
13
@@ -16,6 +17,8 @@ import { AppRoot } from "~/AppRoot";
17
import { __setClientSettingsForTests } from "~/hooks/useSettings";
18
import { useRightPanelStore } from "~/rightPanelStore";
19
import { getRouter, type AppRouter } from "~/router";
20
+import { appAtomRegistry } from "~/rpc/atomRegistry";
21
+import { vcsEnvironment } from "~/state/vcs";
22
import {
23
ENVIRONMENT_ID,
24
assistantItem,
@@ -327,6 +330,49 @@ it("app-switch-settings-section", async () => {
330
]);
331
});
332
333
+// ChatView reads only a few status fields, so changing file counts should not reach it.
334
+// Keep git scenarios last: the status they leave cached adds renders to later scenarios.
335
+it("app-git-file-counts-with-side-chat", async () => {
336
+ using _clock = frozenClock();
337
+ useRightPanelStore.getState().openSideChat(scopeThreadRef(ENVIRONMENT_ID, WARM), SIDE_CHAT.id);
338
+ await using _app = (await openThread(WARM)).screen;
339
+ await expect.element(lastAnswer(SIDE_CHAT.id)).toBeVisible();
340
+ const gitStatus = vcsEnvironment.status({
341
+ environmentId: ENVIRONMENT_ID,
342
+ input: { cwd: "/workspace/render" },
343
+ });
344
+ const local = (insertions: number, refName = "main") => ({
345
+ isRepo: true,
346
+ hasPrimaryRemote: true,
347
+ isDefaultRef: true,
348
+ refName,
349
+ hasWorkingTreeChanges: true,
350
+ workingTree: {
351
+ files: [{ path: "src/app.ts", insertions, deletions: 0 }],
352
+ insertions,
353
+ deletions: 0,
354
+ },
355
+ });
356
+ await act(() => emitVcsStatus({ _tag: "snapshot", local: local(0), remote: null }));
357
+ const counted = await measure(async () => {
358
+ for (let update = 1; update <= GIT_STATUS_UPDATES; update++) {
359
+ await act(() => emitVcsStatus({ _tag: "localUpdated", local: local(update) }));
360
+ }
361
+ // Zero renders only counts if the last update arrived inside this window.
362
+ await vi.waitFor(() => {
363
+ const status = AsyncResult.getOrElse(appAtomRegistry.get(gitStatus), () => null);
364
+ expect(status?.workingTree.insertions).toBe(GIT_STATUS_UPDATES);
365
+ });
366
+ });
367
+ expect(counted.components.ChatView).toBeUndefined();
368
+ // A field the chat view does read still reaches both chats.
369
+ const branchSwitch = await measure(() =>
370
+ act(() => emitVcsStatus({ _tag: "localUpdated", local: local(0, "feature") })),
371
+ );
372
+ expect(branchSwitch.components.ChatView).toBe(2);
373
+ await report("app-git-file-counts-with-side-chat", [counted]);
374
+});
375
+
376
// ChatView re-renders when the tree goes dirty or clean; the composer and side chat timeline should not.
377
it("app-git-status-updates-with-side-chat", async () => {
378
using _clock = frozenClock();