Skip to content
TypeScript

perf(web): connections settings compile with the React Compiler (#20515)

Julius Marminge6a326afb81c6
diff --git a/apps/web/reactCompiledFiles.ts b/apps/web/reactCompiledFiles.ts
index 4625f8c6a6a..2e0355c1839 100644
--- a/apps/web/reactCompiledFiles.ts
+++ b/apps/web/reactCompiledFiles.ts
@@ -90,4 +90,5 @@ export const REACT_COMPILED_FILES = [
"apps/web/src/components/settings/IntegrationsSettings.tsx",
"apps/web/src/components/settings/ThemeImportDialog.tsx",
"apps/web/src/components/settings/SnapShotSettings.tsx",
+ "apps/web/src/components/settings/ConnectionsSettings.tsx",
] as const;
diff --git a/apps/web/src/components/settings/ConnectionsSettings.tsx b/apps/web/src/components/settings/ConnectionsSettings.tsx
index 29429e37af8..bb7fa4ada23 100644
--- a/apps/web/src/components/settings/ConnectionsSettings.tsx
+++ b/apps/web/src/components/settings/ConnectionsSettings.tsx
@@ -15,10 +15,8 @@ import {
type KeyboardEvent,
type ReactNode,
memo,
- useCallback,
useEffect,
useId,
- useMemo,
useRef,
useState,
} from "react";
@@ -55,8 +53,10 @@ import {
} from "@t3tools/client-runtime/connection";
import {
isAtomCommandInterrupted,
+ settlePromise,
squashAtomCommandFailure,
} from "@t3tools/client-runtime/state/runtime";
+import * as Cause from "effect/Cause";
import * as DateTime from "effect/DateTime";
import * as Option from "effect/Option";
@@ -574,33 +574,24 @@ const PairingLinkListRow = memo(function PairingLinkListRow({
canRevoke,
}: PairingLinkListRowProps) {
const nowMs = useRelativeTimeTick(1_000);
- const expiresAtMs = useMemo(
- () => new Date(pairingLink.expiresAt).getTime(),
- [pairingLink.expiresAt],
- );
+ const expiresAtMs = new Date(pairingLink.expiresAt).getTime();
const [isRevealDialogOpen, setIsRevealDialogOpen] = useState(false);
const [isQrPanelOpen, setIsQrPanelOpen] = useState(false);
const [qrEndpointId, setQrEndpointId] = useState<string | null>(null);
const qrPanelId = useId();
- const currentOriginPairingUrl = useMemo(
- () => (credential ? resolveCurrentOriginPairingUrl(credential) : null),
- [credential],
- );
- const hostedPairingUrl = useMemo(
- () =>
- credential && endpointUrl != null && endpointUrl !== ""
- ? resolveHostedPairingUrl(endpointUrl, credential)
- : null,
- [endpointUrl, credential],
- );
- const endpointPairingUrl = useMemo(() => {
+ const currentOriginPairingUrl = credential ? resolveCurrentOriginPairingUrl(credential) : null;
+ const hostedPairingUrl =
+ credential && endpointUrl != null && endpointUrl !== ""
+ ? resolveHostedPairingUrl(endpointUrl, credential)
+ : null;
+ const endpointPairingUrl = (() => {
const endpoint = selectPairingEndpoint(endpoints, defaultEndpointKey);
return endpoint && credential
? resolveAdvertisedEndpointPairingUrl(endpoint, credential)
: null;
- }, [defaultEndpointKey, endpoints, credential]);
- const endpointCopyOptions = useMemo(() => {
+ })();
+ const endpointCopyOptions = (() => {
const options: Array<{
readonly id: string;
readonly preferenceKey: string;
@@ -625,7 +616,7 @@ const PairingLinkListRow = memo(function PairingLinkListRow({
});
}
return options;
- }, [endpoints, credential]);
+ })();
const shareablePairingUrl =
endpointPairingUrl ??
(credential && endpointUrl != null && endpointUrl !== ""
@@ -686,21 +677,16 @@ const PairingLinkListRow = memo(function PairingLinkListRow({
},
});
- const copyPairingValue = useCallback(
- (value: string, kind: "code" | "hosted-link" | "link") => {
- copyToClipboard(value, { value, kind });
- },
- [copyToClipboard],
- );
+ const copyPairingValue = (value: string, kind: "code" | "hosted-link" | "link") => {
+ copyToClipboard(value, { value, kind });
+ };
- const copyKindForUrl = useCallback(
- (url: string): "hosted-link" | "link" => (isHostedAppPairingUrl(url) ? "hosted-link" : "link"),
- [],
- );
+ const copyKindForUrl = (url: string): "hosted-link" | "link" =>
+ isHostedAppPairingUrl(url) ? "hosted-link" : "link";
- const handleCopyCode = useCallback(() => {
+ const handleCopyCode = () => {
if (credential) copyPairingValue(credential, "code");
- }, [copyPairingValue, credential]);
+ };
const expiresAbsolute = formatAccessTimestamp(pairingLink.expiresAt);
@@ -1036,7 +1022,7 @@ const AuthorizedClientsHeaderAction = memo(function AuthorizedClientsHeaderActio
const selectedScopes = pairingScopes.filter((scope) => delegatableScopes.includes(scope));
const [isCreatingPairingLink, setIsCreatingPairingLink] = useState(false);
- const handleCreatePairingLink = useCallback(async () => {
+ const handleCreatePairingLink = async () => {
if (
primaryEnvironmentId === null ||
selectedScopes.length === 0 ||
@@ -1045,7 +1031,7 @@ const AuthorizedClientsHeaderAction = memo(function AuthorizedClientsHeaderActio
)
return;
setIsCreatingPairingLink(true);
- try {
+ const settled = await settlePromise(async () => {
const created = await createServerPairingCredential({
label: pairingLabel,
scopes: selectedScopes,
@@ -1056,7 +1042,9 @@ const AuthorizedClientsHeaderAction = memo(function AuthorizedClientsHeaderActio
AuthStandardClientScopes.filter((scope) => delegatableScopes.includes(scope)),
);
setDialogOpen(false);
- } catch (error) {
+ });
+ if (settled._tag === "Failure") {
+ const error = Cause.squash(settled.cause);
const message = error instanceof Error ? error.message : "Failed to create pairing URL.";
toastManager.add(
stackedThreadToast({
@@ -1065,14 +1053,13 @@ const AuthorizedClientsHeaderAction = memo(function AuthorizedClientsHeaderActio
description: message,
}),
);
- } finally {
- setIsCreatingPairingLink(false);
}
- }, [delegatableScopes, onPairingLinkCreated, pairingLabel, primaryEnvironmentId, selectedScopes]);
+ setIsCreatingPairingLink(false);
+ };
- const togglePairingScope = useCallback((scope: AuthGrantScope, checked: boolean) => {
+ const togglePairingScope = (scope: AuthGrantScope, checked: boolean) => {
setPairingScopes((current) => togglePairingScopeSelection(current, scope, checked));
- }, []);
+ };
return (
<div className="flex items-center gap-2">
@@ -1498,12 +1485,9 @@ function SavedBackendListRow({
);
},
});
- const copyTraceId = useCallback(
- (traceId: string) => {
- copyTraceIdToClipboard(traceId, { traceId });
- },
- [copyTraceIdToClipboard],
- );
+ const copyTraceId = (traceId: string) => {
+ copyTraceIdToClipboard(traceId, { traceId });
+ };
const { copyToClipboard: copyMcpUrl } = useCopyToClipboard<{ url: string }>({
target: "MCP URL",
onCopy: ({ url }) => {
@@ -2035,72 +2019,55 @@ export function ConnectionsSettings() {
? (primarySessionState.data.permissions ?? primarySessionState.data.scopes ?? null)
: null;
const currentAuthPolicy = desktopBridge ? null : (primarySessionState.data?.auth.policy ?? null);
- const savedEnvironments = useMemo(
- () =>
- environments.filter(
- (environment) => environment.entry.target._tag !== "PrimaryConnectionTarget",
- ),
- [environments],
+ const savedEnvironments = environments.filter(
+ (environment) => environment.entry.target._tag !== "PrimaryConnectionTarget",
);
- const listedEnvironments = useMemo(
- () =>
- savedEnvironments.filter(
- (environment) => !isDesktopLocalConnectionTarget(environment.entry.target),
- ),
- [savedEnvironments],
+ const listedEnvironments = savedEnvironments.filter(
+ (environment) => !isDesktopLocalConnectionTarget(environment.entry.target),
);
- const savedServerUpdateStatesAtom = useMemo(
- () =>
- Atom.make((get) =>
- savedEnvironments.map((environment) => ({
- environment,
- updateStatus: get(serverEnvironment.updateStateAtom(environment.environmentId)).status,
- })),
- ),
- [savedEnvironments],
+ const savedServerUpdateStatesAtom = Atom.make((get) =>
+ savedEnvironments.map((environment) => ({
+ environment,
+ updateStatus: get(serverEnvironment.updateStateAtom(environment.environmentId)).status,
+ })),
);
const savedServerUpdateStates = useAtomValue(savedServerUpdateStatesAtom);
- const savedServerUpdateTargets = useMemo(
- () =>
- savedServerUpdateStates.flatMap(({ environment, updateStatus }): ServerUpdateTarget[] => {
- const mismatch = resolveServerConfigVersionMismatch(environment.serverConfig);
- const selfUpdate = resolveServerSelfUpdateCapability(environment.serverConfig);
- const desktopAppUpdate = supportsDesktopAppUpdate(environment.serverConfig);
- if (
- !mismatch ||
- updateStatus === "running" ||
- !environment.entry.enabled ||
- environment.connection.phase !== "connected" ||
- isDesktopLocalConnectionTarget(environment.entry.target) ||
- selfUpdate === null ||
- (selfUpdate === "desktop-managed" && !desktopAppUpdate)
- ) {
- return [];
- }
- return [
- {
- environmentId: environment.environmentId,
- serverLabel: environment.label,
- selfUpdate,
- installation: environment.serverConfig?.environment.capabilities.serverInstallation,
- desktopAppUpdate,
- threadContinuation: supportsServerUpdateThreadContinuation(environment.serverConfig),
- continueThreadsAfterServerUpdate:
- environment.serverConfig?.settings.continueThreadsAfterServerUpdate ?? false,
- targetVersion: mismatch.clientVersion,
- },
- ];
- }),
- [savedServerUpdateStates],
- );
- const loadBalancingEnvironments = useMemo(
- () => [
- ...(primaryEnvironment ? [primaryEnvironment] : []),
- ...savedEnvironments.filter((environment) => environment.entry.enabled),
- ],
- [primaryEnvironment, savedEnvironments],
+ const savedServerUpdateTargets = savedServerUpdateStates.flatMap(
+ ({ environment, updateStatus }): ServerUpdateTarget[] => {
+ const mismatch = resolveServerConfigVersionMismatch(environment.serverConfig);
+ const selfUpdate = resolveServerSelfUpdateCapability(environment.serverConfig);
+ const desktopAppUpdate = supportsDesktopAppUpdate(environment.serverConfig);
+ if (
+ !mismatch ||
+ updateStatus === "running" ||
+ !environment.entry.enabled ||
+ environment.connection.phase !== "connected" ||
+ isDesktopLocalConnectionTarget(environment.entry.target) ||
+ selfUpdate === null ||
+ (selfUpdate === "desktop-managed" && !desktopAppUpdate)
+ ) {
+ return [];
+ }
+ return [
+ {
+ environmentId: environment.environmentId,
+ serverLabel: environment.label,
+ selfUpdate,
+ installation: environment.serverConfig?.environment.capabilities.serverInstallation,
+ desktopAppUpdate,
+ threadContinuation: supportsServerUpdateThreadContinuation(environment.serverConfig),
+ continueThreadsAfterServerUpdate:
+ environment.serverConfig?.settings.continueThreadsAfterServerUpdate ?? false,
+ targetVersion: mismatch.clientVersion,
+ },
+ ];
+ },
);
- const savedDesktopSshEnvironmentKeys = useMemo(() => {
+ const loadBalancingEnvironments = [
+ ...(primaryEnvironment ? [primaryEnvironment] : []),
+ ...savedEnvironments.filter((environment) => environment.entry.enabled),
+ ];
+ const savedDesktopSshEnvironmentKeys = (() => {
const keys = new Set<string>();
for (const environment of savedEnvironments) {
const profile = environment.entry.profile;
@@ -2116,7 +2083,7 @@ export function ConnectionsSettings() {
keys.add(formatDesktopSshTarget(target));
}
return keys;
- }, [savedEnvironments]);
+ })();
const [desktopServerExposureMutationError, setDesktopServerExposureMutationError] = useState<
string | null
>(null);
@@ -2126,9 +2093,9 @@ export function ConnectionsSettings() {
const [createdPairingCredentials, setCreatedPairingCredentials] = useState<
ReadonlyMap<string, string>
>(() => new Map());
- const handlePairingLinkCreated = useCallback((created: AuthPairingCredentialResult) => {
+ const handlePairingLinkCreated = (created: AuthPairingCredentialResult) => {
setCreatedPairingCredentials((current) => new Map(current).set(created.id, created.credential));
- }, []);
+ };
const [revokingDesktopPairingLinkId, setRevokingDesktopPairingLinkId] = useState<string | null>(
null,
);
@@ -2218,20 +2185,16 @@ export function ConnectionsSettings() {
const desktopWslError = desktopWslMutationError ?? desktopWsl.error;
const isLoadingWslState = desktopWsl.isPending && desktopWsl.data === null;
const discoveredSshHosts = desktopSshHosts.data ?? EMPTY_DISCOVERED_SSH_HOSTS;
- const unsavedDiscoveredSshHosts = useMemo(
- () =>
- discoveredSshHosts.filter((target) => {
- const address = formatDesktopSshTarget(target);
- return (
- !savedDesktopSshEnvironmentKeys.has(target.alias) &&
- !savedDesktopSshEnvironmentKeys.has(address)
- );
- }),
- [discoveredSshHosts, savedDesktopSshEnvironmentKeys],
- );
- const filteredDiscoveredSshHosts = useMemo(
- () => filterDiscoveredSshHosts(unsavedDiscoveredSshHosts, savedBackendSshHost),
- [savedBackendSshHost, unsavedDiscoveredSshHosts],
+ const unsavedDiscoveredSshHosts = discoveredSshHosts.filter((target) => {
+ const address = formatDesktopSshTarget(target);
+ return (
+ !savedDesktopSshEnvironmentKeys.has(target.alias) &&
+ !savedDesktopSshEnvironmentKeys.has(address)
+ );
+ });
+ const filteredDiscoveredSshHosts = filterDiscoveredSshHosts(
+ unsavedDiscoveredSshHosts,
+ savedBackendSshHost,
);
const isLoadingDiscoveredSshHosts = desktopSshHosts.isPending && desktopSshHosts.data === null;
const discoveredSshHostsError = desktopSshHosts.error;
@@ -2247,7 +2210,7 @@ export function ConnectionsSettings() {
desktopAccessManagementMutationError ?? authAccessChanges.error;
const isLoadingDesktopAccessManagement =
authAccessChanges.isPending && authAccessChanges.data === null;
- const desktopPairingLinks = useMemo(() => {
+ const desktopPairingLinks = (() => {
const event = authAccessChanges.data;
if (event?.type !== "snapshot") return [];
return sortDesktopPairingLinks(
@@ -2255,8 +2218,8 @@ export function ConnectionsSettings() {
toDesktopPairingLinkRecord(pairingLink),
),
);
- }, [authAccessChanges.data]);
- const desktopClientSessions = useMemo(() => {
+ })();
+ const desktopClientSessions = (() => {
const event = authAccessChanges.data;
if (event?.type !== "snapshot") return [];
return sortDesktopClientSessions(
@@ -2264,7 +2227,7 @@ export function ConnectionsSettings() {
toDesktopClientSessionRecord(clientSession),
),
);
- }, [authAccessChanges.data]);
+ })();
const isLocalBackendNetworkAccessible = desktopBridge
? desktopServerExposureState?.mode === "network-accessible"
: currentAuthPolicy === "remote-reachable";
@@ -2276,7 +2239,7 @@ export function ConnectionsSettings() {
parsedTailscaleServePort >= 1 &&
parsedTailscaleServePort <= 65_535;
- const pendingTailscaleServeBaseUrl = useMemo(() => {
+ const pendingTailscaleServeBaseUrl = (() => {
if (!pendingTailscaleServeEndpoint) return null;
if (!isTailscaleServePortValid) return pendingTailscaleServeEndpoint.httpBaseUrl;
if (parsedTailscaleServePort === DEFAULT_TAILSCALE_SERVE_PORT) {
@@ -2289,48 +2252,44 @@ export function ConnectionsSettings() {
} catch {
return pendingTailscaleServeEndpoint.httpBaseUrl;
}
- }, [isTailscaleServePortValid, parsedTailscaleServePort, pendingTailscaleServeEndpoint]);
+ })();
- const handleDesktopServerExposureChange = useCallback(
- async (checked: boolean) => {
- if (
- !desktopBridge ||
- primaryEnvironmentId === null ||
- !readEnvironmentScope(primaryEnvironmentId, AuthEnvironmentMaintainScope)
- )
- return;
- setIsUpdatingDesktopServerExposure(true);
- setDesktopServerExposureMutationError(null);
- try {
- await desktopBridge.setServerExposureMode(checked ? "network-accessible" : "local-only");
- refreshDesktopNetworkAccessState();
- setIsDesktopServerExposureDialogOpen(false);
- setIsUpdatingDesktopServerExposure(false);
- } catch (error) {
- const message =
- error instanceof Error ? error.message : "Failed to update network exposure.";
- setIsDesktopServerExposureDialogOpen(false);
- setDesktopServerExposureMutationError(message);
- toastManager.add(
- stackedThreadToast({
- type: "error",
- title: "Could not update network access",
- description: message,
- }),
- );
- setIsUpdatingDesktopServerExposure(false);
- }
- },
- [desktopBridge, primaryEnvironmentId],
- );
+ const handleDesktopServerExposureChange = async (checked: boolean) => {
+ if (
+ !desktopBridge ||
+ primaryEnvironmentId === null ||
+ !readEnvironmentScope(primaryEnvironmentId, AuthEnvironmentMaintainScope)
+ )
+ return;
+ setIsUpdatingDesktopServerExposure(true);
+ setDesktopServerExposureMutationError(null);
+ try {
+ await desktopBridge.setServerExposureMode(checked ? "network-accessible" : "local-only");
+ refreshDesktopNetworkAccessState();
+ setIsDesktopServerExposureDialogOpen(false);
+ setIsUpdatingDesktopServerExposure(false);
+ } catch (error) {
+ const message = error instanceof Error ? error.message : "Failed to update network exposure.";
+ setIsDesktopServerExposureDialogOpen(false);
+ setDesktopServerExposureMutationError(message);
+ toastManager.add(
+ stackedThreadToast({
+ type: "error",
+ title: "Could not update network access",
+ description: message,
+ }),
+ );
+ setIsUpdatingDesktopServerExposure(false);
+ }
+ };
- const handleConfirmDesktopServerExposureChange = useCallback(() => {
+ const handleConfirmDesktopServerExposureChange = () => {
if (pendingDesktopServerExposureMode === null) return;
const checked = pendingDesktopServerExposureMode === "network-accessible";
void handleDesktopServerExposureChange(checked);
- }, [handleDesktopServerExposureChange, pendingDesktopServerExposureMode]);
+ };
- const handleConfirmTailscaleServeSetup = useCallback(async () => {
+ const handleConfirmTailscaleServeSetup = async () => {
if (
!desktopBridge ||
primaryEnvironmentId === null ||
@@ -2340,14 +2299,16 @@ export function ConnectionsSettings() {
if (!isTailscaleServePortValid) return;
setIsUpdatingTailscaleServe(true);
setDesktopServerExposureMutationError(null);
- try {
+ const settled = await settlePromise(async () => {
await desktopBridge.setTailscaleServeEnabled({
enabled: true,
port: parsedTailscaleServePort,
});
refreshDesktopNetworkAccessState();
setPendingTailscaleServeEndpoint(null);
- } catch (error) {
+ });
+ if (settled._tag === "Failure") {
+ const error = Cause.squash(settled.cause);
const message =
error instanceof Error ? error.message : "Failed to configure Tailscale HTTPS.";
setDesktopServerExposureMutationError(message);
@@ -2358,22 +2319,18 @@ export function ConnectionsSettings() {
description: message,
}),
);
- } finally {
- setIsUpdatingTailscaleServe(false);
}
- }, [desktopBridge, isTailscaleServePortValid, parsedTailscaleServePort, primaryEnvironmentId]);
+ setIsUpdatingTailscaleServe(false);
+ };
- const handleStartTailscaleServeSetup = useCallback(
- (endpoint: AdvertisedEndpoint) => {
- setTailscaleServePortInput(
- String(desktopServerExposureState?.tailscaleServePort ?? DEFAULT_TAILSCALE_SERVE_PORT),
- );
- setPendingTailscaleServeEndpoint(endpoint);
- },
- [desktopServerExposureState?.tailscaleServePort],
- );
+ const handleStartTailscaleServeSetup = (endpoint: AdvertisedEndpoint) => {
+ setTailscaleServePortInput(
+ String(desktopServerExposureState?.tailscaleServePort ?? DEFAULT_TAILSCALE_SERVE_PORT),
+ );
+ setPendingTailscaleServeEndpoint(endpoint);
+ };
- const handleConfirmTailscaleServeDisable = useCallback(async () => {
+ const handleConfirmTailscaleServeDisable = async () => {
if (
!desktopBridge ||
primaryEnvironmentId === null ||
@@ -2382,14 +2339,16 @@ export function ConnectionsSettings() {
return;
setIsUpdatingTailscaleServe(true);
setDesktopServerExposureMutationError(null);
- try {
+ const settled = await settlePromise(async () => {
await desktopBridge.setTailscaleServeEnabled({
enabled: false,
port: desktopServerExposureState?.tailscaleServePort ?? DEFAULT_TAILSCALE_SERVE_PORT,
});
refreshDesktopNetworkAccessState();
setDisableTailscaleServeDialogOpen(false);
- } catch (error) {
+ });
+ if (settled._tag === "Failure") {
+ const error = Cause.squash(settled.cause);
const message = error instanceof Error ? error.message : "Failed to disable Tailscale HTTPS.";
setDesktopServerExposureMutationError(message);
toastManager.add(
@@ -2399,72 +2358,69 @@ export function ConnectionsSettings() {
description: message,
}),
);
- } finally {
- setIsUpdatingTailscaleServe(false);
}
- }, [desktopBridge, desktopServerExposureState, primaryEnvironmentId]);
+ setIsUpdatingTailscaleServe(false);
+ };
- const handleStartTailscaleServeDisable = useCallback((_endpoint: AdvertisedEndpoint) => {
+ const handleStartTailscaleServeDisable = (_endpoint: AdvertisedEndpoint) => {
setDisableTailscaleServeDialogOpen(true);
- }, []);
+ };
- const handleRevokeDesktopPairingLink = useCallback(
- async (id: string) => {
- if (
- primaryEnvironmentId === null ||
- !readEnvironmentScope(primaryEnvironmentId, AuthAccessWriteScope)
- )
- return;
- setRevokingDesktopPairingLinkId(id);
- setDesktopAccessManagementMutationError(null);
- try {
- await revokeServerPairingLink(id);
- } catch (error) {
- const message = error instanceof Error ? error.message : "Failed to revoke pairing link.";
- setDesktopAccessManagementMutationError(message);
- toastManager.add(
- stackedThreadToast({
- type: "error",
- title: "Could not revoke pairing link",
- description: message,
- }),
- );
- } finally {
- setRevokingDesktopPairingLinkId(null);
- }
- },
- [primaryEnvironmentId],
- );
+ const handleRevokeDesktopPairingLink = async (id: string) => {
+ if (
+ primaryEnvironmentId === null ||
+ !readEnvironmentScope(primaryEnvironmentId, AuthAccessWriteScope)
+ )
+ return;
+ setRevokingDesktopPairingLinkId(id);
+ setDesktopAccessManagementMutationError(null);
+ const settled = await settlePromise(async () => {
+ await revokeServerPairingLink(id);
+ });
+ if (settled._tag === "Failure") {
+ const error = Cause.squash(settled.cause);
+ const message = error instanceof Error ? error.message : "Failed to revoke pairing link.";
+ setDesktopAccessManagementMutationError(message);
+ toastManager.add(
+ stackedThreadToast({
+ type: "error",
+ title: "Could not revoke pairing link",
+ description: message,
+ }),
+ );
+ }
+ setRevokingDesktopPairingLinkId(null);
+ };
- const handleRevokeDesktopClientSession = useCallback(
- async (sessionId: ServerClientSessionRecord["sessionId"]) => {
- if (
- primaryEnvironmentId === null ||
- !readEnvironmentScope(primaryEnvironmentId, AuthAccessWriteScope)
- )
- return;
- setRevokingDesktopClientSessionId(sessionId);
- setDesktopAccessManagementMutationError(null);
- try {
- await revokeServerClientSession(sessionId);
- } catch (error) {
- const message = error instanceof Error ? error.message : "Failed to revoke client access.";
- setDesktopAccessManagementMutationError(message);
- toastManager.add(
- stackedThreadToast({
- type: "error",
- title: "Could not revoke client access",
- description: message,
- }),
- );
- } finally {
- setRevokingDesktopClientSessionId(null);
- }
- },
- [primaryEnvironmentId],
- );
+ const handleRevokeDesktopClientSession = async (
+ sessionId: ServerClientSessionRecord["sessionId"],
+ ) => {
+ if (
+ primaryEnvironmentId === null ||
+ !readEnvironmentScope(primaryEnvironmentId, AuthAccessWriteScope)
+ )
+ return;
+ setRevokingDesktopClientSessionId(sessionId);
+ setDesktopAccessManagementMutationError(null);
+ const settled = await settlePromise(async () => {
+ await revokeServerClientSession(sessionId);
+ });
+ if (settled._tag === "Failure") {
+ const error = Cause.squash(settled.cause);
+ const message = error instanceof Error ? error.message : "Failed to revoke client access.";
+ setDesktopAccessManagementMutationError(message);
+ toastManager.add(
+ stackedThreadToast({
+ type: "error",
+ title: "Could not revoke client access",
+ description: message,
+ }),
+ );
+ }
+ setRevokingDesktopClientSessionId(null);
+ };
- const handleRevokeOtherDesktopClients = useCallback(async () => {
+ const handleRevokeOtherDesktopClients = async () => {
if (
primaryEnvironmentId === null ||
!readEnvironmentScope(primaryEnvironmentId, AuthAccessWriteScope)
@@ -2472,14 +2428,16 @@ export function ConnectionsSettings() {
return;
setIsRevokingOtherDesktopClients(true);
setDesktopAccessManagementMutationError(null);
- try {
+ const settled = await settlePromise(async () => {
const revokedCount = await revokeOtherServerClientSessions();
toastManager.add({
type: "success",
title: revokedCount === 1 ? "Revoked 1 other client" : `Revoked ${revokedCount} clients`,
description: "Other paired clients will need a new pairing link before reconnecting.",
});
- } catch (error) {
+ });
+ if (settled._tag === "Failure") {
+ const error = Cause.squash(settled.cause);
const message = error instanceof Error ? error.message : "Failed to revoke other clients.";
setDesktopAccessManagementMutationError(message);
toastManager.add(
@@ -2489,47 +2447,43 @@ export function ConnectionsSettings() {
description: message,
}),
);
- } finally {
- setIsRevokingOtherDesktopClients(false);
}
- }, [primaryEnvironmentId]);
-
- const connectSavedBackendSshTarget = useCallback(
- async (target: DesktopSshEnvironmentTarget) => {
- setIsAddingSavedBackend(true);
- setSavedBackendError(null);
- const result = await connectSshEnvironment({
- target,
- label: "",
- ...(routeTarget ? { expectedEnvironmentId: routeTarget.environmentId } : {}),
- });
- if (result._tag === "Failure") {
- if (!isAtomCommandInterrupted(result)) {
- setSavedBackendError(formatDesktopSshConnectionError(squashAtomCommandFailure(result)));
- }
- setIsAddingSavedBackend(false);
- return;
- }
+ setIsRevokingOtherDesktopClients(false);
+ };
- setSavedBackendHost("");
- setSavedBackendPairingCode("");
- setSavedBackendSshHost("");
- setSavedBackendSshUsername("");
- setSavedBackendSshPort("");
- setAddBackendDialogOpen(false);
- toastManager.add({
- type: "success",
- title: routeTarget ? "Route added" : "Environment connected",
- description: routeTarget
- ? `${routeTarget.label} can now be reached over SSH ${target.alias}.`
- : `${target.alias} is ready over an SSH-managed tunnel.`,
- });
+ const connectSavedBackendSshTarget = async (target: DesktopSshEnvironmentTarget) => {
+ setIsAddingSavedBackend(true);
+ setSavedBackendError(null);
+ const result = await connectSshEnvironment({
+ target,
+ label: "",
+ ...(routeTarget ? { expectedEnvironmentId: routeTarget.environmentId } : {}),
+ });
+ if (result._tag === "Failure") {
+ if (!isAtomCommandInterrupted(result)) {
+ setSavedBackendError(formatDesktopSshConnectionError(squashAtomCommandFailure(result)));
+ }
setIsAddingSavedBackend(false);
- },
- [connectSshEnvironment, routeTarget],
- );
+ return;
+ }
+
+ setSavedBackendHost("");
+ setSavedBackendPairingCode("");
+ setSavedBackendSshHost("");
+ setSavedBackendSshUsername("");
+ setSavedBackendSshPort("");
+ setAddBackendDialogOpen(false);
+ toastManager.add({
+ type: "success",
+ title: routeTarget ? "Route added" : "Environment connected",
+ description: routeTarget
+ ? `${routeTarget.label} can now be reached over SSH ${target.alias}.`
+ : `${target.alias} is ready over an SSH-managed tunnel.`,
+ });
+ setIsAddingSavedBackend(false);
+ };
- const handleAddSavedBackend = useCallback(async () => {
+ const handleAddSavedBackend = async () => {
if (savedBackendMode === "ssh") {
let target: DesktopSshEnvironmentTarget;
try {
@@ -2610,209 +2564,155 @@ export function ConnectionsSettings() {
},
);
setIsAddingSavedBackend(false);
- }, [
- routeTarget,
- connectPairing,
- connectSavedBackendSshTarget,
- savedBackendHost,
- savedBackendMode,
- savedBackendPairingCode,
- savedBackendSshHost,
- savedBackendSshPort,
- savedBackendSshUsername,
- ]);
+ };
- const handleSavedBackendSshFieldKeyDown = useCallback(
- (event: KeyboardEvent<HTMLInputElement>) => {
- if (event.nativeEvent.isComposing || event.keyCode === 229) return;
- if (event.key === "Enter" && savedBackendSshHost.trim().length > 0) {
- event.preventDefault();
- void handleAddSavedBackend();
- }
- },
- [handleAddSavedBackend, savedBackendSshHost],
- );
+ const handleSavedBackendSshFieldKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
+ if (event.nativeEvent.isComposing || event.keyCode === 229) return;
+ if (event.key === "Enter" && savedBackendSshHost.trim().length > 0) {
+ event.preventDefault();
+ void handleAddSavedBackend();
+ }
+ };
- const handleSelectSshHostSuggestion = useCallback(
- async (target: DesktopDiscoveredSshHost) => {
- if (isAddingSavedBackend || !desktopBridge) return;
+ const handleSelectSshHostSuggestion = async (target: DesktopDiscoveredSshHost) => {
+ if (isAddingSavedBackend || !desktopBridge) return;
- setIsAddingSavedBackend(true);
- setSavedBackendError(null);
- setSavedBackendSshHost(target.alias);
- let resolved: DesktopSshEnvironmentTarget;
- try {
- resolved = await desktopBridge.resolveSshHost(target.alias);
- } catch (error) {
- setSavedBackendError(formatDesktopSshConnectionError(error));
- setIsAddingSavedBackend(false);
- return;
- }
- setSavedBackendSshUsername(resolved.username ?? "");
- setSavedBackendSshPort(resolved.port === null ? "" : String(resolved.port));
- await connectSavedBackendSshTarget(resolved);
- },
- [connectSavedBackendSshTarget, desktopBridge, isAddingSavedBackend],
- );
-
- const handleSavedBackendSshHostKeyDown = useCallback(
- (event: KeyboardEvent<HTMLInputElement>) => {
- if (event.nativeEvent.isComposing || event.keyCode === 229) return;
+ setIsAddingSavedBackend(true);
+ setSavedBackendError(null);
+ setSavedBackendSshHost(target.alias);
+ let resolved: DesktopSshEnvironmentTarget;
+ try {
+ resolved = await desktopBridge.resolveSshHost(target.alias);
+ } catch (error) {
+ setSavedBackendError(formatDesktopSshConnectionError(error));
+ setIsAddingSavedBackend(false);
+ return;
+ }
+ setSavedBackendSshUsername(resolved.username ?? "");
+ setSavedBackendSshPort(resolved.port === null ? "" : String(resolved.port));
+ await connectSavedBackendSshTarget(resolved);
+ };
- const isSshHostPopupVisible = sshHostSuggestionsOpen && hasSshHostSuggestionContent;
- if (isSshHostPopupVisible) {
- const command = resolveShortcutCommand(event, keybindings, {
- platform: navigator.platform,
- context: { modelPickerOpen: false },
- });
- const index = threadJumpIndexFromCommand(command ?? "");
- const target = index === null ? undefined : filteredDiscoveredSshHosts[index];
- if (target) {
- event.preventDefault();
- event.stopPropagation();
- setSshHostSuggestionsOpen(false);
- void handleSelectSshHostSuggestion(target);
- return;
- }
+ const handleSavedBackendSshHostKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
+ if (event.nativeEvent.isComposing || event.keyCode === 229) return;
- if (event.key === "Escape") {
- event.preventDefault();
- event.stopPropagation();
- return;
- }
+ const isSshHostPopupVisible = sshHostSuggestionsOpen && hasSshHostSuggestionContent;
+ if (isSshHostPopupVisible) {
+ const command = resolveShortcutCommand(event, keybindings, {
+ platform: navigator.platform,
+ context: { modelPickerOpen: false },
+ });
+ const index = threadJumpIndexFromCommand(command ?? "");
+ const target = index === null ? undefined : filteredDiscoveredSshHosts[index];
+ if (target) {
+ event.preventDefault();
+ event.stopPropagation();
+ setSshHostSuggestionsOpen(false);
+ void handleSelectSshHostSuggestion(target);
+ return;
}
- const hasHighlightedSshHost =
- isSshHostPopupVisible && highlightedSshHostRef.current !== undefined;
- if (
- !event.defaultPrevented &&
- !hasHighlightedSshHost &&
- event.key === "Enter" &&
- savedBackendSshHost.trim().length > 0
- ) {
+ if (event.key === "Escape") {
event.preventDefault();
- void handleAddSavedBackend();
+ event.stopPropagation();
+ return;
}
- },
- [
- filteredDiscoveredSshHosts,
- handleAddSavedBackend,
- handleSelectSshHostSuggestion,
- hasSshHostSuggestionContent,
- keybindings,
- savedBackendSshHost,
- sshHostSuggestionsOpen,
- ],
- );
+ }
- const handleSetSavedBackendEnabled = useCallback(
- async (environmentId: EnvironmentId, enabled: boolean) => {
- setSavedBackendError(null);
- const result = await setEnvironmentEnabled({ environmentId, enabled });
- if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
- const error = squashAtomCommandFailure(result);
- const message =
- error instanceof Error
- ? error.message
- : `Failed to switch the backend ${enabled ? "on" : "off"}.`;
- setSavedBackendError(message);
- toastManager.add(
- stackedThreadToast({
- type: "error",
- title: `Could not switch backend ${enabled ? "on" : "off"}`,
- description: message,
- }),
- );
- }
- },
- [setEnvironmentEnabled],
- );
+ const hasHighlightedSshHost =
+ isSshHostPopupVisible && highlightedSshHostRef.current !== undefined;
+ if (
+ !event.defaultPrevented &&
+ !hasHighlightedSshHost &&
+ event.key === "Enter" &&
+ savedBackendSshHost.trim().length > 0
+ ) {
+ event.preventDefault();
+ void handleAddSavedBackend();
+ }
+ };
- const removeSavedBackend = useCallback(
- async (environment: EnvironmentPresentation) => {
- const environmentId = environment.environmentId;
- setRemovingSavedEnvironmentId(environmentId);
- setSavedBackendError(null);
- const result = await removeEnvironment(environmentId);
- setRemovingSavedEnvironmentId(null);
- if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
- const error = squashAtomCommandFailure(result);
- const message = error instanceof Error ? error.message : "Failed to remove backend.";
- setSavedBackendError(message);
- toastManager.add(
- stackedThreadToast({
- type: "error",
- title: "Could not remove backend",
- description: message,
- }),
- );
- }
- },
- [removeEnvironment],
- );
+ const handleSetSavedBackendEnabled = async (environmentId: EnvironmentId, enabled: boolean) => {
+ setSavedBackendError(null);
+ const result = await setEnvironmentEnabled({ environmentId, enabled });
+ if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
+ const error = squashAtomCommandFailure(result);
+ const message =
+ error instanceof Error
+ ? error.message
+ : `Failed to switch the backend ${enabled ? "on" : "off"}.`;
+ setSavedBackendError(message);
+ toastManager.add(
+ stackedThreadToast({
+ type: "error",
+ title: `Could not switch backend ${enabled ? "on" : "off"}`,
+ description: message,
+ }),
+ );
+ }
+ };
+
+ const removeSavedBackend = async (environment: EnvironmentPresentation) => {
+ const environmentId = environment.environmentId;
+ setRemovingSavedEnvironmentId(environmentId);
+ setSavedBackendError(null);
+ const result = await removeEnvironment(environmentId);
+ setRemovingSavedEnvironmentId(null);
+ if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
+ const error = squashAtomCommandFailure(result);
+ const message = error instanceof Error ? error.message : "Failed to remove backend.";
+ setSavedBackendError(message);
+ toastManager.add(
+ stackedThreadToast({
+ type: "error",
+ title: "Could not remove backend",
+ description: message,
+ }),
+ );
+ }
+ };
// T3 Connect environments get their own dialog: removing one here leaves its
// account registration, so it points to where that can be deregistered.
const [pendingT3ConnectRemoval, setPendingT3ConnectRemoval] =
useState<EnvironmentPresentation | null>(null);
- const handleRemoveSavedBackend = useCallback(
- async (environment: EnvironmentPresentation) => {
- if (environment.relayManaged && hasCloudPublicConfig()) {
- setPendingT3ConnectRemoval(environment);
- return;
- }
- const confirmed = await requestConfirmDialog(
- `Remove ${environment.label} from this device?\nThis forgets its pairing, credentials, and cached threads here. Switch it off instead to keep it saved.`,
- { variant: "destructive" },
- );
- if (confirmed === true) await removeSavedBackend(environment);
- },
- [removeSavedBackend],
- );
+ const handleRemoveSavedBackend = async (environment: EnvironmentPresentation) => {
+ if (environment.relayManaged && hasCloudPublicConfig()) {
+ setPendingT3ConnectRemoval(environment);
+ return;
+ }
+ const confirmed = await requestConfirmDialog(
+ `Remove ${environment.label} from this device?\nThis forgets its pairing, credentials, and cached threads here. Switch it off instead to keep it saved.`,
+ { variant: "destructive" },
+ );
+ if (confirmed === true) await removeSavedBackend(environment);
+ };
const visibleDesktopPairingLinks = desktopPairingLinks;
- const tailscaleHttpsEndpoint = useMemo(
- () => desktopAdvertisedEndpoints.find(isTailscaleHttpsEndpoint) ?? null,
- [desktopAdvertisedEndpoints],
- );
- const visibleDesktopNetworkAdvertisedEndpoints = useMemo(
- () =>
- isLocalBackendNetworkAccessible
- ? desktopAdvertisedEndpoints.filter((endpoint) => !isTailscaleHttpsEndpoint(endpoint))
- : [],
- [desktopAdvertisedEndpoints, isLocalBackendNetworkAccessible],
- );
- const visibleDesktopAdvertisedEndpoints = useMemo(
- () =>
- tailscaleHttpsEndpoint
- ? [...visibleDesktopNetworkAdvertisedEndpoints, tailscaleHttpsEndpoint]
- : visibleDesktopNetworkAdvertisedEndpoints,
- [tailscaleHttpsEndpoint, visibleDesktopNetworkAdvertisedEndpoints],
- );
- const defaultDesktopNetworkAdvertisedEndpoint = useMemo(
- () =>
- selectPairingEndpoint(visibleDesktopNetworkAdvertisedEndpoints, defaultAdvertisedEndpointKey),
- [defaultAdvertisedEndpointKey, visibleDesktopNetworkAdvertisedEndpoints],
- );
- const defaultDesktopAdvertisedEndpoint = useMemo(
- () =>
- defaultDesktopNetworkAdvertisedEndpoint ??
- selectPairingEndpoint(
- tailscaleHttpsEndpoint ? [tailscaleHttpsEndpoint] : [],
- defaultAdvertisedEndpointKey,
- ),
- [defaultAdvertisedEndpointKey, defaultDesktopNetworkAdvertisedEndpoint, tailscaleHttpsEndpoint],
- );
+ const tailscaleHttpsEndpoint = desktopAdvertisedEndpoints.find(isTailscaleHttpsEndpoint) ?? null;
+ const visibleDesktopNetworkAdvertisedEndpoints = isLocalBackendNetworkAccessible
+ ? desktopAdvertisedEndpoints.filter((endpoint) => !isTailscaleHttpsEndpoint(endpoint))
+ : [];
+ const visibleDesktopAdvertisedEndpoints = tailscaleHttpsEndpoint
+ ? [...visibleDesktopNetworkAdvertisedEndpoints, tailscaleHttpsEndpoint]
+ : visibleDesktopNetworkAdvertisedEndpoints;
+ const defaultDesktopNetworkAdvertisedEndpoint = selectPairingEndpoint(
+ visibleDesktopNetworkAdvertisedEndpoints,
+ defaultAdvertisedEndpointKey,
+ );
+ const defaultDesktopAdvertisedEndpoint =
+ defaultDesktopNetworkAdvertisedEndpoint ??
+ selectPairingEndpoint(
+ tailscaleHttpsEndpoint ? [tailscaleHttpsEndpoint] : [],
+ defaultAdvertisedEndpointKey,
+ );
const defaultDesktopAdvertisedEndpointKey = defaultDesktopAdvertisedEndpoint
? endpointDefaultPreferenceKey(defaultDesktopAdvertisedEndpoint)
: null;
- const handleSetDefaultAdvertisedEndpoint = useCallback(
- (endpoint: AdvertisedEndpoint) => {
- setDefaultAdvertisedEndpointKey(endpointDefaultPreferenceKey(endpoint));
- },
- [setDefaultAdvertisedEndpointKey],
- );
- const handleSavedBackendHostChange = useCallback((value: string) => {
+ const handleSetDefaultAdvertisedEndpoint = (endpoint: AdvertisedEndpoint) => {
+ setDefaultAdvertisedEndpointKey(endpointDefaultPreferenceKey(endpoint));
+ };
+ const handleSavedBackendHostChange = (value: string) => {
const parsedPairingUrl = parsePairingUrlFields(value);
if (parsedPairingUrl) {
setSavedBackendHost(parsedPairingUrl.host);
@@ -2820,7 +2720,7 @@ export function ConnectionsSettings() {
return;
}
setSavedBackendHost(value);
- }, []);
+ };
const renderConnectionModeCard = (input: {
readonly mode: "remote" | "ssh";
@@ -3108,111 +3008,98 @@ export function ConnectionsSettings() {
);
})
: null;
- const applyWslSettingChange = useCallback(
- async (apply: () => Promise<DesktopWslState>) => {
- if (
- !desktopBridge ||
- primaryEnvironmentId === null ||
- !readEnvironmentScope(primaryEnvironmentId, AuthEnvironmentMaintainScope)
- )
- return;
- setIsUpdatingWslBackend(true);
- setDesktopWslMutationError(null);
- try {
- await apply();
- refreshDesktopWslState();
- } catch (error) {
- const message = error instanceof Error ? error.message : "Failed to update WSL backend.";
- setDesktopWslMutationError(message);
- toastManager.add(
- stackedThreadToast({
- type: "error",
- title: "Could not change WSL backend",
- description: message,
- }),
- );
- refreshDesktopWslState();
- } finally {
- setIsUpdatingWslBackend(false);
- }
- },
- [desktopBridge, primaryEnvironmentId],
- );
+ const applyWslSettingChange = async (apply: () => Promise<DesktopWslState>) => {
+ if (
+ !desktopBridge ||
+ primaryEnvironmentId === null ||
+ !readEnvironmentScope(primaryEnvironmentId, AuthEnvironmentMaintainScope)
+ )
+ return;
+ setIsUpdatingWslBackend(true);
+ setDesktopWslMutationError(null);
+ const settled = await settlePromise(async () => {
+ await apply();
+ refreshDesktopWslState();
+ });
+ if (settled._tag === "Failure") {
+ const error = Cause.squash(settled.cause);
+ const message = error instanceof Error ? error.message : "Failed to update WSL backend.";
+ setDesktopWslMutationError(message);
+ toastManager.add(
+ stackedThreadToast({
+ type: "error",
+ title: "Could not change WSL backend",
+ description: message,
+ }),
+ );
+ refreshDesktopWslState();
+ }
+ setIsUpdatingWslBackend(false);
+ };
- const loadWslState = useCallback(() => {
+ const loadWslState = () => {
setDesktopWslMutationError(null);
refreshDesktopWslState();
- }, []);
+ };
- const hasWslRegistrationToLose = useMemo(() => {
- return environments.some((environment) =>
- isDesktopLocalConnectionTarget(environment.entry.target),
- );
- }, [environments]);
-
- const handleSelectWslMode = useCallback(
- (value: string) => {
- if (!desktopBridge || !desktopWslState) return;
- const defaultDistroName =
- desktopWslState.distros.find((distro) => distro.isDefault)?.name ?? null;
- if (value === BACKEND_VALUE_WSL_OFF) {
- // Match the recovery row's visibility (`enabled || wslOnly`): when WSL
- // went unavailable while wsl-only was persisted, `enabled` can be false
- // while `wslOnly` is true, and the "Switch to Windows" button must
- // still clear that state instead of silently no-op'ing.
- if (!desktopWslState.enabled && !desktopWslState.wslOnly) return;
- const wasWslOnly = desktopWslState.wslOnly;
- if (hasWslRegistrationToLose || wasWslOnly) {
- setPendingWslChange({ kind: "disable", wasWslOnly });
- return;
- }
- void applyWslSettingChange(() => desktopBridge.setWslBackendEnabled(false));
- return;
- }
- const nextDistro = value === BACKEND_VALUE_DEFAULT_WSL ? null : value;
- const resolvedNext = nextDistro ?? defaultDistroName;
- if (!desktopWslState.enabled) {
- setPendingWslChange({ kind: "enable", nextDistro });
- return;
- }
- const resolvedCurrent = desktopWslState.distro ?? defaultDistroName;
- if (resolvedCurrent === resolvedNext) return;
- if (hasWslRegistrationToLose || desktopWslState.wslOnly) {
- setPendingWslChange({ kind: "distro", nextDistro });
+ const hasWslRegistrationToLose = environments.some((environment) =>
+ isDesktopLocalConnectionTarget(environment.entry.target),
+ );
+
+ const handleSelectWslMode = (value: string) => {
+ if (!desktopBridge || !desktopWslState) return;
+ const defaultDistroName =
+ desktopWslState.distros.find((distro) => distro.isDefault)?.name ?? null;
+ if (value === BACKEND_VALUE_WSL_OFF) {
+ // Match the recovery row's visibility (`enabled || wslOnly`): when WSL
+ // went unavailable while wsl-only was persisted, `enabled` can be false
+ // while `wslOnly` is true, and the "Switch to Windows" button must
+ // still clear that state instead of silently no-op'ing.
+ if (!desktopWslState.enabled && !desktopWslState.wslOnly) return;
+ const wasWslOnly = desktopWslState.wslOnly;
+ if (hasWslRegistrationToLose || wasWslOnly) {
+ setPendingWslChange({ kind: "disable", wasWslOnly });
return;
}
- void applyWslSettingChange(() => desktopBridge.setWslDistro(nextDistro));
- },
- [applyWslSettingChange, desktopBridge, desktopWslState, hasWslRegistrationToLose],
- );
+ void applyWslSettingChange(() => desktopBridge.setWslBackendEnabled(false));
+ return;
+ }
+ const nextDistro = value === BACKEND_VALUE_DEFAULT_WSL ? null : value;
+ const resolvedNext = nextDistro ?? defaultDistroName;
+ if (!desktopWslState.enabled) {
+ setPendingWslChange({ kind: "enable", nextDistro });
+ return;
+ }
+ const resolvedCurrent = desktopWslState.distro ?? defaultDistroName;
+ if (resolvedCurrent === resolvedNext) return;
+ if (hasWslRegistrationToLose || desktopWslState.wslOnly) {
+ setPendingWslChange({ kind: "distro", nextDistro });
+ return;
+ }
+ void applyWslSettingChange(() => desktopBridge.setWslDistro(nextDistro));
+ };
- const handleConfirmEnableWsl = useCallback(
- (mode: "both" | "wsl-only") => {
- if (!desktopBridge || !pendingWslChange || pendingWslChange.kind !== "enable") return;
- const nextDistro = pendingWslChange.nextDistro;
- setPendingWslChange(null);
- const persistedDistro = desktopWslState?.distro ?? null;
- void applyWslSettingChange(() =>
- applyWslEnableSelection({
- bridge: desktopBridge,
- mode,
- nextDistro,
- persistedDistro,
- }),
- );
- },
- [applyWslSettingChange, desktopBridge, desktopWslState, pendingWslChange],
- );
+ const handleConfirmEnableWsl = (mode: "both" | "wsl-only") => {
+ if (!desktopBridge || !pendingWslChange || pendingWslChange.kind !== "enable") return;
+ const nextDistro = pendingWslChange.nextDistro;
+ setPendingWslChange(null);
+ const persistedDistro = desktopWslState?.distro ?? null;
+ void applyWslSettingChange(() =>
+ applyWslEnableSelection({
+ bridge: desktopBridge,
+ mode,
+ nextDistro,
+ persistedDistro,
+ }),
+ );
+ };
- const handleToggleWslOnly = useCallback(
- (enabled: boolean) => {
- if (!desktopBridge || !desktopWslState || desktopWslState.wslOnly === enabled) return;
- setPendingWslChange({ kind: "wsl-only", nextValue: enabled });
- },
- [desktopBridge, desktopWslState],
- );
+ const handleToggleWslOnly = (enabled: boolean) => {
+ if (!desktopBridge || !desktopWslState || desktopWslState.wslOnly === enabled) return;
+ setPendingWslChange({ kind: "wsl-only", nextValue: enabled });
+ };
- const handleConfirmWslChange = useCallback(() => {
+ const handleConfirmWslChange = () => {
if (!desktopBridge || !pendingWslChange) return;
const change = pendingWslChange;
if (change.kind === "enable") return;
@@ -3232,7 +3119,7 @@ export function ConnectionsSettings() {
return;
}
void applyWslSettingChange(() => desktopBridge.setWslOnly(change.nextValue));
- }, [applyWslSettingChange, desktopBridge, pendingWslChange]);
+ };
const renderWslRow = () => {
if (!desktopWslState) {