The best way to control Claude Code, Codex and more from any computer or phone
perf(web): connections settings compile with the React Compiler (#20515)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 16, 2026 at 19:04 UTC
6a326afb81c64b746d70602988795b528dfe8abc
2 files changed
+450
-562
apps/web/reactCompiledFiles.ts
+1
@@ -90,4 +90,5 @@ export const REACT_COMPILED_FILES = [
90
"apps/web/src/components/settings/IntegrationsSettings.tsx",
91
"apps/web/src/components/settings/ThemeImportDialog.tsx",
92
"apps/web/src/components/settings/SnapShotSettings.tsx",
93
+ "apps/web/src/components/settings/ConnectionsSettings.tsx",
94
] as const;
apps/web/src/components/settings/ConnectionsSettings.tsx
+449
-562
@@ -15,10 +15,8 @@ import {
15
type KeyboardEvent,
16
type ReactNode,
17
memo,
18
- useCallback,
18
useEffect,
19
useId,
21
- useMemo,
20
useRef,
21
useState,
22
} from "react";
@@ -55,8 +53,10 @@ import {
53
} from "@t3tools/client-runtime/connection";
54
import {
55
isAtomCommandInterrupted,
56
+ settlePromise,
57
squashAtomCommandFailure,
58
} from "@t3tools/client-runtime/state/runtime";
59
+import * as Cause from "effect/Cause";
60
import * as DateTime from "effect/DateTime";
61
import * as Option from "effect/Option";
62
@@ -574,33 +574,24 @@ const PairingLinkListRow = memo(function PairingLinkListRow({
574
canRevoke,
575
}: PairingLinkListRowProps) {
576
const nowMs = useRelativeTimeTick(1_000);
577
- const expiresAtMs = useMemo(
578
- () => new Date(pairingLink.expiresAt).getTime(),
579
- [pairingLink.expiresAt],
580
- );
577
+ const expiresAtMs = new Date(pairingLink.expiresAt).getTime();
578
const [isRevealDialogOpen, setIsRevealDialogOpen] = useState(false);
579
const [isQrPanelOpen, setIsQrPanelOpen] = useState(false);
580
const [qrEndpointId, setQrEndpointId] = useState<string | null>(null);
581
const qrPanelId = useId();
582
586
- const currentOriginPairingUrl = useMemo(
587
- () => (credential ? resolveCurrentOriginPairingUrl(credential) : null),
588
- [credential],
589
- );
590
- const hostedPairingUrl = useMemo(
591
- () =>
592
- credential && endpointUrl != null && endpointUrl !== ""
593
- ? resolveHostedPairingUrl(endpointUrl, credential)
594
- : null,
595
- [endpointUrl, credential],
596
- );
597
- const endpointPairingUrl = useMemo(() => {
583
+ const currentOriginPairingUrl = credential ? resolveCurrentOriginPairingUrl(credential) : null;
584
+ const hostedPairingUrl =
585
+ credential && endpointUrl != null && endpointUrl !== ""
586
+ ? resolveHostedPairingUrl(endpointUrl, credential)
587
+ : null;
588
+ const endpointPairingUrl = (() => {
589
const endpoint = selectPairingEndpoint(endpoints, defaultEndpointKey);
590
return endpoint && credential
591
? resolveAdvertisedEndpointPairingUrl(endpoint, credential)
592
: null;
602
- }, [defaultEndpointKey, endpoints, credential]);
603
- const endpointCopyOptions = useMemo(() => {
593
+ })();
594
+ const endpointCopyOptions = (() => {
595
const options: Array<{
596
readonly id: string;
597
readonly preferenceKey: string;
@@ -625,7 +616,7 @@ const PairingLinkListRow = memo(function PairingLinkListRow({
616
});
617
}
618
return options;
628
- }, [endpoints, credential]);
619
+ })();
620
const shareablePairingUrl =
621
endpointPairingUrl ??
622
(credential && endpointUrl != null && endpointUrl !== ""
@@ -686,21 +677,16 @@ const PairingLinkListRow = memo(function PairingLinkListRow({
677
},
678
});
679
689
- const copyPairingValue = useCallback(
690
- (value: string, kind: "code" | "hosted-link" | "link") => {
691
- copyToClipboard(value, { value, kind });
692
- },
693
- [copyToClipboard],
694
- );
680
+ const copyPairingValue = (value: string, kind: "code" | "hosted-link" | "link") => {
681
+ copyToClipboard(value, { value, kind });
682
+ };
683
696
- const copyKindForUrl = useCallback(
697
- (url: string): "hosted-link" | "link" => (isHostedAppPairingUrl(url) ? "hosted-link" : "link"),
698
- [],
699
- );
684
+ const copyKindForUrl = (url: string): "hosted-link" | "link" =>
685
+ isHostedAppPairingUrl(url) ? "hosted-link" : "link";
686
701
- const handleCopyCode = useCallback(() => {
687
+ const handleCopyCode = () => {
688
if (credential) copyPairingValue(credential, "code");
703
- }, [copyPairingValue, credential]);
689
+ };
690
691
const expiresAbsolute = formatAccessTimestamp(pairingLink.expiresAt);
692
@@ -1036,7 +1022,7 @@ const AuthorizedClientsHeaderAction = memo(function AuthorizedClientsHeaderActio
1022
const selectedScopes = pairingScopes.filter((scope) => delegatableScopes.includes(scope));
1023
const [isCreatingPairingLink, setIsCreatingPairingLink] = useState(false);
1024
1039
- const handleCreatePairingLink = useCallback(async () => {
1025
+ const handleCreatePairingLink = async () => {
1026
if (
1027
primaryEnvironmentId === null ||
1028
selectedScopes.length === 0 ||
@@ -1045,7 +1031,7 @@ const AuthorizedClientsHeaderAction = memo(function AuthorizedClientsHeaderActio
1031
)
1032
return;
1033
setIsCreatingPairingLink(true);
1048
- try {
1034
+ const settled = await settlePromise(async () => {
1035
const created = await createServerPairingCredential({
1036
label: pairingLabel,
1037
scopes: selectedScopes,
@@ -1056,7 +1042,9 @@ const AuthorizedClientsHeaderAction = memo(function AuthorizedClientsHeaderActio
1042
AuthStandardClientScopes.filter((scope) => delegatableScopes.includes(scope)),
1043
);
1044
setDialogOpen(false);
1059
- } catch (error) {
1045
+ });
1046
+ if (settled._tag === "Failure") {
1047
+ const error = Cause.squash(settled.cause);
1048
const message = error instanceof Error ? error.message : "Failed to create pairing URL.";
1049
toastManager.add(
1050
stackedThreadToast({
@@ -1065,14 +1053,13 @@ const AuthorizedClientsHeaderAction = memo(function AuthorizedClientsHeaderActio
1053
description: message,
1054
}),
1055
);
1068
- } finally {
1069
- setIsCreatingPairingLink(false);
1056
}
1071
- }, [delegatableScopes, onPairingLinkCreated, pairingLabel, primaryEnvironmentId, selectedScopes]);
1057
+ setIsCreatingPairingLink(false);
1058
+ };
1059
1073
- const togglePairingScope = useCallback((scope: AuthGrantScope, checked: boolean) => {
1060
+ const togglePairingScope = (scope: AuthGrantScope, checked: boolean) => {
1061
setPairingScopes((current) => togglePairingScopeSelection(current, scope, checked));
1075
- }, []);
1062
+ };
1063
1064
return (
1065
<div className="flex items-center gap-2">
@@ -1498,12 +1485,9 @@ function SavedBackendListRow({
1485
);
1486
},
1487
});
1501
- const copyTraceId = useCallback(
1502
- (traceId: string) => {
1503
- copyTraceIdToClipboard(traceId, { traceId });
1504
- },
1505
- [copyTraceIdToClipboard],
1506
- );
1488
+ const copyTraceId = (traceId: string) => {
1489
+ copyTraceIdToClipboard(traceId, { traceId });
1490
+ };
1491
const { copyToClipboard: copyMcpUrl } = useCopyToClipboard<{ url: string }>({
1492
target: "MCP URL",
1493
onCopy: ({ url }) => {
@@ -2035,72 +2019,55 @@ export function ConnectionsSettings() {
2019
? (primarySessionState.data.permissions ?? primarySessionState.data.scopes ?? null)
2020
: null;
2021
const currentAuthPolicy = desktopBridge ? null : (primarySessionState.data?.auth.policy ?? null);
2038
- const savedEnvironments = useMemo(
2039
- () =>
2040
- environments.filter(
2041
- (environment) => environment.entry.target._tag !== "PrimaryConnectionTarget",
2042
- ),
2043
- [environments],
2022
+ const savedEnvironments = environments.filter(
2023
+ (environment) => environment.entry.target._tag !== "PrimaryConnectionTarget",
2024
);
2045
- const listedEnvironments = useMemo(
2046
- () =>
2047
- savedEnvironments.filter(
2048
- (environment) => !isDesktopLocalConnectionTarget(environment.entry.target),
2049
- ),
2050
- [savedEnvironments],
2025
+ const listedEnvironments = savedEnvironments.filter(
2026
+ (environment) => !isDesktopLocalConnectionTarget(environment.entry.target),
2027
);
2052
- const savedServerUpdateStatesAtom = useMemo(
2053
- () =>
2054
- Atom.make((get) =>
2055
- savedEnvironments.map((environment) => ({
2056
- environment,
2057
- updateStatus: get(serverEnvironment.updateStateAtom(environment.environmentId)).status,
2058
- })),
2059
- ),
2060
- [savedEnvironments],
2028
+ const savedServerUpdateStatesAtom = Atom.make((get) =>
2029
+ savedEnvironments.map((environment) => ({
2030
+ environment,
2031
+ updateStatus: get(serverEnvironment.updateStateAtom(environment.environmentId)).status,
2032
+ })),
2033
);
2034
const savedServerUpdateStates = useAtomValue(savedServerUpdateStatesAtom);
2063
- const savedServerUpdateTargets = useMemo(
2064
- () =>
2065
- savedServerUpdateStates.flatMap(({ environment, updateStatus }): ServerUpdateTarget[] => {
2066
- const mismatch = resolveServerConfigVersionMismatch(environment.serverConfig);
2067
- const selfUpdate = resolveServerSelfUpdateCapability(environment.serverConfig);
2068
- const desktopAppUpdate = supportsDesktopAppUpdate(environment.serverConfig);
2069
- if (
2070
- !mismatch ||
2071
- updateStatus === "running" ||
2072
- !environment.entry.enabled ||
2073
- environment.connection.phase !== "connected" ||
2074
- isDesktopLocalConnectionTarget(environment.entry.target) ||
2075
- selfUpdate === null ||
2076
- (selfUpdate === "desktop-managed" && !desktopAppUpdate)
2077
- ) {
2078
- return [];
2079
- }
2080
- return [
2081
- {
2082
- environmentId: environment.environmentId,
2083
- serverLabel: environment.label,
2084
- selfUpdate,
2085
- installation: environment.serverConfig?.environment.capabilities.serverInstallation,
2086
- desktopAppUpdate,
2087
- threadContinuation: supportsServerUpdateThreadContinuation(environment.serverConfig),
2088
- continueThreadsAfterServerUpdate:
2089
- environment.serverConfig?.settings.continueThreadsAfterServerUpdate ?? false,
2090
- targetVersion: mismatch.clientVersion,
2091
- },
2092
- ];
2093
- }),
2094
- [savedServerUpdateStates],
2095
- );
2096
- const loadBalancingEnvironments = useMemo(
2097
- () => [
2098
- ...(primaryEnvironment ? [primaryEnvironment] : []),
2099
- ...savedEnvironments.filter((environment) => environment.entry.enabled),
2100
- ],
2101
- [primaryEnvironment, savedEnvironments],
2035
+ const savedServerUpdateTargets = savedServerUpdateStates.flatMap(
2036
+ ({ environment, updateStatus }): ServerUpdateTarget[] => {
2037
+ const mismatch = resolveServerConfigVersionMismatch(environment.serverConfig);
2038
+ const selfUpdate = resolveServerSelfUpdateCapability(environment.serverConfig);
2039
+ const desktopAppUpdate = supportsDesktopAppUpdate(environment.serverConfig);
2040
+ if (
2041
+ !mismatch ||
2042
+ updateStatus === "running" ||
2043
+ !environment.entry.enabled ||
2044
+ environment.connection.phase !== "connected" ||
2045
+ isDesktopLocalConnectionTarget(environment.entry.target) ||
2046
+ selfUpdate === null ||
2047
+ (selfUpdate === "desktop-managed" && !desktopAppUpdate)
2048
+ ) {
2049
+ return [];
2050
+ }
2051
+ return [
2052
+ {
2053
+ environmentId: environment.environmentId,
2054
+ serverLabel: environment.label,
2055
+ selfUpdate,
2056
+ installation: environment.serverConfig?.environment.capabilities.serverInstallation,
2057
+ desktopAppUpdate,
2058
+ threadContinuation: supportsServerUpdateThreadContinuation(environment.serverConfig),
2059
+ continueThreadsAfterServerUpdate:
2060
+ environment.serverConfig?.settings.continueThreadsAfterServerUpdate ?? false,
2061
+ targetVersion: mismatch.clientVersion,
2062
+ },
2063
+ ];
2064
+ },
2065
);
2103
- const savedDesktopSshEnvironmentKeys = useMemo(() => {
2066
+ const loadBalancingEnvironments = [
2067
+ ...(primaryEnvironment ? [primaryEnvironment] : []),
2068
+ ...savedEnvironments.filter((environment) => environment.entry.enabled),
2069
+ ];
2070
+ const savedDesktopSshEnvironmentKeys = (() => {
2071
const keys = new Set<string>();
2072
for (const environment of savedEnvironments) {
2073
const profile = environment.entry.profile;
@@ -2116,7 +2083,7 @@ export function ConnectionsSettings() {
2083
keys.add(formatDesktopSshTarget(target));
2084
}
2085
return keys;
2119
- }, [savedEnvironments]);
2086
+ })();
2087
const [desktopServerExposureMutationError, setDesktopServerExposureMutationError] = useState<
2088
string | null
2089
>(null);
@@ -2126,9 +2093,9 @@ export function ConnectionsSettings() {
2093
const [createdPairingCredentials, setCreatedPairingCredentials] = useState<
2094
ReadonlyMap<string, string>
2095
>(() => new Map());
2129
- const handlePairingLinkCreated = useCallback((created: AuthPairingCredentialResult) => {
2096
+ const handlePairingLinkCreated = (created: AuthPairingCredentialResult) => {
2097
setCreatedPairingCredentials((current) => new Map(current).set(created.id, created.credential));
2131
- }, []);
2098
+ };
2099
const [revokingDesktopPairingLinkId, setRevokingDesktopPairingLinkId] = useState<string | null>(
2100
null,
2101
);
@@ -2218,20 +2185,16 @@ export function ConnectionsSettings() {
2185
const desktopWslError = desktopWslMutationError ?? desktopWsl.error;
2186
const isLoadingWslState = desktopWsl.isPending && desktopWsl.data === null;
2187
const discoveredSshHosts = desktopSshHosts.data ?? EMPTY_DISCOVERED_SSH_HOSTS;
2221
- const unsavedDiscoveredSshHosts = useMemo(
2222
- () =>
2223
- discoveredSshHosts.filter((target) => {
2224
- const address = formatDesktopSshTarget(target);
2225
- return (
2226
- !savedDesktopSshEnvironmentKeys.has(target.alias) &&
2227
- !savedDesktopSshEnvironmentKeys.has(address)
2228
- );
2229
- }),
2230
- [discoveredSshHosts, savedDesktopSshEnvironmentKeys],
2231
- );
2232
- const filteredDiscoveredSshHosts = useMemo(
2233
- () => filterDiscoveredSshHosts(unsavedDiscoveredSshHosts, savedBackendSshHost),
2234
- [savedBackendSshHost, unsavedDiscoveredSshHosts],
2188
+ const unsavedDiscoveredSshHosts = discoveredSshHosts.filter((target) => {
2189
+ const address = formatDesktopSshTarget(target);
2190
+ return (
2191
+ !savedDesktopSshEnvironmentKeys.has(target.alias) &&
2192
+ !savedDesktopSshEnvironmentKeys.has(address)
2193
+ );
2194
+ });
2195
+ const filteredDiscoveredSshHosts = filterDiscoveredSshHosts(
2196
+ unsavedDiscoveredSshHosts,
2197
+ savedBackendSshHost,
2198
);
2199
const isLoadingDiscoveredSshHosts = desktopSshHosts.isPending && desktopSshHosts.data === null;
2200
const discoveredSshHostsError = desktopSshHosts.error;
@@ -2247,7 +2210,7 @@ export function ConnectionsSettings() {
2210
desktopAccessManagementMutationError ?? authAccessChanges.error;
2211
const isLoadingDesktopAccessManagement =
2212
authAccessChanges.isPending && authAccessChanges.data === null;
2250
- const desktopPairingLinks = useMemo(() => {
2213
+ const desktopPairingLinks = (() => {
2214
const event = authAccessChanges.data;
2215
if (event?.type !== "snapshot") return [];
2216
return sortDesktopPairingLinks(
@@ -2255,8 +2218,8 @@ export function ConnectionsSettings() {
2218
toDesktopPairingLinkRecord(pairingLink),
2219
),
2220
);
2258
- }, [authAccessChanges.data]);
2259
- const desktopClientSessions = useMemo(() => {
2221
+ })();
2222
+ const desktopClientSessions = (() => {
2223
const event = authAccessChanges.data;
2224
if (event?.type !== "snapshot") return [];
2225
return sortDesktopClientSessions(
@@ -2264,7 +2227,7 @@ export function ConnectionsSettings() {
2227
toDesktopClientSessionRecord(clientSession),
2228
),
2229
);
2267
- }, [authAccessChanges.data]);
2230
+ })();
2231
const isLocalBackendNetworkAccessible = desktopBridge
2232
? desktopServerExposureState?.mode === "network-accessible"
2233
: currentAuthPolicy === "remote-reachable";
@@ -2276,7 +2239,7 @@ export function ConnectionsSettings() {
2239
parsedTailscaleServePort >= 1 &&
2240
parsedTailscaleServePort <= 65_535;
2241
2279
- const pendingTailscaleServeBaseUrl = useMemo(() => {
2242
+ const pendingTailscaleServeBaseUrl = (() => {
2243
if (!pendingTailscaleServeEndpoint) return null;
2244
if (!isTailscaleServePortValid) return pendingTailscaleServeEndpoint.httpBaseUrl;
2245
if (parsedTailscaleServePort === DEFAULT_TAILSCALE_SERVE_PORT) {
@@ -2289,48 +2252,44 @@ export function ConnectionsSettings() {
2252
} catch {
2253
return pendingTailscaleServeEndpoint.httpBaseUrl;
2254
}
2292
- }, [isTailscaleServePortValid, parsedTailscaleServePort, pendingTailscaleServeEndpoint]);
2255
+ })();
2256
2294
- const handleDesktopServerExposureChange = useCallback(
2295
- async (checked: boolean) => {
2296
- if (
2297
- !desktopBridge ||
2298
- primaryEnvironmentId === null ||
2299
- !readEnvironmentScope(primaryEnvironmentId, AuthEnvironmentMaintainScope)
2300
- )
2301
- return;
2302
- setIsUpdatingDesktopServerExposure(true);
2303
- setDesktopServerExposureMutationError(null);
2304
- try {
2305
- await desktopBridge.setServerExposureMode(checked ? "network-accessible" : "local-only");
2306
- refreshDesktopNetworkAccessState();
2307
- setIsDesktopServerExposureDialogOpen(false);
2308
- setIsUpdatingDesktopServerExposure(false);
2309
- } catch (error) {
2310
- const message =
2311
- error instanceof Error ? error.message : "Failed to update network exposure.";
2312
- setIsDesktopServerExposureDialogOpen(false);
2313
- setDesktopServerExposureMutationError(message);
2314
- toastManager.add(
2315
- stackedThreadToast({
2316
- type: "error",
2317
- title: "Could not update network access",
2318
- description: message,
2319
- }),
2320
- );
2321
- setIsUpdatingDesktopServerExposure(false);
2322
- }
2323
- },
2324
- [desktopBridge, primaryEnvironmentId],
2325
- );
2257
+ const handleDesktopServerExposureChange = async (checked: boolean) => {
2258
+ if (
2259
+ !desktopBridge ||
2260
+ primaryEnvironmentId === null ||
2261
+ !readEnvironmentScope(primaryEnvironmentId, AuthEnvironmentMaintainScope)
2262
+ )
2263
+ return;
2264
+ setIsUpdatingDesktopServerExposure(true);
2265
+ setDesktopServerExposureMutationError(null);
2266
+ try {
2267
+ await desktopBridge.setServerExposureMode(checked ? "network-accessible" : "local-only");
2268
+ refreshDesktopNetworkAccessState();
2269
+ setIsDesktopServerExposureDialogOpen(false);
2270
+ setIsUpdatingDesktopServerExposure(false);
2271
+ } catch (error) {
2272
+ const message = error instanceof Error ? error.message : "Failed to update network exposure.";
2273
+ setIsDesktopServerExposureDialogOpen(false);
2274
+ setDesktopServerExposureMutationError(message);
2275
+ toastManager.add(
2276
+ stackedThreadToast({
2277
+ type: "error",
2278
+ title: "Could not update network access",
2279
+ description: message,
2280
+ }),
2281
+ );
2282
+ setIsUpdatingDesktopServerExposure(false);
2283
+ }
2284
+ };
2285
2327
- const handleConfirmDesktopServerExposureChange = useCallback(() => {
2286
+ const handleConfirmDesktopServerExposureChange = () => {
2287
if (pendingDesktopServerExposureMode === null) return;
2288
const checked = pendingDesktopServerExposureMode === "network-accessible";
2289
void handleDesktopServerExposureChange(checked);
2331
- }, [handleDesktopServerExposureChange, pendingDesktopServerExposureMode]);
2290
+ };
2291
2333
- const handleConfirmTailscaleServeSetup = useCallback(async () => {
2292
+ const handleConfirmTailscaleServeSetup = async () => {
2293
if (
2294
!desktopBridge ||
2295
primaryEnvironmentId === null ||
@@ -2340,14 +2299,16 @@ export function ConnectionsSettings() {
2299
if (!isTailscaleServePortValid) return;
2300
setIsUpdatingTailscaleServe(true);
2301
setDesktopServerExposureMutationError(null);
2343
- try {
2302
+ const settled = await settlePromise(async () => {
2303
await desktopBridge.setTailscaleServeEnabled({
2304
enabled: true,
2305
port: parsedTailscaleServePort,
2306
});
2307
refreshDesktopNetworkAccessState();
2308
setPendingTailscaleServeEndpoint(null);
2350
- } catch (error) {
2309
+ });
2310
+ if (settled._tag === "Failure") {
2311
+ const error = Cause.squash(settled.cause);
2312
const message =
2313
error instanceof Error ? error.message : "Failed to configure Tailscale HTTPS.";
2314
setDesktopServerExposureMutationError(message);
@@ -2358,22 +2319,18 @@ export function ConnectionsSettings() {
2319
description: message,
2320
}),
2321
);
2361
- } finally {
2362
- setIsUpdatingTailscaleServe(false);
2322
}
2364
- }, [desktopBridge, isTailscaleServePortValid, parsedTailscaleServePort, primaryEnvironmentId]);
2323
+ setIsUpdatingTailscaleServe(false);
2324
+ };
2325
2366
- const handleStartTailscaleServeSetup = useCallback(
2367
- (endpoint: AdvertisedEndpoint) => {
2368
- setTailscaleServePortInput(
2369
- String(desktopServerExposureState?.tailscaleServePort ?? DEFAULT_TAILSCALE_SERVE_PORT),
2370
- );
2371
- setPendingTailscaleServeEndpoint(endpoint);
2372
- },
2373
- [desktopServerExposureState?.tailscaleServePort],
2374
- );
2326
+ const handleStartTailscaleServeSetup = (endpoint: AdvertisedEndpoint) => {
2327
+ setTailscaleServePortInput(
2328
+ String(desktopServerExposureState?.tailscaleServePort ?? DEFAULT_TAILSCALE_SERVE_PORT),
2329
+ );
2330
+ setPendingTailscaleServeEndpoint(endpoint);
2331
+ };
2332
2376
- const handleConfirmTailscaleServeDisable = useCallback(async () => {
2333
+ const handleConfirmTailscaleServeDisable = async () => {
2334
if (
2335
!desktopBridge ||
2336
primaryEnvironmentId === null ||
@@ -2382,14 +2339,16 @@ export function ConnectionsSettings() {
2339
return;
2340
setIsUpdatingTailscaleServe(true);
2341
setDesktopServerExposureMutationError(null);
2385
- try {
2342
+ const settled = await settlePromise(async () => {
2343
await desktopBridge.setTailscaleServeEnabled({
2344
enabled: false,
2345
port: desktopServerExposureState?.tailscaleServePort ?? DEFAULT_TAILSCALE_SERVE_PORT,
2346
});
2347
refreshDesktopNetworkAccessState();
2348
setDisableTailscaleServeDialogOpen(false);
2392
- } catch (error) {
2349
+ });
2350
+ if (settled._tag === "Failure") {
2351
+ const error = Cause.squash(settled.cause);
2352
const message = error instanceof Error ? error.message : "Failed to disable Tailscale HTTPS.";
2353
setDesktopServerExposureMutationError(message);
2354
toastManager.add(
@@ -2399,72 +2358,69 @@ export function ConnectionsSettings() {
2358
description: message,
2359
}),
2360
);
2402
- } finally {
2403
- setIsUpdatingTailscaleServe(false);
2361
}
2405
- }, [desktopBridge, desktopServerExposureState, primaryEnvironmentId]);
2362
+ setIsUpdatingTailscaleServe(false);
2363
+ };
2364
2407
- const handleStartTailscaleServeDisable = useCallback((_endpoint: AdvertisedEndpoint) => {
2365
+ const handleStartTailscaleServeDisable = (_endpoint: AdvertisedEndpoint) => {
2366
setDisableTailscaleServeDialogOpen(true);
2409
- }, []);
2367
+ };
2368
2411
- const handleRevokeDesktopPairingLink = useCallback(
2412
- async (id: string) => {
2413
- if (
2414
- primaryEnvironmentId === null ||
2415
- !readEnvironmentScope(primaryEnvironmentId, AuthAccessWriteScope)
2416
- )
2417
- return;
2418
- setRevokingDesktopPairingLinkId(id);
2419
- setDesktopAccessManagementMutationError(null);
2420
- try {
2421
- await revokeServerPairingLink(id);
2422
- } catch (error) {
2423
- const message = error instanceof Error ? error.message : "Failed to revoke pairing link.";
2424
- setDesktopAccessManagementMutationError(message);
2425
- toastManager.add(
2426
- stackedThreadToast({
2427
- type: "error",
2428
- title: "Could not revoke pairing link",
2429
- description: message,
2430
- }),
2431
- );
2432
- } finally {
2433
- setRevokingDesktopPairingLinkId(null);
2434
- }
2435
- },
2436
- [primaryEnvironmentId],
2437
- );
2369
+ const handleRevokeDesktopPairingLink = async (id: string) => {
2370
+ if (
2371
+ primaryEnvironmentId === null ||
2372
+ !readEnvironmentScope(primaryEnvironmentId, AuthAccessWriteScope)
2373
+ )
2374
+ return;
2375
+ setRevokingDesktopPairingLinkId(id);
2376
+ setDesktopAccessManagementMutationError(null);
2377
+ const settled = await settlePromise(async () => {
2378
+ await revokeServerPairingLink(id);
2379
+ });
2380
+ if (settled._tag === "Failure") {
2381
+ const error = Cause.squash(settled.cause);
2382
+ const message = error instanceof Error ? error.message : "Failed to revoke pairing link.";
2383
+ setDesktopAccessManagementMutationError(message);
2384
+ toastManager.add(
2385
+ stackedThreadToast({
2386
+ type: "error",
2387
+ title: "Could not revoke pairing link",
2388
+ description: message,
2389
+ }),
2390
+ );
2391
+ }
2392
+ setRevokingDesktopPairingLinkId(null);
2393
+ };
2394
2439
- const handleRevokeDesktopClientSession = useCallback(
2440
- async (sessionId: ServerClientSessionRecord["sessionId"]) => {
2441
- if (
2442
- primaryEnvironmentId === null ||
2443
- !readEnvironmentScope(primaryEnvironmentId, AuthAccessWriteScope)
2444
- )
2445
- return;
2446
- setRevokingDesktopClientSessionId(sessionId);
2447
- setDesktopAccessManagementMutationError(null);
2448
- try {
2449
- await revokeServerClientSession(sessionId);
2450
- } catch (error) {
2451
- const message = error instanceof Error ? error.message : "Failed to revoke client access.";
2452
- setDesktopAccessManagementMutationError(message);
2453
- toastManager.add(
2454
- stackedThreadToast({
2455
- type: "error",
2456
- title: "Could not revoke client access",
2457
- description: message,
2458
- }),
2459
- );
2460
- } finally {
2461
- setRevokingDesktopClientSessionId(null);
2462
- }
2463
- },
2464
- [primaryEnvironmentId],
2465
- );
2395
+ const handleRevokeDesktopClientSession = async (
2396
+ sessionId: ServerClientSessionRecord["sessionId"],
2397
+ ) => {
2398
+ if (
2399
+ primaryEnvironmentId === null ||
2400
+ !readEnvironmentScope(primaryEnvironmentId, AuthAccessWriteScope)
2401
+ )
2402
+ return;
2403
+ setRevokingDesktopClientSessionId(sessionId);
2404
+ setDesktopAccessManagementMutationError(null);
2405
+ const settled = await settlePromise(async () => {
2406
+ await revokeServerClientSession(sessionId);
2407
+ });
2408
+ if (settled._tag === "Failure") {
2409
+ const error = Cause.squash(settled.cause);
2410
+ const message = error instanceof Error ? error.message : "Failed to revoke client access.";
2411
+ setDesktopAccessManagementMutationError(message);
2412
+ toastManager.add(
2413
+ stackedThreadToast({
2414
+ type: "error",
2415
+ title: "Could not revoke client access",
2416
+ description: message,
2417
+ }),
2418
+ );
2419
+ }
2420
+ setRevokingDesktopClientSessionId(null);
2421
+ };
2422
2467
- const handleRevokeOtherDesktopClients = useCallback(async () => {
2423
+ const handleRevokeOtherDesktopClients = async () => {
2424
if (
2425
primaryEnvironmentId === null ||
2426
!readEnvironmentScope(primaryEnvironmentId, AuthAccessWriteScope)
@@ -2472,14 +2428,16 @@ export function ConnectionsSettings() {
2428
return;
2429
setIsRevokingOtherDesktopClients(true);
2430
setDesktopAccessManagementMutationError(null);
2475
- try {
2431
+ const settled = await settlePromise(async () => {
2432
const revokedCount = await revokeOtherServerClientSessions();
2433
toastManager.add({
2434
type: "success",
2435
title: revokedCount === 1 ? "Revoked 1 other client" : `Revoked ${revokedCount} clients`,
2436
description: "Other paired clients will need a new pairing link before reconnecting.",
2437
});
2482
- } catch (error) {
2438
+ });
2439
+ if (settled._tag === "Failure") {
2440
+ const error = Cause.squash(settled.cause);
2441
const message = error instanceof Error ? error.message : "Failed to revoke other clients.";
2442
setDesktopAccessManagementMutationError(message);
2443
toastManager.add(
@@ -2489,47 +2447,43 @@ export function ConnectionsSettings() {
2447
description: message,
2448
}),
2449
);
2492
- } finally {
2493
- setIsRevokingOtherDesktopClients(false);
2450
}
2495
- }, [primaryEnvironmentId]);
2496
-
2497
- const connectSavedBackendSshTarget = useCallback(
2498
- async (target: DesktopSshEnvironmentTarget) => {
2499
- setIsAddingSavedBackend(true);
2500
- setSavedBackendError(null);
2501
- const result = await connectSshEnvironment({
2502
- target,
2503
- label: "",
2504
- ...(routeTarget ? { expectedEnvironmentId: routeTarget.environmentId } : {}),
2505
- });
2506
- if (result._tag === "Failure") {
2507
- if (!isAtomCommandInterrupted(result)) {
2508
- setSavedBackendError(formatDesktopSshConnectionError(squashAtomCommandFailure(result)));
2509
- }
2510
- setIsAddingSavedBackend(false);
2511
- return;
2512
- }
2451
+ setIsRevokingOtherDesktopClients(false);
2452
+ };
2453
2514
- setSavedBackendHost("");
2515
- setSavedBackendPairingCode("");
2516
- setSavedBackendSshHost("");
2517
- setSavedBackendSshUsername("");
2518
- setSavedBackendSshPort("");
2519
- setAddBackendDialogOpen(false);
2520
- toastManager.add({
2521
- type: "success",
2522
- title: routeTarget ? "Route added" : "Environment connected",
2523
- description: routeTarget
2524
- ? `${routeTarget.label} can now be reached over SSH ${target.alias}.`
2525
- : `${target.alias} is ready over an SSH-managed tunnel.`,
2526
- });
2454
+ const connectSavedBackendSshTarget = async (target: DesktopSshEnvironmentTarget) => {
2455
+ setIsAddingSavedBackend(true);
2456
+ setSavedBackendError(null);
2457
+ const result = await connectSshEnvironment({
2458
+ target,
2459
+ label: "",
2460
+ ...(routeTarget ? { expectedEnvironmentId: routeTarget.environmentId } : {}),
2461
+ });
2462
+ if (result._tag === "Failure") {
2463
+ if (!isAtomCommandInterrupted(result)) {
2464
+ setSavedBackendError(formatDesktopSshConnectionError(squashAtomCommandFailure(result)));
2465
+ }
2466
setIsAddingSavedBackend(false);
2528
- },
2529
- [connectSshEnvironment, routeTarget],
2530
- );
2467
+ return;
2468
+ }
2469
+
2470
+ setSavedBackendHost("");
2471
+ setSavedBackendPairingCode("");
2472
+ setSavedBackendSshHost("");
2473
+ setSavedBackendSshUsername("");
2474
+ setSavedBackendSshPort("");
2475
+ setAddBackendDialogOpen(false);
2476
+ toastManager.add({
2477
+ type: "success",
2478
+ title: routeTarget ? "Route added" : "Environment connected",
2479
+ description: routeTarget
2480
+ ? `${routeTarget.label} can now be reached over SSH ${target.alias}.`
2481
+ : `${target.alias} is ready over an SSH-managed tunnel.`,
2482
+ });
2483
+ setIsAddingSavedBackend(false);
2484
+ };
2485
2532
- const handleAddSavedBackend = useCallback(async () => {
2486
+ const handleAddSavedBackend = async () => {
2487
if (savedBackendMode === "ssh") {
2488
let target: DesktopSshEnvironmentTarget;
2489
try {
@@ -2610,209 +2564,155 @@ export function ConnectionsSettings() {
2564
},
2565
);
2566
setIsAddingSavedBackend(false);
2613
- }, [
2614
- routeTarget,
2615
- connectPairing,
2616
- connectSavedBackendSshTarget,
2617
- savedBackendHost,
2618
- savedBackendMode,
2619
- savedBackendPairingCode,
2620
- savedBackendSshHost,
2621
- savedBackendSshPort,
2622
- savedBackendSshUsername,
2623
- ]);
2567
+ };
2568
2625
- const handleSavedBackendSshFieldKeyDown = useCallback(
2626
- (event: KeyboardEvent<HTMLInputElement>) => {
2627
- if (event.nativeEvent.isComposing || event.keyCode === 229) return;
2628
- if (event.key === "Enter" && savedBackendSshHost.trim().length > 0) {
2629
- event.preventDefault();
2630
- void handleAddSavedBackend();
2631
- }
2632
- },
2633
- [handleAddSavedBackend, savedBackendSshHost],
2634
- );
2569
+ const handleSavedBackendSshFieldKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
2570
+ if (event.nativeEvent.isComposing || event.keyCode === 229) return;
2571
+ if (event.key === "Enter" && savedBackendSshHost.trim().length > 0) {
2572
+ event.preventDefault();
2573
+ void handleAddSavedBackend();
2574
+ }
2575
+ };
2576
2636
- const handleSelectSshHostSuggestion = useCallback(
2637
- async (target: DesktopDiscoveredSshHost) => {
2638
- if (isAddingSavedBackend || !desktopBridge) return;
2577
+ const handleSelectSshHostSuggestion = async (target: DesktopDiscoveredSshHost) => {
2578
+ if (isAddingSavedBackend || !desktopBridge) return;
2579
2640
- setIsAddingSavedBackend(true);
2641
- setSavedBackendError(null);
2642
- setSavedBackendSshHost(target.alias);
2643
- let resolved: DesktopSshEnvironmentTarget;
2644
- try {
2645
- resolved = await desktopBridge.resolveSshHost(target.alias);
2646
- } catch (error) {
2647
- setSavedBackendError(formatDesktopSshConnectionError(error));
2648
- setIsAddingSavedBackend(false);
2649
- return;
2650
- }
2651
- setSavedBackendSshUsername(resolved.username ?? "");
2652
- setSavedBackendSshPort(resolved.port === null ? "" : String(resolved.port));
2653
- await connectSavedBackendSshTarget(resolved);
2654
- },
2655
- [connectSavedBackendSshTarget, desktopBridge, isAddingSavedBackend],
2656
- );
2657
-
2658
- const handleSavedBackendSshHostKeyDown = useCallback(
2659
- (event: KeyboardEvent<HTMLInputElement>) => {
2660
- if (event.nativeEvent.isComposing || event.keyCode === 229) return;
2580
+ setIsAddingSavedBackend(true);
2581
+ setSavedBackendError(null);
2582
+ setSavedBackendSshHost(target.alias);
2583
+ let resolved: DesktopSshEnvironmentTarget;
2584
+ try {
2585
+ resolved = await desktopBridge.resolveSshHost(target.alias);
2586
+ } catch (error) {
2587
+ setSavedBackendError(formatDesktopSshConnectionError(error));
2588
+ setIsAddingSavedBackend(false);
2589
+ return;
2590
+ }
2591
+ setSavedBackendSshUsername(resolved.username ?? "");
2592
+ setSavedBackendSshPort(resolved.port === null ? "" : String(resolved.port));
2593
+ await connectSavedBackendSshTarget(resolved);
2594
+ };
2595
2662
- const isSshHostPopupVisible = sshHostSuggestionsOpen && hasSshHostSuggestionContent;
2663
- if (isSshHostPopupVisible) {
2664
- const command = resolveShortcutCommand(event, keybindings, {
2665
- platform: navigator.platform,
2666
- context: { modelPickerOpen: false },
2667
- });
2668
- const index = threadJumpIndexFromCommand(command ?? "");
2669
- const target = index === null ? undefined : filteredDiscoveredSshHosts[index];
2670
- if (target) {
2671
- event.preventDefault();
2672
- event.stopPropagation();
2673
- setSshHostSuggestionsOpen(false);
2674
- void handleSelectSshHostSuggestion(target);
2675
- return;
2676
- }
2596
+ const handleSavedBackendSshHostKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
2597
+ if (event.nativeEvent.isComposing || event.keyCode === 229) return;
2598
2678
- if (event.key === "Escape") {
2679
- event.preventDefault();
2680
- event.stopPropagation();
2681
- return;
2682
- }
2599
+ const isSshHostPopupVisible = sshHostSuggestionsOpen && hasSshHostSuggestionContent;
2600
+ if (isSshHostPopupVisible) {
2601
+ const command = resolveShortcutCommand(event, keybindings, {
2602
+ platform: navigator.platform,
2603
+ context: { modelPickerOpen: false },
2604
+ });
2605
+ const index = threadJumpIndexFromCommand(command ?? "");
2606
+ const target = index === null ? undefined : filteredDiscoveredSshHosts[index];
2607
+ if (target) {
2608
+ event.preventDefault();
2609
+ event.stopPropagation();
2610
+ setSshHostSuggestionsOpen(false);
2611
+ void handleSelectSshHostSuggestion(target);
2612
+ return;
2613
}
2614
2685
- const hasHighlightedSshHost =
2686
- isSshHostPopupVisible && highlightedSshHostRef.current !== undefined;
2687
- if (
2688
- !event.defaultPrevented &&
2689
- !hasHighlightedSshHost &&
2690
- event.key === "Enter" &&
2691
- savedBackendSshHost.trim().length > 0
2692
- ) {
2615
+ if (event.key === "Escape") {
2616
event.preventDefault();
2694
- void handleAddSavedBackend();
2617
+ event.stopPropagation();
2618
+ return;
2619
}
2696
- },
2697
- [
2698
- filteredDiscoveredSshHosts,
2699
- handleAddSavedBackend,
2700
- handleSelectSshHostSuggestion,
2701
- hasSshHostSuggestionContent,
2702
- keybindings,
2703
- savedBackendSshHost,
2704
- sshHostSuggestionsOpen,
2705
- ],
2706
- );
2620
+ }
2621
2708
- const handleSetSavedBackendEnabled = useCallback(
2709
- async (environmentId: EnvironmentId, enabled: boolean) => {
2710
- setSavedBackendError(null);
2711
- const result = await setEnvironmentEnabled({ environmentId, enabled });
2712
- if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
2713
- const error = squashAtomCommandFailure(result);
2714
- const message =
2715
- error instanceof Error
2716
- ? error.message
2717
- : `Failed to switch the backend ${enabled ? "on" : "off"}.`;
2718
- setSavedBackendError(message);
2719
- toastManager.add(
2720
- stackedThreadToast({
2721
- type: "error",
2722
- title: `Could not switch backend ${enabled ? "on" : "off"}`,
2723
- description: message,
2724
- }),
2725
- );
2726
- }
2727
- },
2728
- [setEnvironmentEnabled],
2729
- );
2622
+ const hasHighlightedSshHost =
2623
+ isSshHostPopupVisible && highlightedSshHostRef.current !== undefined;
2624
+ if (
2625
+ !event.defaultPrevented &&
2626
+ !hasHighlightedSshHost &&
2627
+ event.key === "Enter" &&
2628
+ savedBackendSshHost.trim().length > 0
2629
+ ) {
2630
+ event.preventDefault();
2631
+ void handleAddSavedBackend();
2632
+ }
2633
+ };
2634
2731
- const removeSavedBackend = useCallback(
2732
- async (environment: EnvironmentPresentation) => {
2733
- const environmentId = environment.environmentId;
2734
- setRemovingSavedEnvironmentId(environmentId);
2735
- setSavedBackendError(null);
2736
- const result = await removeEnvironment(environmentId);
2737
- setRemovingSavedEnvironmentId(null);
2738
- if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
2739
- const error = squashAtomCommandFailure(result);
2740
- const message = error instanceof Error ? error.message : "Failed to remove backend.";
2741
- setSavedBackendError(message);
2742
- toastManager.add(
2743
- stackedThreadToast({
2744
- type: "error",
2745
- title: "Could not remove backend",
2746
- description: message,
2747
- }),
2748
- );
2749
- }
2750
- },
2751
- [removeEnvironment],
2752
- );
2635
+ const handleSetSavedBackendEnabled = async (environmentId: EnvironmentId, enabled: boolean) => {
2636
+ setSavedBackendError(null);
2637
+ const result = await setEnvironmentEnabled({ environmentId, enabled });
2638
+ if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
2639
+ const error = squashAtomCommandFailure(result);
2640
+ const message =
2641
+ error instanceof Error
2642
+ ? error.message
2643
+ : `Failed to switch the backend ${enabled ? "on" : "off"}.`;
2644
+ setSavedBackendError(message);
2645
+ toastManager.add(
2646
+ stackedThreadToast({
2647
+ type: "error",
2648
+ title: `Could not switch backend ${enabled ? "on" : "off"}`,
2649
+ description: message,
2650
+ }),
2651
+ );
2652
+ }
2653
+ };
2654
+
2655
+ const removeSavedBackend = async (environment: EnvironmentPresentation) => {
2656
+ const environmentId = environment.environmentId;
2657
+ setRemovingSavedEnvironmentId(environmentId);
2658
+ setSavedBackendError(null);
2659
+ const result = await removeEnvironment(environmentId);
2660
+ setRemovingSavedEnvironmentId(null);
2661
+ if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
2662
+ const error = squashAtomCommandFailure(result);
2663
+ const message = error instanceof Error ? error.message : "Failed to remove backend.";
2664
+ setSavedBackendError(message);
2665
+ toastManager.add(
2666
+ stackedThreadToast({
2667
+ type: "error",
2668
+ title: "Could not remove backend",
2669
+ description: message,
2670
+ }),
2671
+ );
2672
+ }
2673
+ };
2674
2675
// T3 Connect environments get their own dialog: removing one here leaves its
2676
// account registration, so it points to where that can be deregistered.
2677
const [pendingT3ConnectRemoval, setPendingT3ConnectRemoval] =
2678
useState<EnvironmentPresentation | null>(null);
2758
- const handleRemoveSavedBackend = useCallback(
2759
- async (environment: EnvironmentPresentation) => {
2760
- if (environment.relayManaged && hasCloudPublicConfig()) {
2761
- setPendingT3ConnectRemoval(environment);
2762
- return;
2763
- }
2764
- const confirmed = await requestConfirmDialog(
2765
- `Remove ${environment.label} from this device?\nThis forgets its pairing, credentials, and cached threads here. Switch it off instead to keep it saved.`,
2766
- { variant: "destructive" },
2767
- );
2768
- if (confirmed === true) await removeSavedBackend(environment);
2769
- },
2770
- [removeSavedBackend],
2771
- );
2679
+ const handleRemoveSavedBackend = async (environment: EnvironmentPresentation) => {
2680
+ if (environment.relayManaged && hasCloudPublicConfig()) {
2681
+ setPendingT3ConnectRemoval(environment);
2682
+ return;
2683
+ }
2684
+ const confirmed = await requestConfirmDialog(
2685
+ `Remove ${environment.label} from this device?\nThis forgets its pairing, credentials, and cached threads here. Switch it off instead to keep it saved.`,
2686
+ { variant: "destructive" },
2687
+ );
2688
+ if (confirmed === true) await removeSavedBackend(environment);
2689
+ };
2690
2691
const visibleDesktopPairingLinks = desktopPairingLinks;
2774
- const tailscaleHttpsEndpoint = useMemo(
2775
- () => desktopAdvertisedEndpoints.find(isTailscaleHttpsEndpoint) ?? null,
2776
- [desktopAdvertisedEndpoints],
2777
- );
2778
- const visibleDesktopNetworkAdvertisedEndpoints = useMemo(
2779
- () =>
2780
- isLocalBackendNetworkAccessible
2781
- ? desktopAdvertisedEndpoints.filter((endpoint) => !isTailscaleHttpsEndpoint(endpoint))
2782
- : [],
2783
- [desktopAdvertisedEndpoints, isLocalBackendNetworkAccessible],
2784
- );
2785
- const visibleDesktopAdvertisedEndpoints = useMemo(
2786
- () =>
2787
- tailscaleHttpsEndpoint
2788
- ? [...visibleDesktopNetworkAdvertisedEndpoints, tailscaleHttpsEndpoint]
2789
- : visibleDesktopNetworkAdvertisedEndpoints,
2790
- [tailscaleHttpsEndpoint, visibleDesktopNetworkAdvertisedEndpoints],
2791
- );
2792
- const defaultDesktopNetworkAdvertisedEndpoint = useMemo(
2793
- () =>
2794
- selectPairingEndpoint(visibleDesktopNetworkAdvertisedEndpoints, defaultAdvertisedEndpointKey),
2795
- [defaultAdvertisedEndpointKey, visibleDesktopNetworkAdvertisedEndpoints],
2796
- );
2797
- const defaultDesktopAdvertisedEndpoint = useMemo(
2798
- () =>
2799
- defaultDesktopNetworkAdvertisedEndpoint ??
2800
- selectPairingEndpoint(
2801
- tailscaleHttpsEndpoint ? [tailscaleHttpsEndpoint] : [],
2802
- defaultAdvertisedEndpointKey,
2803
- ),
2804
- [defaultAdvertisedEndpointKey, defaultDesktopNetworkAdvertisedEndpoint, tailscaleHttpsEndpoint],
2805
- );
2692
+ const tailscaleHttpsEndpoint = desktopAdvertisedEndpoints.find(isTailscaleHttpsEndpoint) ?? null;
2693
+ const visibleDesktopNetworkAdvertisedEndpoints = isLocalBackendNetworkAccessible
2694
+ ? desktopAdvertisedEndpoints.filter((endpoint) => !isTailscaleHttpsEndpoint(endpoint))
2695
+ : [];
2696
+ const visibleDesktopAdvertisedEndpoints = tailscaleHttpsEndpoint
2697
+ ? [...visibleDesktopNetworkAdvertisedEndpoints, tailscaleHttpsEndpoint]
2698
+ : visibleDesktopNetworkAdvertisedEndpoints;
2699
+ const defaultDesktopNetworkAdvertisedEndpoint = selectPairingEndpoint(
2700
+ visibleDesktopNetworkAdvertisedEndpoints,
2701
+ defaultAdvertisedEndpointKey,
2702
+ );
2703
+ const defaultDesktopAdvertisedEndpoint =
2704
+ defaultDesktopNetworkAdvertisedEndpoint ??
2705
+ selectPairingEndpoint(
2706
+ tailscaleHttpsEndpoint ? [tailscaleHttpsEndpoint] : [],
2707
+ defaultAdvertisedEndpointKey,
2708
+ );
2709
const defaultDesktopAdvertisedEndpointKey = defaultDesktopAdvertisedEndpoint
2710
? endpointDefaultPreferenceKey(defaultDesktopAdvertisedEndpoint)
2711
: null;
2809
- const handleSetDefaultAdvertisedEndpoint = useCallback(
2810
- (endpoint: AdvertisedEndpoint) => {
2811
- setDefaultAdvertisedEndpointKey(endpointDefaultPreferenceKey(endpoint));
2812
- },
2813
- [setDefaultAdvertisedEndpointKey],
2814
- );
2815
- const handleSavedBackendHostChange = useCallback((value: string) => {
2712
+ const handleSetDefaultAdvertisedEndpoint = (endpoint: AdvertisedEndpoint) => {
2713
+ setDefaultAdvertisedEndpointKey(endpointDefaultPreferenceKey(endpoint));
2714
+ };
2715
+ const handleSavedBackendHostChange = (value: string) => {
2716
const parsedPairingUrl = parsePairingUrlFields(value);
2717
if (parsedPairingUrl) {
2718
setSavedBackendHost(parsedPairingUrl.host);
@@ -2820,7 +2720,7 @@ export function ConnectionsSettings() {
2720
return;
2721
}
2722
setSavedBackendHost(value);
2823
- }, []);
2723
+ };
2724
2725
const renderConnectionModeCard = (input: {
2726
readonly mode: "remote" | "ssh";
@@ -3108,111 +3008,98 @@ export function ConnectionsSettings() {
3008
);
3009
})
3010
: null;
3111
- const applyWslSettingChange = useCallback(
3112
- async (apply: () => Promise<DesktopWslState>) => {
3113
- if (
3114
- !desktopBridge ||
3115
- primaryEnvironmentId === null ||
3116
- !readEnvironmentScope(primaryEnvironmentId, AuthEnvironmentMaintainScope)
3117
- )
3118
- return;
3119
- setIsUpdatingWslBackend(true);
3120
- setDesktopWslMutationError(null);
3121
- try {
3122
- await apply();
3123
- refreshDesktopWslState();
3124
- } catch (error) {
3125
- const message = error instanceof Error ? error.message : "Failed to update WSL backend.";
3126
- setDesktopWslMutationError(message);
3127
- toastManager.add(
3128
- stackedThreadToast({
3129
- type: "error",
3130
- title: "Could not change WSL backend",
3131
- description: message,
3132
- }),
3133
- );
3134
- refreshDesktopWslState();
3135
- } finally {
3136
- setIsUpdatingWslBackend(false);
3137
- }
3138
- },
3139
- [desktopBridge, primaryEnvironmentId],
3140
- );
3011
+ const applyWslSettingChange = async (apply: () => Promise<DesktopWslState>) => {
3012
+ if (
3013
+ !desktopBridge ||
3014
+ primaryEnvironmentId === null ||
3015
+ !readEnvironmentScope(primaryEnvironmentId, AuthEnvironmentMaintainScope)
3016
+ )
3017
+ return;
3018
+ setIsUpdatingWslBackend(true);
3019
+ setDesktopWslMutationError(null);
3020
+ const settled = await settlePromise(async () => {
3021
+ await apply();
3022
+ refreshDesktopWslState();
3023
+ });
3024
+ if (settled._tag === "Failure") {
3025
+ const error = Cause.squash(settled.cause);
3026
+ const message = error instanceof Error ? error.message : "Failed to update WSL backend.";
3027
+ setDesktopWslMutationError(message);
3028
+ toastManager.add(
3029
+ stackedThreadToast({
3030
+ type: "error",
3031
+ title: "Could not change WSL backend",
3032
+ description: message,
3033
+ }),
3034
+ );
3035
+ refreshDesktopWslState();
3036
+ }
3037
+ setIsUpdatingWslBackend(false);
3038
+ };
3039
3142
- const loadWslState = useCallback(() => {
3040
+ const loadWslState = () => {
3041
setDesktopWslMutationError(null);
3042
refreshDesktopWslState();
3145
- }, []);
3043
+ };
3044
3147
- const hasWslRegistrationToLose = useMemo(() => {
3148
- return environments.some((environment) =>
3149
- isDesktopLocalConnectionTarget(environment.entry.target),
3150
- );
3151
- }, [environments]);
3152
-
3153
- const handleSelectWslMode = useCallback(
3154
- (value: string) => {
3155
- if (!desktopBridge || !desktopWslState) return;
3156
- const defaultDistroName =
3157
- desktopWslState.distros.find((distro) => distro.isDefault)?.name ?? null;
3158
- if (value === BACKEND_VALUE_WSL_OFF) {
3159
- // Match the recovery row's visibility (`enabled || wslOnly`): when WSL
3160
- // went unavailable while wsl-only was persisted, `enabled` can be false
3161
- // while `wslOnly` is true, and the "Switch to Windows" button must
3162
- // still clear that state instead of silently no-op'ing.
3163
- if (!desktopWslState.enabled && !desktopWslState.wslOnly) return;
3164
- const wasWslOnly = desktopWslState.wslOnly;
3165
- if (hasWslRegistrationToLose || wasWslOnly) {
3166
- setPendingWslChange({ kind: "disable", wasWslOnly });
3167
- return;
3168
- }
3169
- void applyWslSettingChange(() => desktopBridge.setWslBackendEnabled(false));
3170
- return;
3171
- }
3172
- const nextDistro = value === BACKEND_VALUE_DEFAULT_WSL ? null : value;
3173
- const resolvedNext = nextDistro ?? defaultDistroName;
3174
- if (!desktopWslState.enabled) {
3175
- setPendingWslChange({ kind: "enable", nextDistro });
3176
- return;
3177
- }
3178
- const resolvedCurrent = desktopWslState.distro ?? defaultDistroName;
3179
- if (resolvedCurrent === resolvedNext) return;
3180
- if (hasWslRegistrationToLose || desktopWslState.wslOnly) {
3181
- setPendingWslChange({ kind: "distro", nextDistro });
3045
+ const hasWslRegistrationToLose = environments.some((environment) =>
3046
+ isDesktopLocalConnectionTarget(environment.entry.target),
3047
+ );
3048
+
3049
+ const handleSelectWslMode = (value: string) => {
3050
+ if (!desktopBridge || !desktopWslState) return;
3051
+ const defaultDistroName =
3052
+ desktopWslState.distros.find((distro) => distro.isDefault)?.name ?? null;
3053
+ if (value === BACKEND_VALUE_WSL_OFF) {
3054
+ // Match the recovery row's visibility (`enabled || wslOnly`): when WSL
3055
+ // went unavailable while wsl-only was persisted, `enabled` can be false
3056
+ // while `wslOnly` is true, and the "Switch to Windows" button must
3057
+ // still clear that state instead of silently no-op'ing.
3058
+ if (!desktopWslState.enabled && !desktopWslState.wslOnly) return;
3059
+ const wasWslOnly = desktopWslState.wslOnly;
3060
+ if (hasWslRegistrationToLose || wasWslOnly) {
3061
+ setPendingWslChange({ kind: "disable", wasWslOnly });
3062
return;
3063
}
3184
- void applyWslSettingChange(() => desktopBridge.setWslDistro(nextDistro));
3185
- },
3186
- [applyWslSettingChange, desktopBridge, desktopWslState, hasWslRegistrationToLose],
3187
- );
3064
+ void applyWslSettingChange(() => desktopBridge.setWslBackendEnabled(false));
3065
+ return;
3066
+ }
3067
+ const nextDistro = value === BACKEND_VALUE_DEFAULT_WSL ? null : value;
3068
+ const resolvedNext = nextDistro ?? defaultDistroName;
3069
+ if (!desktopWslState.enabled) {
3070
+ setPendingWslChange({ kind: "enable", nextDistro });
3071
+ return;
3072
+ }
3073
+ const resolvedCurrent = desktopWslState.distro ?? defaultDistroName;
3074
+ if (resolvedCurrent === resolvedNext) return;
3075
+ if (hasWslRegistrationToLose || desktopWslState.wslOnly) {
3076
+ setPendingWslChange({ kind: "distro", nextDistro });
3077
+ return;
3078
+ }
3079
+ void applyWslSettingChange(() => desktopBridge.setWslDistro(nextDistro));
3080
+ };
3081
3189
- const handleConfirmEnableWsl = useCallback(
3190
- (mode: "both" | "wsl-only") => {
3191
- if (!desktopBridge || !pendingWslChange || pendingWslChange.kind !== "enable") return;
3192
- const nextDistro = pendingWslChange.nextDistro;
3193
- setPendingWslChange(null);
3194
- const persistedDistro = desktopWslState?.distro ?? null;
3195
- void applyWslSettingChange(() =>
3196
- applyWslEnableSelection({
3197
- bridge: desktopBridge,
3198
- mode,
3199
- nextDistro,
3200
- persistedDistro,
3201
- }),
3202
- );
3203
- },
3204
- [applyWslSettingChange, desktopBridge, desktopWslState, pendingWslChange],
3205
- );
3082
+ const handleConfirmEnableWsl = (mode: "both" | "wsl-only") => {
3083
+ if (!desktopBridge || !pendingWslChange || pendingWslChange.kind !== "enable") return;
3084
+ const nextDistro = pendingWslChange.nextDistro;
3085
+ setPendingWslChange(null);
3086
+ const persistedDistro = desktopWslState?.distro ?? null;
3087
+ void applyWslSettingChange(() =>
3088
+ applyWslEnableSelection({
3089
+ bridge: desktopBridge,
3090
+ mode,
3091
+ nextDistro,
3092
+ persistedDistro,
3093
+ }),
3094
+ );
3095
+ };
3096
3207
- const handleToggleWslOnly = useCallback(
3208
- (enabled: boolean) => {
3209
- if (!desktopBridge || !desktopWslState || desktopWslState.wslOnly === enabled) return;
3210
- setPendingWslChange({ kind: "wsl-only", nextValue: enabled });
3211
- },
3212
- [desktopBridge, desktopWslState],
3213
- );
3097
+ const handleToggleWslOnly = (enabled: boolean) => {
3098
+ if (!desktopBridge || !desktopWslState || desktopWslState.wslOnly === enabled) return;
3099
+ setPendingWslChange({ kind: "wsl-only", nextValue: enabled });
3100
+ };
3101
3215
- const handleConfirmWslChange = useCallback(() => {
3102
+ const handleConfirmWslChange = () => {
3103
if (!desktopBridge || !pendingWslChange) return;
3104
const change = pendingWslChange;
3105
if (change.kind === "enable") return;
@@ -3232,7 +3119,7 @@ export function ConnectionsSettings() {
3119
return;
3120
}
3121
void applyWslSettingChange(() => desktopBridge.setWslOnly(change.nextValue));
3235
- }, [applyWslSettingChange, desktopBridge, pendingWslChange]);
3122
+ };
3123
3124
const renderWslRow = () => {
3125
if (!desktopWslState) {