fix(settings): surface WSL-state load failures with retry; clear stale error

Follow-up to the WSL-state seeding fix, addressing two Cursor Bugbot findings:
- If getWslState() failed on mount, renderWslRow() returned null so the error
  was hidden entirely. Now render an error row with a Retry control when the
  load fails and the user can manage the local backend.
- Extract loadWslState(), which clears any prior error before fetching, so a
  stale failure message cannot linger after a later successful load.
This commit is contained in:
Josh Gratton committed 2026-06-19 17:37:34 -04:00
1 parent a10e576422
commit 72a648a0ec
1 file changed
+40 -19
@@ -2801,33 +2801,35 @@ export function ConnectionsSettings() {
[desktopBridge],
);
// Seed the WSL backend state from the desktop bridge on mount (and when
// local-backend management becomes available). Without this, desktopWslState
// stays null and renderWslRow() bails, hiding the WSL settings UI entirely.
// The broader desktop access-management state is owned by desktopNetworkAccess
// upstream; this effect only owns the WSL picker's state.
useEffect(() => {
if (!canManageLocalBackend || !desktopBridge) {
// Load the WSL backend state from the desktop bridge. Clears any prior error
// up front so a stale failure message can't linger after a later success, and
// is reused by the retry control in renderWslRow.
const loadWslState = useCallback(() => {
if (!desktopBridge) {
return;
}
let cancelled = false;
setDesktopWslError(null);
void desktopBridge
.getWslState()
.then((state) => {
if (!cancelled) {
setDesktopWslState(state);
}
setDesktopWslState(state);
})
.catch((error: unknown) => {
if (cancelled) {
return;
}
setDesktopWslError(error instanceof Error ? error.message : "Failed to load WSL state.");
});
return () => {
cancelled = true;
};
}, [canManageLocalBackend, desktopBridge]);
}, [desktopBridge]);
// Seed the WSL backend state on mount (and when local-backend management
// becomes available). Without this, desktopWslState stays null and
// renderWslRow() bails, hiding the WSL settings UI entirely. The broader
// desktop access-management state is owned by desktopNetworkAccess upstream;
// this only owns the WSL picker's state.
useEffect(() => {
if (!canManageLocalBackend) {
return;
}
loadWslState();
}, [canManageLocalBackend, loadWslState]);
// True when a desktop-local WSL backend is currently registered as an
// environment on this machine. We use this as a proxy for "the user has work
@@ -2957,7 +2959,26 @@ export function ConnectionsSettings() {
}, [applyWslSettingChange, desktopBridge, pendingWslChange]);
const renderWslRow = () => {
if (!desktopWslState) return null;
if (!desktopWslState) {
// The initial getWslState() load failed: surface the error with a retry
// rather than hiding the section silently. With no error we simply haven't
// loaded yet (or WSL management isn't available), so render nothing.
if (desktopWslError && canManageLocalBackend) {
return (
<SettingsRow
title="WSL backend"
description="Couldn't load the WSL backend state."
status={<span className="block text-destructive">{desktopWslError}</span>}
control={
<Button size="xs" variant="outline" onClick={loadWslState}>
Retry
</Button>
}
/>
);
}
return null;
}
// WSL went unavailable while the user still has the WSL backend persisted
// (it may have been uninstalled or its distro removed). The desktop side
// falls back to the Windows backend, but the normal distro picker needs a