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 21, 13:30 UTC
perf(web): opening a thread from a draft only renders its sidebar row (#33435)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Dominik Žabčík committed
Nov 14, 2026 at 18:09 UTC
f968db10d749b8ede49d5c8f35bd81cf4fb13681
3 files changed
+40
-17
apps/web/src/components/Sidebar.tsx
+5
-3
@@ -1524,12 +1524,13 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
1524
}
1525
};
1526
1527
- const startThreadRename = (threadRef: ScopedThreadRef, title: string) => {
1527
+ // The ref write stops the compiler memoizing this, and every row receives it.
1528
+ const startThreadRename = useStableCallback((threadRef: ScopedThreadRef, title: string) => {
1529
if (!readEnvironmentScope(threadRef.environmentId, AuthOrchestrationOperateScope)) return;
1530
setRenamingThreadRef(threadRef);
1531
setRenamingTitle(title);
1532
renamingOriginalTitleRef.current = title;
1532
- };
1533
+ });
1534
const cancelThreadRename = () => setRenamingThreadRef(null);
1535
const commitThreadRename = (threadRef: ScopedThreadRef, title: string) => {
1536
const originalTitle = renamingOriginalTitleRef.current;
@@ -1559,6 +1560,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
1560
})();
1561
};
1562
1563
+ const readOpensPullRequestsInRightPanel = useStableCallback(() => routeThreadRef !== null);
1564
const handleThreadClick = (event: ReactMouseEvent, threadRef: ScopedThreadRef) => {
1565
if (isSidebarNestedLinkClick(event.target)) return;
1566
const isMac = isMacPlatform(navigator.platform);
@@ -3420,7 +3422,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
3422
routeRowThreadKey === threadKey ? revealActiveRow : undefined
3423
}
3424
isRouteThread={routeThreadKey === threadKey}
3423
- openPullRequestsInRightPanel={routeThreadRef !== null}
3425
+ readOpensPullRequestsInRightPanel={readOpensPullRequestsInRightPanel}
3426
jumpLabel={
3427
showJumpHints ? (jumpLabelByKey.get(threadKey) ?? null) : null
3428
}
apps/web/src/components/sidebar/SidebarThreadRow.tsx
+4
-3
@@ -568,7 +568,8 @@ type SidebarThreadRowProps = {
568
// Unlike isActive, never true for the ancestor standing in for an open
569
// subagent: drafts and PR clicks care about which composer is on screen.
570
isRouteThread: boolean;
571
- openPullRequestsInRightPanel: boolean;
571
+ // Read at click time; a prop would re-render every row on entering or leaving a thread route.
572
+ readOpensPullRequestsInRightPanel: () => boolean;
573
jumpLabel: string | null;
574
currentEnvironmentId: string | null;
575
environmentLabel: string | null;
@@ -660,7 +661,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
661
onUnsettle,
662
onUnsnooze,
663
onUnpin,
663
- openPullRequestsInRightPanel,
664
+ readOpensPullRequestsInRightPanel,
665
renamingTitle,
666
thread,
667
variant,
@@ -965,7 +966,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
966
const handlePrClick = (event: ReactMouseEvent<HTMLElement>, targetUrl?: string) => {
967
const url = targetUrl ?? pr?.url ?? currentLinkedPr?.url;
968
if (!url) return;
968
- const showInRightPanel = targetUrl !== undefined || openPullRequestsInRightPanel;
969
+ const showInRightPanel = targetUrl !== undefined || readOpensPullRequestsInRightPanel();
970
const openedInRightPanel = openPrLink(event, url, showInRightPanel ? threadRef : undefined);
971
if (openedInRightPanel && showInRightPanel && !props.isRouteThread) {
972
onThreadActivate(threadRef);
apps/web/test/appScenarios.renders.tsx
+31
-11
@@ -3,7 +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";
6
+import { scopeProjectRef, 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";
@@ -14,6 +14,7 @@ import { commands, page, userEvent } from "vite-plus/test/browser";
14
import "~/index.css";
15
16
import { AppRoot } from "~/AppRoot";
17
+import { DraftId, useComposerDraftStore } from "~/composerDraftStore";
18
import { __setClientSettingsForTests } from "~/hooks/useSettings";
19
import { useRightPanelStore } from "~/rightPanelStore";
20
import { getRouter, type AppRouter } from "~/router";
@@ -21,6 +22,7 @@ import { appAtomRegistry } from "~/rpc/atomRegistry";
22
import { vcsEnvironment } from "~/state/vcs";
23
import {
24
ENVIRONMENT_ID,
25
+ PROJECT_ID,
26
assistantItem,
27
emitTerminalMetadata,
28
emitThreadEvent,
@@ -120,6 +122,16 @@ async function openThread(threadId: ThreadId) {
122
return app;
123
}
124
125
+const goToThread = (router: AppRouter, threadId: ThreadId) => async () => {
126
+ await act(() =>
127
+ router.navigate({
128
+ to: "/$environmentId/$threadId",
129
+ params: { environmentId: ENVIRONMENT_ID, threadId },
130
+ }),
131
+ );
132
+ await expect.element(lastAnswer(threadId)).toBeVisible();
133
+};
134
+
135
async function measure(action: () => Promise<void>): Promise<RenderReport> {
136
await quiet();
137
startCounting();
@@ -269,21 +281,29 @@ it("app-switch-thread", async () => {
281
using _clock = frozenClock();
282
const { screen, router } = await openThread(A);
283
await using _app = screen;
272
- const go = (threadId: ThreadId) => async () => {
273
- await act(() =>
274
- router.navigate({
275
- to: "/$environmentId/$threadId",
276
- params: { environmentId: ENVIRONMENT_ID, threadId },
277
- }),
278
- );
279
- await expect.element(lastAnswer(threadId)).toBeVisible();
280
- };
281
- const windows = [await measure(go(B)), await measure(go(A))];
284
+ const windows = [await measure(goToThread(router, B)), await measure(goToThread(router, A))];
285
// Only the rows losing and gaining the active highlight change.
286
for (const window of windows) expect(window.components.SidebarThreadRow).toBe(2);
287
await report("app-switch-thread", windows);
288
});
289
290
+// A row reads whether a thread is open only when its PR badge is clicked, so opening a thread
291
+// from a draft changes only the row that gains the highlight.
292
+it("app-open-thread-from-draft", async () => {
293
+ using _clock = frozenClock();
294
+ const drafts = useComposerDraftStore.getState();
295
+ const draftId = DraftId.make("draft-render");
296
+ drafts.setProjectDraftThreadId(scopeProjectRef(ENVIRONMENT_ID, PROJECT_ID), draftId);
297
+ using _draft = { [Symbol.dispose]: () => drafts.clearDraftThread(draftId) };
298
+ const { screen, router } = await mountApp(`/draft/${draftId}`);
299
+ await using _app = screen;
300
+ // The sidebar lists the project once the shell snapshot has arrived.
301
+ await expect.element(page.getByText("render", { exact: true }).first()).toBeVisible();
302
+ const counted = await measure(goToThread(router, A));
303
+ expect(counted.components.SidebarThreadRow).toBe(1);
304
+ await report("app-open-thread-from-draft", [counted], { commits: false });
305
+});
306
+
307
// Through the diff.toggle shortcut, the same handler as the header's diff button.
308
const toggleDiff = (to: "open" | "close") => async () => {
309
await userEvent.keyboard("{Control>}d{/Control}");