@devries-cameron20 / t3code Mirror · read-only / commits / 74b1f97ce9
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 08:30 UTC

fix(web): reopening Settings reloads WSL distributions (#38281)

Co-authored-by: Grok 4.7 <noreply@x.ai> Co-authored-by: Julius Marminge <julius0216@outlook.com>

Wout Stiens committed Nov 17, 2026 at 20:44 UTC 74b1f97ce9e8891975bb29d10a4de1fdb0505863
4 files changed +85 -11
apps/web/src/components/settings/ConnectionsSettings.tsx
+2 -2
@@ -99,7 +99,7 @@ import {
99 desktopNetworkAccessStateAtom,
100 refreshDesktopNetworkAccessState,
101 } from "~/state/desktopNetworkAccess";
102 -import { desktopWslStateAtom, refreshDesktopWslState } from "~/state/desktopWslState";
102 +import { desktopWslAccessStateAtom, refreshDesktopWslState } from "~/state/desktopWslState";
103 import { useDesktopUpdateState } from "~/state/desktopUpdate";
104 import {
105 type EnvironmentPresentation,
@@ -415,7 +415,7 @@ function ConnectionsSettingsContent({
415 showsAccess && canManageLocalBackend && desktopBridge ? desktopNetworkAccessStateAtom : null,
416 );
417 const desktopWsl = useEnvironmentQuery(
418 - showsAccess && canManageLocalBackend && desktopBridge ? desktopWslStateAtom : null,
418 + showsAccess && canManageLocalBackend && desktopBridge ? desktopWslAccessStateAtom : null,
419 );
420 const desktopWslState = desktopWsl.data;
421 const desktopWslError = desktopWslMutationError ?? desktopWsl.error;
apps/web/src/state/desktopWslState.test.ts new
+72
@@ -0,0 +1,72 @@
1 +import type { DesktopWslState } from "@t3tools/contracts";
2 +import { AsyncResult, AtomRegistry } from "effect/reactivity";
3 +import { expect, it, vi } from "vite-plus/test";
4 +
5 +import { desktopWslAccessStateAtom, desktopWslStateAtom } from "./desktopWslState";
6 +
7 +const ubuntuOnly: DesktopWslState = {
8 + enabled: false,
9 + distro: null,
10 + available: true,
11 + wslOnly: false,
12 + distros: [{ name: "Ubuntu", isDefault: true, version: 2 }],
13 + preflightError: null,
14 +};
15 +const withDebian: DesktopWslState = {
16 + ...ubuntuOnly,
17 + distros: [...ubuntuOnly.distros, { name: "Debian", isDefault: false, version: 2 }],
18 +};
19 +
20 +it("refetches on every Access visit and reuses a fresh result for Search", async () => {
21 + const pending = Promise.withResolvers<DesktopWslState>();
22 + const getWslState = vi
23 + .fn<() => Promise<DesktopWslState>>()
24 + .mockResolvedValueOnce(ubuntuOnly)
25 + .mockReturnValueOnce(pending.promise);
26 + vi.stubGlobal("window", { desktopBridge: { getWslState } });
27 + using _now = vi.spyOn(Date, "now").mockReturnValue(1_000_000);
28 + const tasks: Array<() => void> = [];
29 + const registry = AtomRegistry.make({
30 + scheduleTask: (task) => {
31 + tasks.push(task);
32 + return () => {};
33 + },
34 + });
35 + const runTasks = () => {
36 + for (const task of tasks.splice(0)) task();
37 + };
38 + const settled = (atom: typeof desktopWslStateAtom) =>
39 + new Promise<DesktopWslState>((resolve) => {
40 + const unsubscribe = registry.subscribe(
41 + atom,
42 + (result) => {
43 + if (result._tag === "Success" && !result.waiting) {
44 + unsubscribe();
45 + resolve(result.value);
46 + }
47 + },
48 + { immediate: true },
49 + );
50 + });
51 + try {
52 + const closeSearch = registry.mount(desktopWslStateAtom);
53 + expect(await settled(desktopWslStateAtom)).toEqual(ubuntuOnly);
54 + closeSearch();
55 + runTasks();
56 +
57 + registry.mount(desktopWslStateAtom)();
58 + runTasks();
59 + expect(getWslState).toHaveBeenCalledTimes(1);
60 +
61 + const closeAccess = registry.mount(desktopWslAccessStateAtom);
62 + runTasks();
63 + expect(getWslState).toHaveBeenCalledTimes(2);
64 + expect(AsyncResult.getOrThrow(registry.get(desktopWslAccessStateAtom))).toEqual(ubuntuOnly);
65 + pending.resolve(withDebian);
66 + expect(await settled(desktopWslAccessStateAtom)).toEqual(withDebian);
67 + closeAccess();
68 + } finally {
69 + registry.dispose();
70 + vi.unstubAllGlobals();
71 + }
72 +});
apps/web/src/state/desktopWslState.ts
+10 -8
@@ -1,3 +1,4 @@
1 +import { revalidateOnMount } from "@t3tools/client-runtime/state/runtime";
2 import type { DesktopBridge, DesktopWslState } from "@t3tools/contracts";
3 import * as Effect from "effect/Effect";
4 import * as Schema from "effect/Schema";
@@ -5,9 +6,8 @@ import { Atom } from "effect/reactivity";
6
7 import { appAtomRegistry } from "~/rpc/atomRegistry";
8
8 -const DESKTOP_WSL_STATE_STALE_TIME_MS = 30_000;
9 -
9 type DesktopWslStateBridge = Pick<DesktopBridge, "getWslState">;
10 +const WSL_SEARCH_STALE_TIME_MS = 30_000;
11
12 class DesktopWslStateUnavailableError extends Schema.TaggedError<DesktopWslStateUnavailableError>()(
13 "DesktopWslStateUnavailableError",
@@ -44,17 +44,19 @@ function createDesktopWslStateAtom(getBridge: () => DesktopWslStateBridge | unde
44 });
45
46 return Atom.make(loadDesktopWslState()).pipe(
47 - Atom.swr({
48 - staleTime: DESKTOP_WSL_STATE_STALE_TIME_MS,
49 - revalidateOnMount: true,
50 - }),
47 Atom.keepAlive,
48 Atom.withLabel("desktop:wsl-state:load"),
49 );
50 }
51
56 -export const desktopWslStateAtom = createDesktopWslStateAtom(getDesktopWslStateBridge);
52 +const desktopWslStateCache = createDesktopWslStateAtom(getDesktopWslStateBridge);
53 +
54 +export const desktopWslStateAtom = desktopWslStateCache.pipe(
55 + revalidateOnMount(WSL_SEARCH_STALE_TIME_MS),
56 +);
57 +
58 +export const desktopWslAccessStateAtom = desktopWslStateCache.pipe(revalidateOnMount(0));
59
60 export function refreshDesktopWslState(): void {
59 - appAtomRegistry.refresh(desktopWslStateAtom);
61 + appAtomRegistry.refresh(desktopWslStateCache);
62 }
packages/client-runtime/src/state/runtime.ts
+1 -1
@@ -573,7 +573,7 @@ const isStale = (result: AsyncResult.AsyncResult<unknown, unknown>, staleTimeMs:
573 * TTL skips on a remount; this layer has no TTL (a transform drops it) while `self` keeps the cache.
574 * It reads `self` as a dependency, not a subscription, so `self` goes idle with its last reader.
575 */
576 -const revalidateOnMount =
576 +export const revalidateOnMount =
577 (staleTimeMs: number) =>
578 <A, E>(
579 self: Atom.Atom<AsyncResult.AsyncResult<A, E>>,