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 command palette caches its derived lookups without "use memo" (#21116)
Julius Marminge committed
Oct 18, 2026 at 00:06 UTC
2e16cf2822b73494fa1c4ffae55014a8e028e04c
2 files changed
+34
-58
apps/web/src/components/CommandPalette.tsx
+31
-57
@@ -371,16 +371,12 @@ function notifyThemeSaveFailure(): void {
371
);
372
}
373
374
-// These helpers keep "use memo" until the palette's item building moves out of this
375
-// component: inlined, each result reaches the returned <CommandPaletteContent> through
376
-// the action and thread item arrays built after the browse hooks, and the compiler
377
-// leaves all of them uncached.
378
-function useThemeCards(
379
- customThemes: ReturnType<typeof useCustomThemes>,
380
- environmentThemes: ReturnType<typeof useEnvironmentThemeDefinitions>,
381
-) {
382
- // oxlint-disable-next-line t3code/no-manual-memo -- Kept until the palette's item building moves out of this component (see above).
383
- "use memo";
374
+// Each helper reads its own source hook so the compiler caches the derived value on that
375
+// source. Taking the source as an argument instead leaves the helper hook-free, and the
376
+// compiler then treats it as a plain function and caches nothing.
377
+function useThemeCards() {
378
+ const customThemes = useCustomThemes();
379
+ const environmentThemes = useEnvironmentThemeDefinitions();
380
const seen = new Set<string>();
381
return [
382
...STANDARD_THEME_CARDS.map((card) => ({ ...card, id: null })),
@@ -394,21 +390,23 @@ function useThemeCards(
390
];
391
}
392
397
-function useThreadContentMatchByKey(matches: ReturnType<typeof useThreadSearch>["matches"]) {
398
- // oxlint-disable-next-line t3code/no-manual-memo -- Kept until the palette's item building moves out of this component (see above).
399
- "use memo";
400
- return new Map(
401
- matches.flatMap((match) =>
393
+function useThreadSearchWithContentMatches(
394
+ environmentIds: ReadonlyArray<EnvironmentId>,
395
+ query: string,
396
+) {
397
+ const threadSearch = useThreadSearch(environmentIds, query);
398
+ const contentMatchByKey = new Map(
399
+ threadSearch.matches.flatMap((match) =>
400
match.source === "user" || match.source === "assistant"
401
? [[threadSearchMatchKey(match), match] as const]
402
: [],
403
),
404
);
405
+ return { threadSearch, contentMatchByKey };
406
}
407
409
-function useEnvironmentLookups(environments: ReturnType<typeof useEnvironments>["environments"]) {
410
- // oxlint-disable-next-line t3code/no-manual-memo -- Kept until the palette's item building moves out of this component (see above).
411
- "use memo";
408
+function useEnvironmentLookups() {
409
+ const { environments } = useEnvironments();
410
const environmentLabelById = new Map(
411
environments.map((environment) => [environment.environmentId, environment.label] as const),
412
);
@@ -429,9 +427,8 @@ function useEnvironmentLookups(environments: ReturnType<typeof useEnvironments>[
427
return { environmentLabelById, projectEnvironmentLocationById };
428
}
429
432
-function useProjectLookups(projects: ReturnType<typeof useProjects>) {
433
- // oxlint-disable-next-line t3code/no-manual-memo -- Kept until the palette's item building moves out of this component (see above).
434
- "use memo";
430
+function useProjectLookups() {
431
+ const projects = useProjects();
432
const projectCwdById = new Map<ProjectId, string>(
433
projects.map((project) => [project.id, project.workspaceRoot]),
434
);
@@ -450,25 +447,13 @@ const selectCommandPaletteClientSettings = (settings: ClientSettings) => ({
447
sidebarProjectSortOrder: settings.sidebarProjectSortOrder,
448
sidebarThreadSortOrder: settings.sidebarThreadSortOrder,
449
});
453
-type CommandPaletteClientSettings = ReturnType<typeof selectCommandPaletteClientSettings>;
454
-
455
-function useSortedProjectGroups({
456
- projects,
457
- projectOrder,
458
- clientSettings,
459
- primaryEnvironmentId,
460
- environmentLabelById,
461
- threads,
462
-}: {
463
- readonly projects: ReturnType<typeof useProjects>;
464
- readonly projectOrder: ReturnType<typeof useUiStateStore.getState>["projectOrder"];
465
- readonly clientSettings: CommandPaletteClientSettings;
466
- readonly primaryEnvironmentId: ReturnType<typeof usePrimaryEnvironmentId>;
467
- readonly environmentLabelById: ReadonlyMap<EnvironmentId, string>;
468
- readonly threads: ReturnType<typeof useThreadShells>;
469
-}) {
470
- // oxlint-disable-next-line t3code/no-manual-memo -- Kept until the palette's item building moves out of this component (see above).
471
- "use memo";
450
+
451
+function useSortedProjectGroups(environmentLabelById: ReadonlyMap<EnvironmentId, string>) {
452
+ const projects = useProjects();
453
+ const threads = useThreadShells();
454
+ const projectOrder = useUiStateStore((store) => store.projectOrder);
455
+ const clientSettings = useClientSettings(selectCommandPaletteClientSettings);
456
+ const primaryEnvironmentId = usePrimaryEnvironmentId();
457
const projectGroupingSettings = {
458
sidebarProjectGroupingMode: clientSettings.sidebarProjectGroupingMode,
459
sidebarProjectGroupingOverrides: clientSettings.sidebarProjectGroupingOverrides,
@@ -806,7 +791,6 @@ function OpenCommandPaletteDialog(props: {
791
);
792
}
793
};
809
- const projectOrder = useUiStateStore((store) => store.projectOrder);
794
const threads = useThreadShells();
795
const keybindings = useAtomValue(primaryServerKeybindingsAtom);
796
const {
@@ -818,9 +802,7 @@ function OpenCommandPaletteDialog(props: {
802
setTheme,
803
setThemeHalf,
804
} = useTheme();
821
- const customThemes = useCustomThemes();
822
- const environmentThemes = useEnvironmentThemeDefinitions();
823
- const themeCards = useThemeCards(customThemes, environmentThemes);
805
+ const themeCards = useThemeCards();
806
const providers = useAtomValue(primaryServerProvidersAtom);
807
const providersByEnvironment = useEnvironmentProviders();
808
const providerEntryByEnvironmentAndInstanceId = new Map<string, ProviderInstanceEntry>(
@@ -844,8 +826,8 @@ function OpenCommandPaletteDialog(props: {
826
.filter((environment) => environment.connection.phase === "connected")
827
.map((environment) => environment.environmentId);
828
const threadSearchQuery = currentView === null && !isActionsOnly ? deferredQuery : "";
847
- const threadSearch = useThreadSearch(environmentIds, threadSearchQuery);
848
- const threadContentMatchByKey = useThreadContentMatchByKey(threadSearch.matches);
829
+ const { threadSearch, contentMatchByKey: threadContentMatchByKey } =
830
+ useThreadSearchWithContentMatches(environmentIds, threadSearchQuery);
831
const [browseGeneration, setBrowseGeneration] = useState(0);
832
const [browseNavigation] = useState(createBrowseNavigationCoordinator);
833
const [addProjectEnvironmentId, setAddProjectEnvironmentId] = useState<EnvironmentId | null>(
@@ -868,16 +850,8 @@ function OpenCommandPaletteDialog(props: {
850
const cloneLookupGeneration = useRef(0);
851
const [isRemoteProjectLookingUp, setIsRemoteProjectLookingUp] = useState(false);
852
const [isRemoteProjectCloning, setIsRemoteProjectCloning] = useState(false);
871
- const { environmentLabelById, projectEnvironmentLocationById } =
872
- useEnvironmentLookups(environments);
873
- const projectGroups = useSortedProjectGroups({
874
- projects,
875
- projectOrder,
876
- clientSettings,
877
- primaryEnvironmentId,
878
- environmentLabelById,
879
- threads,
880
- });
853
+ const { environmentLabelById, projectEnvironmentLocationById } = useEnvironmentLookups();
854
+ const projectGroups = useSortedProjectGroups(environmentLabelById);
855
const contextualProjectRef = resolveThreadActionProjectRef({
856
activeDraftThread,
857
activeThread: activeThread ?? undefined,
@@ -1000,7 +974,7 @@ function OpenCommandPaletteDialog(props: {
974
return ensureBrowseDirectoryPath(baseDirectory);
975
};
976
1003
- const { projectCwdById, projectByKey, projectTitleById } = useProjectLookups(projects);
977
+ const { projectCwdById, projectByKey, projectTitleById } = useProjectLookups();
978
979
const activeThreadId = activeThread?.id;
980
const supportsThreadFind =
docs/internals/web-ui.md
+3
-1
@@ -66,7 +66,9 @@ Every file under `apps/web/src` must compile. Lint makes those rules errors ther
66
no upstream rule bans them outright. It also rejects `"use memo"`. The compiler withholds a cache
67
scope when a value reaches plain function calls on both sides of a hook call. A `"use memo"`
68
helper forces one, but hides the ordering problem. Fix the order instead: plain uses of a value go
69
-before the hook, or the helper is inlined. Lint misses some bailouts, notably `try` with `finally` and
69
+before the hook, or the helper is inlined. A `use*` helper that calls no hook is compiled as a
70
+plain function and caches nothing, so a derived-value helper reads its source hook itself instead
71
+of taking the value as an argument. Lint misses some bailouts, notably `try` with `finally` and
72
`throw` inside `try`, so [`reactCompilerCoverage.test.ts`](../../apps/web/src/reactCompilerCoverage.test.ts)
73
compiles every file and fails on any skip. Async handlers rarely need `try`: an
74
atom command settles into a result, so cleanup can follow the `await`. `useStableCallback` still