The best way to control Claude Code, Codex and more from any computer or phone
fix(clients): a route added after a reorder no longer disappears (#24716)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Victor Vogel committed
Oct 30, 2026 at 16:08 UTC
9e97921ad81fe123a6b80bd9d0d04554c7143d06
5 files changed
+127
-12
apps/mobile/src/features/settings/EnvironmentRoutesSection.tsx
+5
-6
@@ -10,6 +10,7 @@ import {
10
connectionRouteLabel,
11
connectionRoutes,
12
isLearned,
13
+ pendingRouteOrder,
14
} from "@t3tools/client-runtime/connection";
15
import { type EnvironmentId, sessionGrantsScope } from "@t3tools/contracts";
16
import {
@@ -67,12 +68,10 @@ export function EnvironmentRoutesSection({
68
const saved = entry === undefined ? [] : connectionRoutes(entry);
69
const savedIds = saved.map((route) => connectionRouteId(route.target));
70
const [pending, setPending] = useState<ReadonlyArray<string> | null>(null);
70
- const order =
71
- pending !== null &&
72
- pending.length === savedIds.length &&
73
- pending.some((id, index) => id !== savedIds[index])
74
- ? pending
75
- : savedIds;
71
+ const shownPending = pendingRouteOrder(pending, savedIds);
72
+ // Dropped during render so a stale order never outlives the save it was for.
73
+ if (pending !== null && shownPending === null) setPending(null);
74
+ const order = shownPending ?? savedIds;
75
const [drag, setDrag] = useState<{ readonly id: string; readonly translation: number } | null>(
76
null,
77
);
apps/web/src/components/settings/EnvironmentRoutesList.browser.test.tsx
new
+92
@@ -0,0 +1,92 @@
1
+import {
2
+ BearerConnectionProfile,
3
+ BearerConnectionTarget,
4
+ type ConnectionCatalogEntry,
5
+ type ConnectionRoute,
6
+} from "@t3tools/client-runtime/connection";
7
+import { EnvironmentId } from "@t3tools/contracts";
8
+import * as Option from "effect/Option";
9
+import { expect, it, vi } from "vite-plus/test";
10
+import { userEvent } from "vite-plus/test/browser";
11
+
12
+vi.mock(import("~/state/session"), async (importOriginal) => ({
13
+ ...(await importOriginal()),
14
+ usePreparedConnection: (() => Option.none()) as never,
15
+}));
16
+
17
+vi.mock(import("~/state/use-atom-command"), async (importOriginal) => ({
18
+ ...(await importOriginal()),
19
+ useAtomCommand: (() => async () => ({ _tag: "Success" })) as never,
20
+}));
21
+
22
+import { render } from "../../../test/render";
23
+import type { EnvironmentPresentation } from "~/state/environments";
24
+import { EnvironmentRoutesList } from "./EnvironmentRoutesList";
25
+
26
+const ENVIRONMENT_ID = EnvironmentId.make("environment-1");
27
+
28
+function direct(id: string, httpBaseUrl: string): ConnectionRoute {
29
+ return {
30
+ target: new BearerConnectionTarget({
31
+ environmentId: ENVIRONMENT_ID,
32
+ label: "Desk",
33
+ connectionId: id,
34
+ }),
35
+ profile: Option.some(
36
+ new BearerConnectionProfile({
37
+ connectionId: id,
38
+ environmentId: ENVIRONMENT_ID,
39
+ label: "Desk",
40
+ httpBaseUrl,
41
+ wsBaseUrl: httpBaseUrl.replace(/^http/, "ws"),
42
+ }),
43
+ ),
44
+ };
45
+}
46
+
47
+const LAN = direct("lan", "http://192.168.1.10:3773/");
48
+const TAILNET = direct("tailnet", "https://desk.tail1234.ts.net/");
49
+const PUBLIC = direct("public", "https://desk.example.com/");
50
+
51
+function routesList(routes: ReadonlyArray<ConnectionRoute>) {
52
+ const [first, ...rest] = routes;
53
+ const entry: ConnectionCatalogEntry = {
54
+ target: first!.target,
55
+ profile: first!.profile,
56
+ alternateRoutes: rest,
57
+ enabled: true,
58
+ };
59
+ const environment: EnvironmentPresentation = {
60
+ environmentId: ENVIRONMENT_ID,
61
+ label: "Desk",
62
+ displayUrl: null,
63
+ relayManaged: false,
64
+ entry,
65
+ connection: { phase: "available", error: null, traceId: null },
66
+ serverConfig: null,
67
+ };
68
+ return <EnvironmentRoutesList environment={environment} onAddRoute={() => undefined} />;
69
+}
70
+
71
+it("shows a route added after a reorder was saved, once another route is removed", async () => {
72
+ await using screen = await render(routesList([LAN, TAILNET]));
73
+ await userEvent.click(screen.getByRole("button", { name: "Reorder LAN, position 1" }));
74
+ await userEvent.keyboard(" ");
75
+ await userEvent.keyboard("{ArrowDown}");
76
+ await userEvent.keyboard(" ");
77
+ await expect
78
+ .element(screen.getByRole("button", { name: "Reorder Tailscale, position 1" }))
79
+ .toBeVisible();
80
+
81
+ await screen.rerender(routesList([TAILNET, LAN]));
82
+ await screen.rerender(routesList([TAILNET, LAN, PUBLIC]));
83
+ await screen.rerender(routesList([TAILNET, PUBLIC]));
84
+
85
+ await expect
86
+ .element(screen.getByRole("button", { name: "Reorder desk.example.com, position 2" }))
87
+ .toBeVisible();
88
+ expect(screen.getByRole("listitem").elements()).toHaveLength(2);
89
+ await expect
90
+ .element(screen.getByRole("button", { name: "Remove desk.example.com route" }))
91
+ .toBeVisible();
92
+});
apps/web/src/components/settings/EnvironmentRoutesList.tsx
+5
-6
@@ -23,6 +23,7 @@ import {
23
connectionRouteLabel,
24
connectionRoutes,
25
isLearned,
26
+ pendingRouteOrder,
27
} from "@t3tools/client-runtime/connection";
28
import { GripVerticalIcon, PlusIcon, XIcon } from "lucide-react";
29
import { useState } from "react";
@@ -46,12 +47,10 @@ export function EnvironmentRoutesList({
47
const saved = connectionRoutes(environment.entry);
48
const savedIds = saved.map((route) => connectionRouteId(route.target));
49
const [pending, setPending] = useState<ReadonlyArray<string> | null>(null);
49
- const order: Array<string> =
50
- pending !== null &&
51
- pending.length === savedIds.length &&
52
- pending.some((id, index) => id !== savedIds[index])
53
- ? [...pending]
54
- : savedIds;
50
+ const shownPending = pendingRouteOrder(pending, savedIds);
51
+ // Dropped during render so a stale order never outlives the save it was for.
52
+ if (pending !== null && shownPending === null) setPending(null);
53
+ const order: Array<string> = shownPending === null ? savedIds : [...shownPending];
54
const byId = new Map(saved.map((route) => [connectionRouteId(route.target), route]));
55
const routes = order.flatMap((id) => byId.get(id) ?? []);
56
packages/client-runtime/src/connection/routes.test.ts
+9
@@ -17,6 +17,7 @@ import {
17
insertRoute,
18
entryWithRoutes,
19
mergeLearnedRoutes,
20
+ pendingRouteOrder,
21
removedWithRelay,
22
routesAfterRemoving,
23
sendsTokenInClear,
@@ -87,6 +88,14 @@ describe("connection routes", () => {
88
const repaired = direct("lan", "http://192.168.1.11:3773/");
89
expect(upsertRoute([RELAY, LAN], repaired)).toEqual([RELAY, repaired]);
90
});
91
+
92
+ it("shows a dragged order only until the saved routes catch up or change", () => {
93
+ const dragged = ["tailnet", "lan"];
94
+ expect(pendingRouteOrder(dragged, ["lan", "tailnet"])).toBe(dragged);
95
+ expect(pendingRouteOrder(dragged, ["tailnet", "lan"])).toBeNull();
96
+ expect(pendingRouteOrder(dragged, ["lan", "public"])).toBeNull();
97
+ expect(pendingRouteOrder(dragged, ["lan", "tailnet", "public"])).toBeNull();
98
+ });
99
});
100
101
describe("learned routes", () => {
packages/client-runtime/src/connection/routes.ts
+16
@@ -422,6 +422,22 @@ export function routesAfterRemoving(
422
});
423
}
424
425
+/**
426
+ * A dragged route order shows until the saved routes catch up with it. It is
427
+ * stale, and returns null, once the saved order matches it or the saved routes
428
+ * are no longer the same set: kept any longer, it would hide a route added
429
+ * later whenever the count happened to match again.
430
+ */
431
+export function pendingRouteOrder(
432
+ pending: ReadonlyArray<string> | null,
433
+ savedIds: ReadonlyArray<string>,
434
+): ReadonlyArray<string> | null {
435
+ if (pending === null || pending.length !== savedIds.length) return null;
436
+ const saved = new Set(savedIds);
437
+ if (!pending.every((id) => saved.has(id))) return null;
438
+ return pending.some((id, index) => id !== savedIds[index]) ? pending : null;
439
+}
440
+
441
export function removedWithRelay(entry: ConnectionCatalogEntry): boolean {
442
return routesAfterRemoving(connectionRoutes(entry), RELAY_ROUTE_ID).length === 0;
443
}