Skip to content

Commit e6ced71

Browse files
refactor(web): the command palette provider lookup keeps its caching without "use memo" (#20827)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent f03378f commit e6ced71

1 file changed

Lines changed: 17 additions & 29 deletions

File tree

‎apps/web/src/components/CommandPalette.tsx‎

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,9 @@ function notifyThemeSaveFailure(): void {
366366
);
367367
}
368368

369-
// These run in their own hooks so the results stay cached across the palette's
370-
// later hook calls; the thread and project items key on them.
369+
// Kept as "use memo" hooks: inlined, each result reaches the dialog's returned
370+
// <CommandPaletteContent> through the action and thread item arrays built after
371+
// the browse hooks, and the compiler leaves all of them uncached.
371372
function useThemeCards(
372373
customThemes: ReturnType<typeof useCustomThemes>,
373374
environmentThemes: ReturnType<typeof useEnvironmentThemeDefinitions>,
@@ -386,29 +387,6 @@ function useThemeCards(
386387
];
387388
}
388389

389-
function useProviderEntryMap(
390-
environments: ReturnType<typeof useEnvironments>["environments"],
391-
primaryEnvironmentId: ReturnType<typeof usePrimaryEnvironmentId>,
392-
providers: Parameters<typeof deriveProviderInstanceEntries>[0],
393-
) {
394-
"use memo";
395-
const map = new Map<string, ProviderInstanceEntry>();
396-
for (const environment of environments) {
397-
const serverConfig = environment.serverConfig;
398-
const environmentProviders =
399-
serverConfig?.providers ??
400-
(environment.environmentId === primaryEnvironmentId ? providers : []);
401-
const derived = deriveProviderInstanceEntries(environmentProviders);
402-
const entries = serverConfig
403-
? applyProviderInstanceSettings(derived, serverConfig.settings, null)
404-
: derived;
405-
for (const entry of entries) {
406-
map.set(`${environment.environmentId}:${entry.instanceId}`, entry);
407-
}
408-
}
409-
return map;
410-
}
411-
412390
function useThreadContentMatchByKey(matches: ReturnType<typeof useThreadSearch>["matches"]) {
413391
"use memo";
414392
return new Map(
@@ -828,10 +806,20 @@ function OpenCommandPaletteDialog(props: {
828806
const environmentThemes = useEnvironmentThemeDefinitions();
829807
const themeCards = useThemeCards(customThemes, environmentThemes);
830808
const providers = useAtomValue(primaryServerProvidersAtom);
831-
const providerEntryByEnvironmentAndInstanceId = useProviderEntryMap(
832-
environments,
833-
primaryEnvironmentId,
834-
providers,
809+
const providerEntryByEnvironmentAndInstanceId = new Map<string, ProviderInstanceEntry>(
810+
environments.flatMap((environment) => {
811+
const serverConfig = environment.serverConfig;
812+
const derived = deriveProviderInstanceEntries(
813+
serverConfig?.providers ??
814+
(environment.environmentId === primaryEnvironmentId ? providers : []),
815+
);
816+
const entries = serverConfig
817+
? applyProviderInstanceSettings(derived, serverConfig.settings, null)
818+
: derived;
819+
return entries.map(
820+
(entry) => [`${environment.environmentId}:${entry.instanceId}`, entry] as const,
821+
);
822+
}),
835823
);
836824
const [viewStack, setViewStack] = useState<CommandPaletteView[]>([]);
837825
const currentView = viewStack.at(-1) ?? null;

0 commit comments

Comments
 (0)