@devries-cameron20 / t3code Mirror · read-only / commits / 5a0d1594e8
Fork 0

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, 20:45 UTC

perf(web): a streaming thread re-renders only its own sidebar row (#22730)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 21, 2026 at 11:19 UTC 5a0d1594e8656a382eff73f65a963506f1f35c1a
6 files changed +70 -6
apps/web/src/components/Sidebar.tsx
+2 -2
@@ -116,7 +116,7 @@ import {
116 useAllEnvironmentProjectSnapshotsReady,
117 useProjects,
118 useServerConfigs,
119 - useThreadShells,
119 + useQuietThreadShells,
120 } from "../state/entities";
121 import { environmentPresentations } from "../state/presentation";
122 import { primaryServerKeybindingsAtom } from "../state/server";
@@ -356,7 +356,7 @@ function useSidebarThreads(input: {
356 }) {
357 const { projectScopeKey, scopedProjectKeys, serverConfigs, optimisticDrop, routeThreadRef } =
358 input;
359 - const threads = useThreadShells();
359 + const threads = useQuietThreadShells();
360 const routeRowThreadKey =
361 routeThreadRef === null
362 ? null
apps/web/src/components/sidebar/SidebarThreadRow.tsx
+9 -2
@@ -96,6 +96,7 @@ import {
96 ThreadSearchPullRequestNumber,
97 } from "../ThreadStatusIndicators";
98 import { resolveSnoozePresets, type SnoozePreset } from "../Sidebar.snooze";
99 +import { useThreadShell } from "../../state/entities";
100 import { ProjectFavicon, type ProjectFaviconProject } from "../ProjectFavicon";
101 import { ThreadSearchMatchExcerpt } from "../ThreadSearchMatch";
102 import { makeWorkspaceFileDropHandlers } from "../chat/workspaceFileDrop";
@@ -463,8 +464,13 @@ export function SortableThreadRow(
464 transition: contextDrag && isDragging ? "transform 150ms ease-out" : transition,
465 isDragging: isDragging && !contextDrag,
466 };
467 + // The sidebar arranges rows from quiet shells, which hold still while a
468 + // thread streams; reading the live shell here re-renders only this row.
469 + const thread =
470 + useThreadShell(scopeThreadRef(rowProps.thread.environmentId, rowProps.thread.id)) ??
471 + rowProps.thread;
472 // Keyed by variant so a card/slim switch remounts the row.
467 - return <SidebarThreadRow key={rowProps.variant} {...rowProps} sortable={bag} />;
473 + return <SidebarThreadRow key={rowProps.variant} {...rowProps} thread={thread} sortable={bag} />;
474 }
475 export type SidebarSweepAction = "settle" | "unsettle" | "unsnooze";
476 const dropVerbBadge: Record<SidebarDropVerb, ReactNode> = {
@@ -1508,7 +1514,8 @@ export const SidebarSearchResultRow = memo(function SidebarSearchResultRow(props
1514 onSelect: () => void;
1515 onFileDropThreads: (threadRef: ScopedThreadRef, files: File[]) => void;
1516 }) {
1511 - const { thread } = props;
1517 + const thread =
1518 + useThreadShell(scopeThreadRef(props.thread.environmentId, props.thread.id)) ?? props.thread;
1519 const accessibility = resolveSidebarRowAccessibility({
1520 title: thread.title,
1521 statusLabel: null,
apps/web/src/hooks/useSidebarProjectGroups.ts
+4 -2
@@ -2,13 +2,15 @@ import { orderItemsByPreferredIds, sortSidebarV2ProjectGroups } from "../compone
2 import { getProjectOrderKey, selectProjectGroupingSettings } from "../logicalProject";
3 import { buildSidebarProjectSnapshots } from "../sidebarProjectGrouping";
4 import { useEnvironmentIdentities, usePrimaryEnvironmentId } from "../state/environments";
5 -import { useProjects, useThreadShells } from "../state/entities";
5 +import { useProjects, useQuietThreadShells } from "../state/entities";
6 import { legacyProjectCwdPreferenceKey, useUiStateStore } from "../uiStateStore";
7 import { useClientSettings } from "./useSettings";
8
9 export function useSidebarProjectGroups() {
10 const projects = useProjects();
11 - const threads = useThreadShells();
11 + // Activity order lags a running thread's streaming ticks until its next
12 + // real change; reading every tick re-rendered the whole sidebar with it.
13 + const threads = useQuietThreadShells();
14 const projectOrder = useUiStateStore((store) => store.projectOrder);
15 const sortOrder = useClientSettings((s) => s.sidebarProjectSortOrder);
16 const groupingSettings = useClientSettings(selectProjectGroupingSettings);
apps/web/src/state/entities.ts
+5
@@ -139,6 +139,11 @@ export function useQuietThreadShell(ref: ScopedThreadRef | null): EnvironmentThr
139 );
140 }
141
142 +/** Every thread shell, held through streaming ticks; see quietThreadShellAtom. */
143 +export function useQuietThreadShells(): ReadonlyArray<EnvironmentThreadShell> {
144 + return useAtomValue(environmentThreadShells.quietThreadShellsAtom);
145 +}
146 +
147 export function useChildThreadInputs(ref: ScopedThreadRef | null) {
148 return useAtomValue(
149 ref === null ? EMPTY_THREAD_SHELLS_ATOM : environmentThreadShells.childThreadInputsAtom(ref),
packages/client-runtime/src/state/threadShell.test.ts
+35
@@ -344,4 +344,39 @@ describe("v2 thread shell lists", () => {
344 harness.registry.dispose();
345 }
346 });
347 +
348 + it("keeps the quiet shell list through streaming ticks", () => {
349 + const harness = makeHarness();
350 + const runId = RunId.make("streaming-list-run");
351 + const running: OrchestrationV2ThreadShell = {
352 + ...v2ThreadShell,
353 + latestRunId: runId,
354 + activeRunId: runId,
355 + status: "running",
356 + itemCount: 1,
357 + visibleItemCount: 1,
358 + };
359 + const setThread = (thread: OrchestrationV2ThreadShell, sequence: number) =>
360 + harness.registry.set(harness.snapshotAtom(environmentId), {
361 + ...v2ShellSnapshot,
362 + snapshotSequence: sequence,
363 + threads: [thread],
364 + });
365 + setThread(running, 1);
366 + const listAtom = harness.threads.quietThreadShellsAtom;
367 + const dispose = harness.registry.mount(listAtom);
368 + try {
369 + const first = harness.registry.get(listAtom);
370 + expect(first).toHaveLength(1);
371 + setThread({ ...running, updatedAt: DateTime.add(v2Now, { seconds: 1 }), itemCount: 4 }, 2);
372 + expect(harness.registry.get(listAtom)).toBe(first);
373 +
374 + setThread({ ...running, title: "Renamed" }, 3);
375 + expect(harness.registry.get(listAtom)).not.toBe(first);
376 + expect(harness.registry.get(listAtom)[0]?.title).toBe("Renamed");
377 + } finally {
378 + dispose();
379 + harness.registry.dispose();
380 + }
381 + });
382 });
packages/client-runtime/src/state/threadShell.ts
+15
@@ -388,6 +388,20 @@ export function createEnvironmentThreadShellAtoms(input: {
388 return previousThreadShells;
389 }).pipe(Atom.withLabel("environment-thread-shell-list"));
390
391 + // Lists that arrange threads read this, so a running thread's streaming
392 + // ticks reach only what reads its live shell.
393 + let previousQuietThreadShells: ReadonlyArray<EnvironmentThreadShell> = [];
394 + const quietThreadShellsAtom = Atom.make((get) => {
395 + const next: EnvironmentThreadShell[] = [];
396 + for (const ref of get(threadRefsAtom)) {
397 + const shell = get(quietThreadShellAtomFamily(threadKey(ref)));
398 + if (shell !== null) next.push(shell);
399 + }
400 + if (arrayElementsEqual(previousQuietThreadShells, next)) return previousQuietThreadShells;
401 + previousQuietThreadShells = next;
402 + return next;
403 + }).pipe(Atom.withLabel("environment-quiet-thread-shell-list"));
404 +
405 let previousNavigationShells: ReadonlyArray<EnvironmentThreadShell> = [];
406 const navigationThreadShellsAtom = Atom.make((get) => {
407 const next: EnvironmentThreadShell[] = [];
@@ -411,6 +425,7 @@ export function createEnvironmentThreadShellAtoms(input: {
425 environmentThreadRefsByProjectAtom,
426 threadRefsAtom,
427 threadShellsAtom,
428 + quietThreadShellsAtom,
429 navigationThreadShellsAtom,
430 threadShellsForProjectRefsAtom: (refs: ReadonlyArray<ScopedProjectRef>) =>
431 threadShellsForProjectRefsAtomFamily(projectRefCollectionKey(refs)),