@devries-cameron20 / t3code Mirror · read-only / commits / 68ed8d35bf
Fork 0

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): settings search items stay cached without "use memo" (#20771)

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

Julius Marminge committed Oct 16, 2026 at 23:18 UTC 68ed8d35bf38c9755805195ccb6731ba096d230f
1 file changed +31 -50
apps/web/src/components/settings/useAvailableSettingsSearchItems.ts
+31 -50
@@ -18,30 +18,21 @@ import {
18
19 export function useAvailableSettingsSearchItems(scopeSearch: SettingsScopeSearch = {}) {
20 const { environments } = useEnvironments();
21 - const primaryEnvironmentId = usePrimaryEnvironmentId();
22 - const localEnvironmentDisabled = isLocalEnvironmentDisabled();
23 - const canMaintain = useEnvironmentScope(primaryEnvironmentId, AuthEnvironmentMaintainScope);
24 - const canManageLocalBackend = !localEnvironmentDisabled && canMaintain;
25 - const desktopWsl = useEnvironmentQuery(
26 - isElectron && canManageLocalBackend ? desktopWslStateAtom : null,
27 - );
28 - const cloudLinkState = usePrimaryCloudLinkState().data;
29 - // Same fallback as the Connections row: older servers imply a tunnel from `linked`.
30 - const managedTunnelActive =
31 - cloudLinkState?.linkRevoked !== true &&
32 - (cloudLinkState?.managedTunnelActive ?? cloudLinkState?.linked ?? false);
33 -
34 - return useFilteredSettingsSearchItems({
35 - localEnvironmentDisabled,
36 - hasCloudPublicConfig: hasCloudPublicConfig(),
37 - hasEnvironment: environments.some((environment) => environment.serverConfig !== null),
38 - hasProviderSettingsEnvironment: environments.some((environment) =>
21 + // The filtered list must be cached on boolean flags so it stays stable for the search and
22 + // the command palette while environments update. The compiler cannot tell that `.some()`
23 + // and other plain calls return primitives, so `=== true` marks each flag as one; without
24 + // it the flags join the filter's cache scope and the list is rebuilt every render.
25 + const hasEnvironment =
26 + environments.some((environment) => environment.serverConfig !== null) === true;
27 + const hasProviderSettingsEnvironment =
28 + environments.some((environment) =>
29 isProviderSettingsEnvironmentAvailable({
30 connectionPhase: environment.connection.phase,
31 hasServerConfig: environment.serverConfig !== null,
32 }),
43 - ),
44 - hasMacProviderSettingsEnvironment: environments.some(
33 + ) === true;
34 + const hasMacProviderSettingsEnvironment =
35 + environments.some(
36 (environment) =>
37 (scopeSearch.machine === undefined || environment.environmentId === scopeSearch.machine) &&
38 environment.serverConfig?.environment.platform.os === "darwin" &&
@@ -49,43 +40,33 @@ export function useAvailableSettingsSearchItems(scopeSearch: SettingsScopeSearch
40 connectionPhase: environment.connection.phase,
41 hasServerConfig: true,
42 }),
52 - ),
53 - canManageLocalBackend,
54 - isWslSettingsRowVisible: isWslSettingsRowVisible({
55 - state: desktopWsl.data,
56 - error: desktopWsl.error,
57 - }),
58 - hasThreadAutoSettlement:
59 - getThreadAutoSettlementSearchAvailability(environments).eligibleEnvironmentIds.length > 0,
60 - managedTunnelActive,
61 - });
62 -}
43 + ) === true;
44 + const hasThreadAutoSettlement =
45 + getThreadAutoSettlementSearchAvailability(environments).eligibleEnvironmentIds.length > 0;
46 + const primaryEnvironmentId = usePrimaryEnvironmentId();
47 + const canMaintain = useEnvironmentScope(primaryEnvironmentId, AuthEnvironmentMaintainScope);
48 + const cloudLinkState = usePrimaryCloudLinkState().data;
49 + // Same fallback as the Connections row: older servers imply a tunnel from `linked`.
50 + const managedTunnelActive =
51 + cloudLinkState?.linkRevoked !== true &&
52 + (cloudLinkState?.managedTunnelActive ?? cloudLinkState?.linked ?? false) === true;
53 + const localEnvironmentDisabled = isLocalEnvironmentDisabled() === true;
54 + const canManageLocalBackend = !localEnvironmentDisabled && canMaintain;
55 + const desktopWsl = useEnvironmentQuery(
56 + isElectron && canManageLocalBackend ? desktopWslStateAtom : null,
57 + );
58 + const cloudPublicConfig = hasCloudPublicConfig() === true;
59 + const wslSettingsRowVisible =
60 + isWslSettingsRowVisible({ state: desktopWsl.data, error: desktopWsl.error }) === true;
61
64 -// The availability flags are primitives, so caching on them keeps the item list stable for the
65 -// search memo and the command palette while environments update.
66 -function useFilteredSettingsSearchItems(
67 - availability: Required<Parameters<typeof filterAvailableSettingsSearchItems>[0]>,
68 -) {
69 - "use memo";
70 - const {
71 - localEnvironmentDisabled,
72 - hasCloudPublicConfig,
73 - hasEnvironment,
74 - hasProviderSettingsEnvironment,
75 - hasMacProviderSettingsEnvironment,
76 - canManageLocalBackend,
77 - isWslSettingsRowVisible,
78 - hasThreadAutoSettlement,
79 - managedTunnelActive,
80 - } = availability;
62 return filterAvailableSettingsSearchItems({
63 localEnvironmentDisabled,
83 - hasCloudPublicConfig,
64 + hasCloudPublicConfig: cloudPublicConfig,
65 hasEnvironment,
66 hasProviderSettingsEnvironment,
67 hasMacProviderSettingsEnvironment,
68 canManageLocalBackend,
88 - isWslSettingsRowVisible,
69 + isWslSettingsRowVisible: wslSettingsRowVisible,
70 hasThreadAutoSettlement,
71 managedTunnelActive,
72 });