The best way to control Claude Code, Codex and more from any computer or phone
fix(mobile): a pairing link fills the open Add environment form instead of stacking another (#26052)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 27, 2026 at 12:15 UTC
76d5ec7a22a312c3b9cb6a64102de1933321e665
3 files changed
+89
-3
apps/mobile/src/App.tsx
+5
-1
@@ -52,7 +52,7 @@ 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 { startDevAutoConnect } from "./features/connection/devAutoConnect";
55
+import { pairingFormLinkAction, startDevAutoConnect } from "./features/connection/devAutoConnect";
56
import {
57
resolvePendingNewTaskPromptLink,
58
takeNewTaskPromptLink,
@@ -129,6 +129,10 @@ const appLinking = {
129
): ReturnType<typeof getActionFromState> =>
130
// Our router handles the selection; React Navigation's type only lists its own actions.
131
(workspaceDetailLinkAction(state) as ReturnType<typeof getActionFromState>) ??
132
+ pairingFormLinkAction(
133
+ state,
134
+ rootNavigationRef.isReady() ? rootNavigationRef.getRootState() : undefined,
135
+ ) ??
136
getActionFromState(state, options),
137
getStateFromPath: getAppStateFromPath,
138
};
apps/mobile/src/features/connection/devAutoConnect.test.ts
+64
-1
@@ -1,6 +1,21 @@
1
+import * as NodeModule from "node:module";
2
import type { NavigationState, PartialState } from "@react-navigation/native";
3
import { expect, it, vi } from "vite-plus/test";
4
5
+const requireFromNative = NodeModule.createRequire(
6
+ NodeModule.createRequire(import.meta.url).resolve("@react-navigation/native/package.json"),
7
+);
8
+const requireFromCore = NodeModule.createRequire(
9
+ requireFromNative.resolve("@react-navigation/core/package.json"),
10
+);
11
+const { getActionFromState, getStateFromPath } = requireFromNative("@react-navigation/core") as {
12
+ readonly getActionFromState: typeof import("@react-navigation/native").getActionFromState;
13
+ readonly getStateFromPath: typeof import("@react-navigation/native").getStateFromPath;
14
+};
15
+const { StackRouter } = requireFromCore("@react-navigation/routers") as {
16
+ readonly StackRouter: typeof import("@react-navigation/native").StackRouter;
17
+};
18
+
19
const harness = vi.hoisted(() => ({
20
pair: vi.fn(),
21
goBack: vi.fn(),
@@ -20,7 +35,12 @@ const harness = vi.hoisted(() => ({
35
deferred: null as Array<() => void> | null,
36
}));
37
23
-vi.mock("@react-navigation/native", () => ({ StackActions: { replace: vi.fn() } }));
38
+vi.mock("@react-navigation/native", () => ({
39
+ StackActions: { replace: vi.fn() },
40
+ CommonActions: {
41
+ replaceParams: (params: object) => ({ type: "REPLACE_PARAMS", payload: { params } }),
42
+ },
43
+}));
44
vi.mock("../../state/use-remote-environment-registry", () => ({
45
pairEnvironment: harness.pair,
46
}));
@@ -47,6 +67,7 @@ import { appAtomRegistry } from "../../state/atom-registry";
67
import {
68
autoConnectReport,
69
devAutoConnectAttemptAtom,
70
+ pairingFormLinkAction,
71
startDevAutoConnect,
72
} from "./devAutoConnect";
73
@@ -191,3 +212,45 @@ it("a success that waited for navigation leaves a newer link's form open", async
212
expect(harness.goBack).not.toHaveBeenCalled();
213
expect(harness.dispatch).not.toHaveBeenCalled();
214
});
215
+
216
+it("a pairing link fills the pairing form already on screen instead of stacking a second one", () => {
217
+ const linking = {
218
+ initialRouteName: "Home",
219
+ screens: {
220
+ Home: "",
221
+ Settings: "settings",
222
+ SettingsEnvironmentNew: "settings/environment-new",
223
+ ConnectionsNew: "connections/new",
224
+ },
225
+ };
226
+ const router = StackRouter({});
227
+ const options = {
228
+ routeNames: Object.keys(linking.screens),
229
+ routeParamList: {},
230
+ routeGetIdList: {},
231
+ };
232
+ // Settings > Environments > Add environment, as the user opened it.
233
+ const open = router.getRehydratedState(
234
+ {
235
+ index: 2,
236
+ routes: [{ name: "Home" }, { name: "Settings" }, { name: "SettingsEnvironmentNew" }],
237
+ },
238
+ options,
239
+ );
240
+ const link = getStateFromPath(
241
+ `connections/new?pairingUrl=${encodeURIComponent(PAIRING_URL)}`,
242
+ linking,
243
+ )!;
244
+ const action = pairingFormLinkAction(link, open) ?? getActionFromState(link, linking)!;
245
+ const next = router.getStateForAction(open, { target: open.key, ...action }, options);
246
+
247
+ expect(next?.routes.map((route) => route.name)).toEqual([
248
+ "Home",
249
+ "Settings",
250
+ "SettingsEnvironmentNew",
251
+ ]);
252
+ expect(next?.routes.at(-1)).toMatchObject({
253
+ key: open.routes[2]!.key,
254
+ params: { pairingUrl: PAIRING_URL },
255
+ });
256
+});
apps/mobile/src/features/connection/devAutoConnect.ts
+20
-1
@@ -1,5 +1,5 @@
1
import type { NavigationState, PartialState } from "@react-navigation/native";
2
-import { StackActions } from "@react-navigation/native";
2
+import { CommonActions, StackActions } from "@react-navigation/native";
3
import type { EnvironmentId } from "@t3tools/contracts";
4
import { Atom } from "effect/reactivity";
5
@@ -97,3 +97,22 @@ export function startDevAutoConnect(
97
}
98
return state;
99
}
100
+
101
+/**
102
+ * A pairing link that lands on an open pairing form fills that form. React Navigation would push
103
+ * `ConnectionsNew` over the Settings page's `SettingsEnvironmentNew`, stacking two copies of the
104
+ * same form. The form keys on the link's pairing URL, so new params remount it with the prefill.
105
+ */
106
+export function pairingFormLinkAction(
107
+ link: PartialState<NavigationState>,
108
+ current: NavigationState | undefined,
109
+) {
110
+ const linked = findLinkedRoute(link, PAIRING_FORM_ROUTES);
111
+ const open = current?.routes[current.index];
112
+ if (!linked || !current || !open || !PAIRING_FORM_ROUTES.includes(open.name)) return undefined;
113
+ return {
114
+ ...CommonActions.replaceParams(linked.params ?? {}),
115
+ source: open.key,
116
+ target: current.key,
117
+ };
118
+}