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 23, 05:30 UTC
refactor(web): the legacy sidebar keeps its caching without "use memo" (#20793)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 17, 2026 at 00:30 UTC
2c722ba396b0b7c8ef66a5eae4e30a6bfd17234a
1 file changed
+35
-50
apps/web/src/components/LegacySidebar.tsx
+35
-50
@@ -291,13 +291,6 @@ function projectGroupingModeDescription(mode: SidebarProjectGroupingMode): strin
291
}
292
}
293
294
-// Every project row keys on this map, so it gets its own cache: inline, it
295
-// shared one with the modifier-key state and rebuilt on every key press.
296
-function useThreadJumpLabelMap(input: Parameters<typeof buildThreadJumpLabelMap>[0]) {
297
- "use memo";
298
- return buildThreadJumpLabelMap(input);
299
-}
300
-
294
function buildThreadJumpLabelMap(input: {
295
keybindings: ResolvedKeybindingsConfig;
296
platform: string;
@@ -383,13 +376,6 @@ function checkTaskPermission(environmentId: EnvironmentId): boolean {
376
return false;
377
}
378
386
-// The row's handlers key on this ref; built inline, the hooks after it kept the
387
-// compiler from caching it, so every render rebuilt all of them.
388
-function useScopedThreadRef(environmentId: EnvironmentId, threadId: ThreadId) {
389
- "use memo";
390
- return scopeThreadRef(environmentId, threadId);
391
-}
392
-
379
const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowProps) {
380
const {
381
orderedProjectThreadKeys,
@@ -420,16 +406,8 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
406
} = props;
407
const canOperateThread = useEnvironmentScope(thread.environmentId, AuthOrchestrationOperateScope);
408
const canOperatePreview = useEnvironmentScope(thread.environmentId, AuthPreviewOperateScope);
423
- const threadRef = useScopedThreadRef(thread.environmentId, thread.id);
424
- const threadKey = scopedThreadKey(threadRef);
409
+ const threadKey = scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id));
410
const [isFileDragOver, setIsFileDragOver] = useState(false);
426
- const fileDropHandlers = makeWorkspaceFileDropHandlers({
427
- setDragActive: setIsFileDragOver,
428
- addFiles: (files) => {
429
- onFileDropThreads(threadRef, files);
430
- },
431
- addFolders: () => {},
432
- });
411
useEffect(() => {
412
if (!isFileDragOver) return;
413
const clearFileDrag = () => setIsFileDragOver(false);
@@ -462,6 +440,32 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
440
const threadEnvironmentLabel = isRemoteThread
441
? (remoteEnvLabel ?? (isDesktopLocalThread ? "Local" : "Remote"))
442
: null;
443
+ const isThreadRunning = !threadRuntimeCanArchive(thread.runtime);
444
+ const threadStatus = resolveThreadStatusPill({
445
+ thread: {
446
+ ...thread,
447
+ lastVisitedAt,
448
+ },
449
+ });
450
+ const linkedPullRequestStatus = useLinkedThreadPullRequest(
451
+ thread.environmentId,
452
+ thread.linkedPullRequest,
453
+ leaseLiveStatus,
454
+ thread.pullRequests,
455
+ thread.branchPullRequest,
456
+ );
457
+ const pr = linkedPullRequestStatus?.pr ?? null;
458
+ const supportsMultiplePullRequests = useSupportsMultiplePullRequests(thread.environmentId);
459
+ // Every hook runs above this line: the handlers below key on this ref, and the
460
+ // compiler can only cache it once no hook call follows its plain uses.
461
+ const threadRef = scopeThreadRef(thread.environmentId, thread.id);
462
+ const fileDropHandlers = makeWorkspaceFileDropHandlers({
463
+ setDragActive: setIsFileDragOver,
464
+ addFiles: (files) => {
465
+ onFileDropThreads(threadRef, files);
466
+ },
467
+ addFolders: () => {},
468
+ });
469
const isHighlighted = isActive || isSelected;
470
const handleOpenDiscoveredPort = (event: React.MouseEvent<HTMLButtonElement>) => {
471
const port = discoveredPorts[0];
@@ -484,22 +488,6 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
488
);
489
})();
490
};
487
- const isThreadRunning = !threadRuntimeCanArchive(thread.runtime);
488
- const threadStatus = resolveThreadStatusPill({
489
- thread: {
490
- ...thread,
491
- lastVisitedAt,
492
- },
493
- });
494
- const linkedPullRequestStatus = useLinkedThreadPullRequest(
495
- thread.environmentId,
496
- thread.linkedPullRequest,
497
- leaseLiveStatus,
498
- thread.pullRequests,
499
- thread.branchPullRequest,
500
- );
501
- const pr = linkedPullRequestStatus?.pr ?? null;
502
- const supportsMultiplePullRequests = useSupportsMultiplePullRequests(thread.environmentId);
491
const currentLinkedPr = supportsMultiplePullRequests
492
? resolveThreadCurrentPullRequestLink(thread.pullRequests)
493
: null;
@@ -1124,7 +1112,6 @@ function resolveProjectThreadStatus(
1112
// SidebarProjectItem frozen: inline, its later calls made the compiler fuse the
1113
// ordered keys with the route-dependent panel, handing every row a new array.
1114
function useProjectThreads(project: SidebarProjectSnapshot) {
1127
- "use memo";
1115
const threadSortOrder = useClientSettings<SidebarThreadSortOrder>(
1116
(settings) => settings.sidebarThreadSortOrder,
1117
);
@@ -1203,7 +1190,6 @@ function useProjectThreadPanel(input: {
1190
projectExpanded: boolean;
1191
isThreadListExpanded: boolean;
1192
}) {
1206
- "use memo";
1193
const {
1194
visibleProjectThreads,
1195
lastVisitedAtByThreadKey,
@@ -3046,7 +3032,6 @@ function openAddProjectCommandPalette() {
3032
// LegacySidebar frozen and cached on their real inputs; inline, its later hook
3033
// calls made the compiler recompute them, and the props of every row with them.
3034
function useLegacySidebarProjects() {
3049
- "use memo";
3035
const projects = useProjects();
3036
const projectOrder = useUiStateStore((store) => store.projectOrder);
3037
const projectGroupingSettings = useClientSettings(selectProjectGroupingSettings);
@@ -3110,7 +3095,6 @@ function useSortedLegacySidebarProjects(input: {
3095
projectPhysicalKeyByScopedRef: ReadonlyMap<string, string>;
3096
sidebarProjectSortOrder: SidebarProjectSortOrder;
3097
}) {
3113
- "use memo";
3098
const {
3099
sidebarProjects,
3100
physicalToLogicalKey,
@@ -3160,7 +3144,6 @@ function useLegacySidebarThreads(input: {
3144
sidebarThreadPreviewCount: number;
3145
expandedThreadListsByProject: ReadonlySet<string>;
3146
}) {
3163
- "use memo";
3147
const {
3148
sortedProjects,
3149
physicalToLogicalKey,
@@ -3406,17 +3389,19 @@ export default function LegacySidebar() {
3389
};
3390
3391
const isManualProjectSorting = sidebarProjectSortOrder === "manual";
3409
- const sidebarShortcutContext = {
3410
- terminalFocus: terminalFocused,
3411
- terminalOpen: routeTerminalOpen,
3412
- modelPickerOpen: isModelPickerOpen(),
3413
- };
3414
- const threadJumpLabelByKey = useThreadJumpLabelMap({
3392
+ // Built before the modifier-dependent shortcut context so the compiler gives it
3393
+ // its own cache; every project row keys on this map.
3394
+ const threadJumpLabelByKey = buildThreadJumpLabelMap({
3395
keybindings,
3396
platform,
3397
terminalOpen: routeTerminalOpen,
3398
threadJumpCommandByKey,
3399
});
3400
+ const sidebarShortcutContext = {
3401
+ terminalFocus: terminalFocused,
3402
+ terminalOpen: routeTerminalOpen,
3403
+ modelPickerOpen: isModelPickerOpen(),
3404
+ };
3405
const shouldShowThreadJumpHintsNow = shouldShowThreadJumpHintsForModifiers(
3406
shortcutModifiers,
3407
keybindings,