@@ -18,74 +18,55 @@ import {
1818
1919export function useAvailableSettingsSearchItems ( scopeSearch : SettingsScopeSearch = { } ) {
2020 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 ) =>
3929 isProviderSettingsEnvironmentAvailable ( {
4030 connectionPhase : environment . connection . phase ,
4131 hasServerConfig : environment . serverConfig !== null ,
4232 } ) ,
43- ) ,
44- hasMacProviderSettingsEnvironment : environments . some (
33+ ) === true ;
34+ const hasMacProviderSettingsEnvironment =
35+ environments . some (
4536 ( environment ) =>
4637 ( scopeSearch . machine === undefined || environment . environmentId === scopeSearch . machine ) &&
4738 environment . serverConfig ?. environment . platform . os === "darwin" &&
4839 isProviderSettingsEnvironmentAvailable ( {
4940 connectionPhase : environment . connection . phase ,
5041 hasServerConfig : true ,
5142 } ) ,
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 ;
6361
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 ;
8162 return filterAvailableSettingsSearchItems ( {
8263 localEnvironmentDisabled,
83- hasCloudPublicConfig,
64+ hasCloudPublicConfig : cloudPublicConfig ,
8465 hasEnvironment,
8566 hasProviderSettingsEnvironment,
8667 hasMacProviderSettingsEnvironment,
8768 canManageLocalBackend,
88- isWslSettingsRowVisible,
69+ isWslSettingsRowVisible : wslSettingsRowVisible ,
8970 hasThreadAutoSettlement,
9071 managedTunnelActive,
9172 } ) ;
0 commit comments