@devries-cameron20 / t3code-1 / commits / 39bca5365c
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

perf(web): typing in a thread no longer re-renders sidebar drafts (#28267)

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

Yuruzuu committed Nov 1, 2026 at 10:49 UTC 39bca5365c296dee18450fe8b43ecb45e94fe9fe
2 files changed +78 -1
apps/web/src/components/sidebar/SidebarDraftBlock.browser.test.tsx new
+68
@@ -0,0 +1,68 @@
1 +import { scopeProjectRef, scopeThreadRef } from "@t3tools/client-runtime/environment";
2 +import { EnvironmentId, ProjectId, ThreadId } from "@t3tools/contracts";
3 +import { Profiler } from "react";
4 +import { expect, it, vi } from "vite-plus/test";
5 +
6 +import { act, render } from "../../../test/render";
7 +import { DraftId, useComposerDraftStore } from "../../composerDraftStore";
8 +import { SidebarDraftBlock } from "./SidebarDraftBlock";
9 +
10 +it("keeps draft previews current through edits, promotion and removal", async () => {
11 + const initial = useComposerDraftStore.getState();
12 + using _store = {
13 + [Symbol.dispose]: () => useComposerDraftStore.setState(initial, true),
14 + };
15 + useComposerDraftStore.setState({
16 + draftsByThreadKey: {},
17 + draftThreadsByThreadKey: {},
18 + logicalProjectDraftThreadKeyByLogicalProjectKey: {},
19 + });
20 + const environmentId = EnvironmentId.make("draft-preview-environment");
21 + const projectRef = scopeProjectRef(environmentId, ProjectId.make("draft-preview-project"));
22 + const draftId = DraftId.make("draft-preview");
23 + const threadId = ThreadId.make("draft-preview-thread");
24 + const onRender = vi.fn();
25 + await using screen = await render(
26 + <Profiler id="draft-block" onRender={onRender}>
27 + <ul>
28 + <SidebarDraftBlock
29 + projectByKey={new Map()}
30 + projectDisplayNameByKey={new Map()}
31 + scopedProjectKeys={null}
32 + routeDraftId={null}
33 + onNavigateToDraft={vi.fn()}
34 + onDraftContextMenu={vi.fn()}
35 + />
36 + </ul>
37 + </Profiler>,
38 + );
39 + const row = screen.getByTestId("sidebar-draft-row");
40 + await expect.element(row).not.toBeInTheDocument();
41 +
42 + await act(() => {
43 + initial.setProjectDraftThreadId(projectRef, draftId, { threadId });
44 + initial.setPrompt(draftId, "First draft preview");
45 + });
46 + await expect.element(row).toHaveAccessibleName("First draft preview, Unsent draft");
47 +
48 + const rendersBeforeOtherComposer = onRender.mock.calls.length;
49 + await act(() =>
50 + initial.setPrompt(scopeThreadRef(environmentId, ThreadId.make("other")), "Other composer"),
51 + );
52 + expect(onRender).toHaveBeenCalledTimes(rendersBeforeOtherComposer);
53 + await act(() => initial.setPrompt(draftId, "Updated draft preview"));
54 + await expect.element(row).toHaveAccessibleName("Updated draft preview, Unsent draft");
55 +
56 + await act(() => initial.markDraftThreadPromoting(draftId));
57 + await expect.element(row).not.toBeInTheDocument();
58 + await act(() => initial.clearDraftThread(draftId));
59 +
60 + const nextDraftId = DraftId.make("next-draft-preview");
61 + await act(() => {
62 + initial.setProjectDraftThreadId(projectRef, nextDraftId, { threadId: ThreadId.make("next") });
63 + initial.setPrompt(nextDraftId, "Next draft preview");
64 + });
65 + await expect.element(row).toHaveAccessibleName("Next draft preview, Unsent draft");
66 + await act(() => initial.clearDraftThread(nextDraftId));
67 + await expect.element(row).not.toBeInTheDocument();
68 +});
apps/web/src/components/sidebar/SidebarDraftBlock.tsx
+10 -1
@@ -8,6 +8,7 @@ import {
8 type MouseEvent as ReactMouseEvent,
9 } from "react";
10 import type { EnvironmentProject } from "@t3tools/client-runtime/state/shell";
11 +import { useShallow } from "zustand/react/shallow";
12 import { cn } from "~/lib/utils";
13 import { resolveSidebarRowAccessibility } from "../Sidebar.logic";
14 import { ProjectFavicon, type ProjectFaviconProject } from "../ProjectFavicon";
@@ -147,7 +148,15 @@ export const SidebarDraftBlock = memo(function SidebarDraftBlock(props: {
148 onDraftContextMenu: (draftId: DraftId, position: { x: number; y: number }) => void;
149 }) {
150 const draftThreadsByThreadKey = useComposerDraftStore((store) => store.draftThreadsByThreadKey);
150 - const draftsByThreadKey = useComposerDraftStore((store) => store.draftsByThreadKey);
151 + const draftsByThreadKey = useComposerDraftStore(
152 + useShallow((store) =>
153 + Object.fromEntries(
154 + Object.keys(store.draftThreadsByThreadKey).map(
155 + (key) => [key, store.draftsByThreadKey[key]] as const,
156 + ),
157 + ),
158 + ),
159 + );
160 const [frozenActive, setFrozenActive] = useState<{
161 routeDraftId: string | null;
162 row: SidebarDraftRowData | null;