Skip to content
TypeScript

fix(web): make WSL settings searchable (#8881)

Utkarsh Patilc50b0b4ef8d6
diff --git a/apps/web/src/components/settings/ConnectionsSettings.logic.test.ts b/apps/web/src/components/settings/ConnectionsSettings.logic.test.ts
index 290e2daa12b..74283796a8e 100644
--- a/apps/web/src/components/settings/ConnectionsSettings.logic.test.ts
+++ b/apps/web/src/components/settings/ConnectionsSettings.logic.test.ts
@@ -3,6 +3,7 @@ import { describe, expect, it, vi } from "vite-plus/test";
import {
applyWslEnableSelection,
isQrShareableEndpoint,
+ isWslSettingsRowVisible,
selectQrEndpointOption,
} from "./ConnectionsSettings.logic";
@@ -15,6 +16,25 @@ const baseWslState: DesktopWslState = {
preflightError: null,
};
+describe("isWslSettingsRowVisible", () => {
+ it("shows the retry row when the WSL state failed to load", () => {
+ expect(isWslSettingsRowVisible({ state: null, error: "load failed" })).toBe(true);
+ });
+
+ it("hides an unavailable and unused WSL snapshot", () => {
+ expect(
+ isWslSettingsRowVisible({
+ state: { ...baseWslState, available: false, wslOnly: false },
+ error: null,
+ }),
+ ).toBe(false);
+ });
+
+ it("shows an available WSL snapshot", () => {
+ expect(isWslSettingsRowVisible({ state: baseWslState, error: null })).toBe(true);
+ });
+});
+
describe("applyWslEnableSelection", () => {
it("clears WSL-only and updates the distro before enabling both backends", async () => {
const calls: Array<string> = [];
diff --git a/apps/web/src/components/settings/ConnectionsSettings.logic.ts b/apps/web/src/components/settings/ConnectionsSettings.logic.ts
index faa0cb6c754..d683efab3a4 100644
--- a/apps/web/src/components/settings/ConnectionsSettings.logic.ts
+++ b/apps/web/src/components/settings/ConnectionsSettings.logic.ts
@@ -11,6 +11,14 @@ export function isQrShareableEndpoint(endpoint: AdvertisedEndpoint): boolean {
return endpoint.status !== "unavailable" && endpoint.reachability !== "loopback";
}
+export function isWslSettingsRowVisible(input: {
+ readonly state: DesktopWslState | null;
+ readonly error: string | null;
+}): boolean {
+ const { state, error } = input;
+ return state ? state.available || state.enabled || state.wslOnly : error !== null;
+}
+
export type QrEndpointOption = {
/** Unique per endpoint instance (AdvertisedEndpoint.id); safe as a React key. */
readonly id: string;
diff --git a/apps/web/src/components/settings/ConnectionsSettings.tsx b/apps/web/src/components/settings/ConnectionsSettings.tsx
index 18d1b0f1c92..6a65856b9b9 100644
--- a/apps/web/src/components/settings/ConnectionsSettings.tsx
+++ b/apps/web/src/components/settings/ConnectionsSettings.tsx
@@ -43,6 +43,7 @@ import { resolveDesktopPairingUrl, resolveHostedPairingUrl } from "./pairingUrls
import {
applyWslEnableSelection,
isQrShareableEndpoint,
+ isWslSettingsRowVisible,
selectQrEndpointOption,
} from "./ConnectionsSettings.logic";
import {
@@ -2766,10 +2767,13 @@ export function ConnectionsSettings() {
// retry so the row doesn't flicker away, and the button reflects the
// loading state. With no error we simply haven't loaded yet (or WSL
// management isn't available), so render nothing.
- if (desktopWslError && canManageLocalBackend) {
+ if (
+ isWslSettingsRowVisible({ state: null, error: desktopWslError }) &&
+ canManageLocalBackend
+ ) {
return (
<SettingsRow
- title="WSL backend"
+ {...searchableSetting("wsl-backend")}
description="Couldn't load the WSL backend state."
status={<span className="block text-destructive">{desktopWslError}</span>}
control={
@@ -2794,11 +2798,13 @@ export function ConnectionsSettings() {
// be stranded on a WSL preference they can't clear, so render a recovery
// row that switches back to Windows. When WSL is unavailable AND unused,
// there's nothing to recover — keep the section hidden as before.
+ if (!isWslSettingsRowVisible({ state: desktopWslState, error: desktopWslError })) {
+ return null;
+ }
if (!desktopWslState.available) {
- if (!desktopWslState.enabled && !desktopWslState.wslOnly) return null;
return (
<SettingsRow
- title="WSL backend"
+ {...searchableSetting("wsl-backend")}
description="WSL is no longer available, so the Windows backend is running instead. Switch off the WSL backend to clear this preference."
status={
desktopWslError ? (
@@ -2835,7 +2841,7 @@ export function ConnectionsSettings() {
return (
<>
<SettingsRow
- title="WSL backend"
+ {...searchableSetting("wsl-backend")}
description="Run a second backend inside a WSL distro alongside the Windows one. Pick a distro to start it; pick Off to stop it. Projects opened against the WSL backend live on the Linux side; Windows projects stay where they are."
status={
desktopWslError ? (
diff --git a/apps/web/src/components/settings/SettingsSidebarNav.tsx b/apps/web/src/components/settings/SettingsSidebarNav.tsx
index 734c2989d91..d336bde5ee1 100644
--- a/apps/web/src/components/settings/SettingsSidebarNav.tsx
+++ b/apps/web/src/components/settings/SettingsSidebarNav.tsx
@@ -7,6 +7,8 @@ import {
type ComponentType,
type KeyboardEvent,
} from "react";
+import { useEnvironmentQuery } from "~/state/query";
+import { desktopWslStateAtom } from "~/state/desktopWslState";
import {
ArchiveIcon,
BlocksIcon,
@@ -21,6 +23,8 @@ import {
} from "lucide-react";
import { useLocation, useNavigate } from "@tanstack/react-router";
+import { isElectron } from "~/env";
+import { isWslSettingsRowVisible } from "./ConnectionsSettings.logic";
import { Button } from "../ui/button";
import { Input } from "../ui/input";
import { Kbd } from "../ui/kbd";
@@ -38,6 +42,7 @@ import { SidebarUtilityMenu } from "../sidebar/SidebarChrome";
import { scrollToSettingsTarget } from "./settingsLayout";
import {
searchSettings,
+ SETTINGS_SEARCH_ITEMS,
SETTINGS_SECTION_LABELS,
type SettingsPath,
type SettingsSearchItem,
@@ -78,10 +83,26 @@ export function SettingsSidebarNav({ pathname }: { pathname: string }) {
const searchInputRef = useRef<HTMLInputElement>(null);
const [query, setQuery] = useState("");
const [activeResultIndex, setActiveResultIndex] = useState(0);
- const results = useMemo(() => searchSettings(query), [query]);
+ const desktopWsl = useEnvironmentQuery(isElectron ? desktopWslStateAtom : null);
+ const searchableItems = useMemo(() => {
+ const wslState = desktopWsl.data;
+ const rowRenders = isWslSettingsRowVisible({
+ state: wslState,
+ error: desktopWsl.error,
+ });
+ if (rowRenders) {
+ return SETTINGS_SEARCH_ITEMS;
+ }
+ return SETTINGS_SEARCH_ITEMS.filter((item) => item.id !== "wsl-backend");
+ }, [desktopWsl.data, desktopWsl.error]);
+ const results = useMemo(() => searchSettings(query, searchableItems), [query, searchableItems]);
const isSearching = query.trim().length > 0;
const hasResults = results.length > 0;
+ useEffect(() => {
+ setActiveResultIndex((index) => Math.min(index, Math.max(results.length - 1, 0)));
+ }, [results.length]);
+
useEffect(() => {
const result = results[activeResultIndex];
if (!result) return;
diff --git a/apps/web/src/components/settings/settingsSearch.test.ts b/apps/web/src/components/settings/settingsSearch.test.ts
index c560d0b43d9..5bf4b4f704d 100644
--- a/apps/web/src/components/settings/settingsSearch.test.ts
+++ b/apps/web/src/components/settings/settingsSearch.test.ts
@@ -71,6 +71,17 @@ describe("searchSettings", () => {
it("hides desktop-only settings from browser search", () => {
expect(SETTINGS_SEARCH_ITEMS.some((item) => item.id === "quit-confirmation")).toBe(true);
expect(searchSettings("quit confirmation")).toEqual([]);
+ expect(searchSettings("wsl")).toEqual([]);
+ });
+
+ it("registers the WSL backend as a desktop-only setting", () => {
+ expect(SETTINGS_SEARCH_ITEMS).toContainEqual({
+ id: "wsl-backend",
+ title: "WSL backend",
+ to: "/settings/connections",
+ desktopOnly: true,
+ windowsOnly: true,
+ });
});
it("keeps catalog result ids unique", () => {
diff --git a/apps/web/src/components/settings/settingsSearch.ts b/apps/web/src/components/settings/settingsSearch.ts
index 1e0d715f68b..d5384d1e508 100644
--- a/apps/web/src/components/settings/settingsSearch.ts
+++ b/apps/web/src/components/settings/settingsSearch.ts
@@ -1,4 +1,5 @@
import { isElectron } from "~/env";
+import { isWindowsPlatform } from "~/lib/utils";
export type SettingsPath =
| "/settings/general"
@@ -18,6 +19,9 @@ export interface SettingsSearchItem {
// Its row only renders in the desktop app, so a browser result would land on
// an anchor that isn't there.
readonly desktopOnly?: boolean;
+ // Its row only renders on Windows desktop, so other desktop platforms must
+ // not expose a result that points to a missing anchor.
+ readonly windowsOnly?: boolean;
}
/**
@@ -259,6 +263,13 @@ export const SETTINGS_SEARCH_ITEMS = [
title: "Remote environments",
to: "/settings/connections",
},
+ {
+ id: "wsl-backend",
+ title: "WSL backend",
+ to: "/settings/connections",
+ desktopOnly: true,
+ windowsOnly: true,
+ },
{
id: "archive",
title: "Archived threads",
@@ -304,6 +315,8 @@ export function searchSettings(
return items.filter(
(item) =>
(isElectron || item.desktopOnly !== true) &&
+ (!item.windowsOnly ||
+ isWindowsPlatform(typeof navigator === "undefined" ? "" : navigator.platform)) &&
normalizeSearchText(item.title).includes(normalizedQuery),
);
}