From 0209d166199e53cdd2bbf0cd4f4b0c35ed0c7cd9 Mon Sep 17 00:00:00 2001 From: UtkarshUsername Date: Mon, 31 Aug 2026 18:17:47 +0530 Subject: [PATCH 1/9] fix(web):-make-WSL-settings-searchable --- apps/web/src/components/settings/ConnectionsSettings.tsx | 6 +++--- apps/web/src/components/settings/settingsSearch.test.ts | 8 ++++++++ apps/web/src/components/settings/settingsSearch.ts | 6 ++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/apps/web/src/components/settings/ConnectionsSettings.tsx b/apps/web/src/components/settings/ConnectionsSettings.tsx index 784a227d..b1fae806 100644 --- a/apps/web/src/components/settings/ConnectionsSettings.tsx +++ b/apps/web/src/components/settings/ConnectionsSettings.tsx @@ -2750,7 +2750,7 @@ export function ConnectionsSettings() { if (desktopWslError && canManageLocalBackend) { return ( {desktopWslError}} control={ @@ -2779,7 +2779,7 @@ export function ConnectionsSettings() { if (!desktopWslState.enabled && !desktopWslState.wslOnly) return null; return ( { expect(searchSettings(" ", ITEMS)).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, + }); + }); it("keeps catalog result ids unique", () => { const ids = SETTINGS_SEARCH_ITEMS.map((item) => item.id); expect(new Set(ids).size).toBe(ids.length); diff --git a/apps/web/src/components/settings/settingsSearch.ts b/apps/web/src/components/settings/settingsSearch.ts index f6377341..32e2de57 100644 --- a/apps/web/src/components/settings/settingsSearch.ts +++ b/apps/web/src/components/settings/settingsSearch.ts @@ -167,6 +167,12 @@ export const SETTINGS_SEARCH_ITEMS = [ to: "/settings/beta", targetId: "sidebar-v2", }, + { + id: "wsl-backend", + title: "WSL backend", + to: "/settings/connections", + desktopOnly: true, + }, { id: "archive", title: "Archived threads", From 12c7c56d381c20c49b0f77e6a6b47163611339a5 Mon Sep 17 00:00:00 2001 From: UtkarshUsername Date: Mon, 31 Aug 2026 18:23:32 +0530 Subject: [PATCH 2/9] fix(web):windows-only-WSL-settings-search --- .../components/settings/settingsSearch.test.ts | 1 + .../src/components/settings/settingsSearch.ts | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/apps/web/src/components/settings/settingsSearch.test.ts b/apps/web/src/components/settings/settingsSearch.test.ts index 8897ab97..aafd30ac 100644 --- a/apps/web/src/components/settings/settingsSearch.test.ts +++ b/apps/web/src/components/settings/settingsSearch.test.ts @@ -65,6 +65,7 @@ describe("searchSettings", () => { 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 32e2de57..0fb0dc71 100644 --- a/apps/web/src/components/settings/settingsSearch.ts +++ b/apps/web/src/components/settings/settingsSearch.ts @@ -1,3 +1,5 @@ +import { isElectron } from "~/env"; +import { isWindowsPlatform } from "~/lib/utils"; export type SettingsPath = | "/settings/general" | "/settings/appearance" @@ -13,6 +15,12 @@ export interface SettingsSearchItem { readonly title: string; readonly to: SettingsPath; readonly targetId?: string; + // 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; } /** @@ -172,6 +180,7 @@ export const SETTINGS_SEARCH_ITEMS = [ title: "WSL backend", to: "/settings/connections", desktopOnly: true, + windowsOnly: true, }, { id: "archive", @@ -215,5 +224,11 @@ export function searchSettings( const normalizedQuery = normalizeSearchText(query); if (normalizedQuery.length === 0) return []; - return items.filter((item) => normalizeSearchText(item.title).includes(normalizedQuery)); + return items.filter( + (item) => + (isElectron || item.desktopOnly !== true) && + (!item.windowsOnly || + isWindowsPlatform(typeof navigator === "undefined" ? "" : navigator.platform)) && + normalizeSearchText(item.title).includes(normalizedQuery), + ); } From 44f10c304c972c7f40d40061fd99e2998b4abd80 Mon Sep 17 00:00:00 2001 From: UtkarshUsername Date: Mon, 31 Aug 2026 18:35:53 +0530 Subject: [PATCH 3/9] fix(web):hide-unavailable-WSL-search-result --- .../src/components/settings/SettingsSidebarNav.tsx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/apps/web/src/components/settings/SettingsSidebarNav.tsx b/apps/web/src/components/settings/SettingsSidebarNav.tsx index b7ca9afc..91c40c05 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, ArrowLeftIcon, @@ -22,6 +24,7 @@ import { } from "lucide-react"; import { useCanGoBack, useLocation, useNavigate } from "@tanstack/react-router"; +import { isElectron } from "~/env"; import { Button } from "../ui/button"; import { Input } from "../ui/input"; import { Kbd } from "../ui/kbd"; @@ -38,6 +41,7 @@ import { T3ConnectSidebarAvatar, T3ConnectSidebarSignIn } from "../clerk/T3Conne import { scrollToSettingsTarget } from "./settingsLayout"; import { searchSettings, + SETTINGS_SEARCH_ITEMS, SETTINGS_SECTION_LABELS, type SettingsPath, type SettingsSearchItem, @@ -79,7 +83,15 @@ export function SettingsSidebarNav({ pathname }: { pathname: string }) { const searchInputRef = useRef(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; + if (wslState?.available || wslState?.enabled || wslState?.wslOnly) { + return SETTINGS_SEARCH_ITEMS; + } + return SETTINGS_SEARCH_ITEMS.filter((item) => item.id !== "wsl-backend"); + }, [desktopWsl.data]); + const results = useMemo(() => searchSettings(query, searchableItems), [query, searchableItems]); const isSearching = query.trim().length > 0; const hasResults = results.length > 0; From d59e7911d99727814e4df10db305019921d415b2 Mon Sep 17 00:00:00 2001 From: UtkarshUsername Date: Mon, 31 Aug 2026 18:43:02 +0530 Subject: [PATCH 4/9] fix(web):show-WSL-search-on-load-error --- apps/web/src/components/settings/SettingsSidebarNav.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/web/src/components/settings/SettingsSidebarNav.tsx b/apps/web/src/components/settings/SettingsSidebarNav.tsx index 91c40c05..f8ef484c 100644 --- a/apps/web/src/components/settings/SettingsSidebarNav.tsx +++ b/apps/web/src/components/settings/SettingsSidebarNav.tsx @@ -86,7 +86,12 @@ export function SettingsSidebarNav({ pathname }: { pathname: string }) { const desktopWsl = useEnvironmentQuery(isElectron ? desktopWslStateAtom : null); const searchableItems = useMemo(() => { const wslState = desktopWsl.data; - if (wslState?.available || wslState?.enabled || wslState?.wslOnly) { + if ( + wslState?.available || + wslState?.enabled || + wslState?.wslOnly || + desktopWsl.error !== null + ) { return SETTINGS_SEARCH_ITEMS; } return SETTINGS_SEARCH_ITEMS.filter((item) => item.id !== "wsl-backend"); From 47998f6044ccd4028630b0be20222aef74ae3246 Mon Sep 17 00:00:00 2001 From: UtkarshUsername Date: Mon, 31 Aug 2026 18:47:13 +0530 Subject: [PATCH 5/9] fix(web):refresh-WSL-search-on-load-error --- apps/web/src/components/settings/SettingsSidebarNav.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/web/src/components/settings/SettingsSidebarNav.tsx b/apps/web/src/components/settings/SettingsSidebarNav.tsx index f8ef484c..cd61fde0 100644 --- a/apps/web/src/components/settings/SettingsSidebarNav.tsx +++ b/apps/web/src/components/settings/SettingsSidebarNav.tsx @@ -95,7 +95,7 @@ export function SettingsSidebarNav({ pathname }: { pathname: string }) { return SETTINGS_SEARCH_ITEMS; } return SETTINGS_SEARCH_ITEMS.filter((item) => item.id !== "wsl-backend"); - }, [desktopWsl.data]); + }, [desktopWsl.data, desktopWsl.error]); const results = useMemo(() => searchSettings(query, searchableItems), [query, searchableItems]); const isSearching = query.trim().length > 0; const hasResults = results.length > 0; From b812c87dcaf468ea8b963dfa07060cdac938a5e3 Mon Sep 17 00:00:00 2001 From: UtkarshUsername Date: Mon, 31 Aug 2026 19:01:54 +0530 Subject: [PATCH 6/9] fix(web):avoid-stale-WSL-search-target --- .../src/components/settings/SettingsSidebarNav.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/web/src/components/settings/SettingsSidebarNav.tsx b/apps/web/src/components/settings/SettingsSidebarNav.tsx index cd61fde0..7e8c1135 100644 --- a/apps/web/src/components/settings/SettingsSidebarNav.tsx +++ b/apps/web/src/components/settings/SettingsSidebarNav.tsx @@ -86,12 +86,12 @@ export function SettingsSidebarNav({ pathname }: { pathname: string }) { const desktopWsl = useEnvironmentQuery(isElectron ? desktopWslStateAtom : null); const searchableItems = useMemo(() => { const wslState = desktopWsl.data; - if ( - wslState?.available || - wslState?.enabled || - wslState?.wslOnly || - desktopWsl.error !== null - ) { + // Mirror renderWslRow: the retry row renders only without a snapshot, + // while a stale snapshot plus a failed refresh follows the snapshot path. + const rowRenders = wslState + ? wslState.available || wslState.enabled || wslState.wslOnly + : desktopWsl.error !== null; + if (rowRenders) { return SETTINGS_SEARCH_ITEMS; } return SETTINGS_SEARCH_ITEMS.filter((item) => item.id !== "wsl-backend"); From 1419c14b781c89809876b1c88236f1ecb1a52b5d Mon Sep 17 00:00:00 2001 From: UtkarshUsername Date: Mon, 31 Aug 2026 19:13:04 +0530 Subject: [PATCH 7/9] fix(web):share-WSL-row-visibility-rule --- .../ConnectionsSettings.logic.test.ts | 26 +++++++++- .../settings/ConnectionsSettings.logic.ts | 51 +++++++++++++++++++ .../settings/ConnectionsSettings.tsx | 16 ++++-- .../settings/SettingsSidebarNav.tsx | 10 ++-- 4 files changed, 94 insertions(+), 9 deletions(-) diff --git a/apps/web/src/components/settings/ConnectionsSettings.logic.test.ts b/apps/web/src/components/settings/ConnectionsSettings.logic.test.ts index c8f039e6..355451e2 100644 --- a/apps/web/src/components/settings/ConnectionsSettings.logic.test.ts +++ b/apps/web/src/components/settings/ConnectionsSettings.logic.test.ts @@ -1,6 +1,11 @@ import type { DesktopWslState } from "@t3tools/contracts"; import { describe, expect, it, vi } from "vite-plus/test"; -import { applyWslEnableSelection } from "./ConnectionsSettings.logic"; +import { + applyWslEnableSelection, + isQrShareableEndpoint, + isWslSettingsRowVisible, + selectQrEndpointOption, +} from "./ConnectionsSettings.logic"; const baseWslState: DesktopWslState = { enabled: false, @@ -11,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 = []; diff --git a/apps/web/src/components/settings/ConnectionsSettings.logic.ts b/apps/web/src/components/settings/ConnectionsSettings.logic.ts index 362a24dd..93ff0423 100644 --- a/apps/web/src/components/settings/ConnectionsSettings.logic.ts +++ b/apps/web/src/components/settings/ConnectionsSettings.logic.ts @@ -2,6 +2,57 @@ import type { DesktopBridge, DesktopWslState } from "@t3tools/contracts"; type WslEnableBridge = Pick; +/** + * A QR code encoding a loopback URL makes the scanning device dial itself, so + * loopback endpoints stay copyable from the endpoint menu but are never + * offered as QR targets. + */ +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; + /** + * Stable per endpoint *type* (endpointDefaultPreferenceKey). Multiple + * endpoints can share one, so it is only used to match the saved default. + */ + readonly preferenceKey: string; + /** False for endpoints that stay copyable but must never render as a QR. */ + readonly qrShareable: boolean; +}; + +/** + * Resolves which endpoint the share panel shows: the user's explicit pick, + * else the saved default endpoint, else the first QR-shareable option (so the + * panel never opens on a loopback QR), else the first option. A stale + * selectedId (endpoint disappeared) falls back rather than blanking the panel. + */ +export function selectQrEndpointOption( + options: ReadonlyArray, + selectedId: string | null, + defaultPreferenceKey: string | null, +): T | null { + return ( + (selectedId !== null ? options.find((option) => option.id === selectedId) : undefined) ?? + (defaultPreferenceKey !== null + ? options.find((option) => option.preferenceKey === defaultPreferenceKey) + : undefined) ?? + options.find((option) => option.qrShareable) ?? + options[0] ?? + null + ); +} + export async function applyWslEnableSelection(input: { readonly bridge: WslEnableBridge; readonly mode: "both" | "wsl-only"; diff --git a/apps/web/src/components/settings/ConnectionsSettings.tsx b/apps/web/src/components/settings/ConnectionsSettings.tsx index b1fae806..4106d7f7 100644 --- a/apps/web/src/components/settings/ConnectionsSettings.tsx +++ b/apps/web/src/components/settings/ConnectionsSettings.tsx @@ -42,7 +42,12 @@ import { useCopyToClipboard } from "../../hooks/useCopyToClipboard"; import { cn } from "../../lib/utils"; import { formatElapsedDurationLabel, formatExpiresInLabel } from "../../timestampFormat"; import { resolveDesktopPairingUrl, resolveHostedPairingUrl } from "./pairingUrls"; -import { applyWslEnableSelection } from "./ConnectionsSettings.logic"; +import { + applyWslEnableSelection, + isQrShareableEndpoint, + isWslSettingsRowVisible, + selectQrEndpointOption, +} from "./ConnectionsSettings.logic"; import { SettingsPageContainer, SettingsRow, @@ -2747,7 +2752,10 @@ 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 (