@devries-cameron20 / t3code-1 / commits / c0f9e36184
Fork 0

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

fix(mobile): pairing deep links can no longer target a saved environment (#26318)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 27, 2026 at 23:23 UTC c0f9e36184956994d6d26c6f3e526676380161d3
3 files changed +62 -13
apps/mobile/src/App.tsx
+12 -6
@@ -52,7 +52,11 @@ import { OverlayPortalHost } from "./components/ui/OverlayPortal";
52 import { shouldHandleAppLink, restoreDraftLinkState } from "./lib/appLinking";
53 import { hasCloudPublicConfig } from "./features/cloud/publicConfig";
54 import { takeScheduledTaskNewLink } from "./features/settings/scheduled-task-editor-state";
55 -import { pairingFormLinkAction, startDevAutoConnect } from "./features/connection/devAutoConnect";
55 +import {
56 + pairingFormLinkAction,
57 + startDevAutoConnect,
58 + withoutPairingTarget,
59 +} from "./features/connection/devAutoConnect";
60 import {
61 resolvePendingNewTaskPromptLink,
62 takeNewTaskPromptLink,
@@ -106,11 +110,13 @@ const linkingConfig = {
110 function getAppStateFromPath(path: string, options: Parameters<typeof getStateFromPath>[1]) {
111 return takeScheduledTaskNewLink(
112 startDevAutoConnect(
109 - takeNewTaskPromptLink(
110 - takeThreadPromptLink(
111 - restoreSettingsLinkState(
112 - restoreDraftLinkState(getStateFromPath(path, options), path),
113 - settingsLinkPage(),
113 + withoutPairingTarget(
114 + takeNewTaskPromptLink(
115 + takeThreadPromptLink(
116 + restoreSettingsLinkState(
117 + restoreDraftLinkState(getStateFromPath(path, options), path),
118 + settingsLinkPage(),
119 + ),
120 ),
121 ),
122 ),
apps/mobile/src/features/connection/devAutoConnect.test.ts
+32 -1
@@ -63,12 +63,14 @@ vi.mock("../../lib/rootNavigation", () => ({
63 },
64 }));
65
66 +import { findLinkedRoute } from "../../lib/appLinking";
67 import { appAtomRegistry } from "../../state/atom-registry";
68 import {
69 autoConnectReport,
70 devAutoConnectAttemptAtom,
71 pairingFormLinkAction,
72 startDevAutoConnect,
73 + withoutPairingTarget,
74 } from "./devAutoConnect";
75
76 const PAIRING_URL = "http://192.168.1.10:3773/pair#token=abc";
@@ -89,7 +91,7 @@ it("pairs from a nested settings link once, reports failure, and closes the form
91
92 const state = settingsLink({ pairingUrl: ` ${PAIRING_URL} `, autoConnect: "1" });
93 expect(startDevAutoConnect(state)).toBe(state);
92 - expect(harness.pair).toHaveBeenCalledExactlyOnceWith(PAIRING_URL, undefined);
94 + expect(harness.pair).toHaveBeenCalledExactlyOnceWith(PAIRING_URL);
95 expect(appAtomRegistry.get(devAutoConnectAttemptAtom)).toEqual({
96 pairingUrl: PAIRING_URL,
97 status: "connecting",
@@ -254,3 +256,32 @@ it("a pairing link fills the pairing form already on screen instead of stacking
256 params: { pairingUrl: PAIRING_URL },
257 });
258 });
259 +
260 +it("a link cannot aim a pairing at a saved environment", () => {
261 + vi.stubGlobal("__DEV__", true);
262 + harness.pair.mockClear();
263 + harness.pair.mockResolvedValue({ ok: false, error: null });
264 + const linking = {
265 + initialRouteName: "Home",
266 + screens: {
267 + Home: "",
268 + Settings: { path: "settings", screens: { SettingsEnvironmentNew: "environment-new" } },
269 + ConnectionsNew: "connections/new",
270 + },
271 + };
272 + for (const path of ["connections/new", "settings/environment-new"]) {
273 + const link = withoutPairingTarget(
274 + getStateFromPath(
275 + `${path}?routeFor=victim&pairingUrl=${encodeURIComponent(PAIRING_URL)}&autoConnect=1`,
276 + linking,
277 + ),
278 + );
279 + expect(findLinkedRoute(link, ["ConnectionsNew", "SettingsEnvironmentNew"])?.params).toEqual({
280 + pairingUrl: PAIRING_URL,
281 + autoConnect: "1",
282 + });
283 +
284 + startDevAutoConnect(link);
285 + expect(harness.pair).toHaveBeenLastCalledWith(PAIRING_URL);
286 + }
287 +});
apps/mobile/src/features/connection/devAutoConnect.ts
+18 -6
@@ -1,9 +1,8 @@
1 import type { NavigationState, PartialState } from "@react-navigation/native";
2 import { CommonActions, StackActions } from "@react-navigation/native";
3 -import type { EnvironmentId } from "@t3tools/contracts";
3 import { Atom } from "effect/reactivity";
4
6 -import { findLinkedRoute } from "../../lib/appLinking";
5 +import { findLinkedRoute, updateLinkedRoute } from "../../lib/appLinking";
6 import { rootNavigationRef, whenRootNavigationReady } from "../../lib/rootNavigation";
7 import { appAtomRegistry } from "../../state/atom-registry";
8 import { leaveSettingsPage } from "../settings/settings-navigation";
@@ -44,10 +43,10 @@ function isAutoConnectFlag(value: unknown): boolean {
43 return value === "1" || value === "true";
44 }
45
47 -async function connect(pairingUrl: string, expectedEnvironmentId: EnvironmentId | undefined) {
46 +async function connect(pairingUrl: string) {
47 const attempt: DevAutoConnectAttempt = { pairingUrl, status: "connecting" };
48 appAtomRegistry.set(devAutoConnectAttemptAtom, attempt);
50 - const outcome = await pairEnvironment(pairingUrl, expectedEnvironmentId);
49 + const outcome = await pairEnvironment(pairingUrl);
50 // A later link replaced or cleared this attempt; its result belongs to no open form.
51 if (appAtomRegistry.get(devAutoConnectAttemptAtom) !== attempt) return;
52 if (!outcome.ok) {
@@ -71,6 +70,20 @@ async function connect(pairingUrl: string, expectedEnvironmentId: EnvironmentId
70 });
71 }
72
73 +/**
74 + * `routeFor` makes a pairing an "Add route" to a saved environment, which skips the guard against
75 + * a pairing taking over that environment's id. Only in-app navigation may set it, never a link.
76 + */
77 +export function withoutPairingTarget(
78 + state: PartialState<NavigationState> | undefined,
79 +): PartialState<NavigationState> | undefined {
80 + return updateLinkedRoute(state, PAIRING_FORM_ROUTES, (route) => {
81 + if (route.params === undefined || !("routeFor" in route.params)) return route;
82 + const { routeFor: _routeFor, ...params } = route.params as { readonly routeFor?: unknown };
83 + return { ...route, params };
84 + });
85 +}
86 +
87 /**
88 * `connections/new?pairingUrl=…&autoConnect=1` (or `settings/environment-new?…`) pairs from the
89 * link itself, so a remount of the form never pairs twice. Production builds ignore the flag so
@@ -85,11 +98,10 @@ export function startDevAutoConnect(
98 const params = (route.params ?? {}) as {
99 readonly autoConnect?: unknown;
100 readonly pairingUrl?: unknown;
88 - readonly routeFor?: EnvironmentId;
101 };
102 const pairingUrl = typeof params.pairingUrl === "string" ? params.pairingUrl.trim() : "";
103 if (isAutoConnectFlag(params.autoConnect) && pairingUrl.length > 0) {
92 - void connect(pairingUrl, params.routeFor);
104 + void connect(pairingUrl);
105 } else {
106 // Only links put a pairing URL on the form, so a form opened by any other link starts
107 // clean instead of showing an earlier auto-connect's failure for the same URL.