The best way to control Claude Code, Codex and more from any computer or phone
refactor(mobile): app link parsing reads top to bottom with pipe (#26330)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 28, 2026 at 00:39 UTC
2349c81afc1ce5de71fdb50f488f395f0307e4a2
3 files changed
+32
-104
apps/mobile/src/App.tsx
+32
-5
@@ -13,9 +13,11 @@ import {
13
createPathConfigForStaticNavigation,
14
createStaticNavigation,
15
getActionFromState,
16
+ getStateFromPath,
17
type NavigationAction,
18
type NavigationState,
19
} from "@react-navigation/native";
20
+import { pipe } from "effect/Function";
21
22
import { RegistryContext } from "@effect/atom-react";
23
import { ProjectChipIconRasterizer } from "./native/ProjectChipIconImages";
@@ -48,12 +50,22 @@ import { subscribeComposerDraftModelReconciliation } from "./state/use-composer-
50
import { environmentThreadShells } from "./state/threads";
51
import { environmentShell } from "./state/shell";
52
import { OverlayPortalHost } from "./components/ui/OverlayPortal";
51
-import { shouldHandleAppLink } from "./lib/appLinking";
53
+import { shouldHandleAppLink, restoreDraftLinkState } from "./lib/appLinking";
54
import { hasCloudPublicConfig } from "./features/cloud/publicConfig";
53
-import { pairingFormLinkAction } from "./features/connection/devAutoConnect";
54
-import { resolvePendingNewTaskPromptLink } from "./features/prompt-links/newTaskPromptLink";
55
-import { resolvePendingThreadPromptLink } from "./features/prompt-links/threadPromptLink";
56
-import { getAppStateFromPath } from "./lib/appLinkState";
55
+import { takeScheduledTaskNewLink } from "./features/settings/scheduled-task-editor-state";
56
+import {
57
+ pairingFormLinkAction,
58
+ startDevAutoConnect,
59
+ withoutPairingTarget,
60
+} from "./features/connection/devAutoConnect";
61
+import {
62
+ resolvePendingNewTaskPromptLink,
63
+ takeNewTaskPromptLink,
64
+} from "./features/prompt-links/newTaskPromptLink";
65
+import {
66
+ resolvePendingThreadPromptLink,
67
+ takeThreadPromptLink,
68
+} from "./features/prompt-links/threadPromptLink";
69
import {
70
disposeOnFoundationReplace,
71
type FoundationHotModule,
@@ -63,10 +75,12 @@ import { installUiRuntimeMemoryWarningGc } from "./lib/useUiRuntimeMemoryWarning
75
import { SubscriptionUsageCoordinator } from "./widgets/SubscriptionUsageCoordinator";
76
import { installSubscriptionUsageRefresh } from "./widgets/useSubscriptionUsage";
77
import { GlobalVoiceInputControl } from "./features/voice-input/GlobalVoiceInputControl";
78
+import { restoreSettingsLinkState } from "./features/settings/settings-navigation";
79
import {
80
hydrateWorkspaceSelections,
81
launchWorkspaceURL,
82
recordWorkspaceSelections,
83
+ settingsLinkPage,
84
} from "./features/workspace/workspace-selection-store";
85
import { workspaceDetailLinkAction } from "./features/workspace/workspace-detail-selection";
86
import { NativeLayoutMetricsProvider } from "./native/native-layout-metrics";
@@ -94,6 +108,19 @@ const linkingConfig = {
108
screens: createPathConfigForStaticNavigation(RootStack, { initialRouteName: "Home" }) ?? {},
109
} as const;
110
111
+function getAppStateFromPath(path: string, options: Parameters<typeof getStateFromPath>[1]) {
112
+ return pipe(
113
+ getStateFromPath(path, options),
114
+ (state) => restoreDraftLinkState(state, path),
115
+ (state) => restoreSettingsLinkState(state, settingsLinkPage()),
116
+ takeThreadPromptLink,
117
+ takeNewTaskPromptLink,
118
+ withoutPairingTarget,
119
+ startDevAutoConnect,
120
+ takeScheduledTaskNewLink,
121
+ );
122
+}
123
+
124
const appLinking = {
125
prefixes: [Linking.createURL("/"), "t3code://", "t3code-dev://", "t3code-preview://"],
126
config: { initialRouteName: "Home" },
apps/mobile/src/lib/appLinkState.test.ts
deleted
-72
@@ -1,72 +0,0 @@
1
-import * as NodeModule from "node:module";
2
-import { expect, it, vi } from "vite-plus/test";
3
-
4
-const harness = vi.hoisted(() => {
5
- vi.stubGlobal("__DEV__", true);
6
- return { pair: vi.fn() };
7
-});
8
-
9
-// The native package pulls in React Native; its link parsing and actions live in core and routers.
10
-vi.mock("@react-navigation/native", () => {
11
- const requireFromNative = NodeModule.createRequire(
12
- NodeModule.createRequire(import.meta.url).resolve("@react-navigation/native/package.json"),
13
- );
14
- const requireFromCore = NodeModule.createRequire(
15
- requireFromNative.resolve("@react-navigation/core/package.json"),
16
- );
17
- const { getStateFromPath } = requireFromNative("@react-navigation/core");
18
- const { CommonActions, StackActions } = requireFromCore("@react-navigation/routers");
19
- return { getStateFromPath, CommonActions, StackActions };
20
-});
21
-
22
-vi.mock("./rootNavigation", () => ({
23
- rootNavigationRef: { isReady: () => false },
24
- whenRootNavigationReady: () => {},
25
-}));
26
-vi.mock("../components/ui/Dialog", () => ({ alert: () => {} }));
27
-vi.mock("../features/prompt-links/prompt-link-actions", () => ({}));
28
-// Stores the prompt-link steps read only when a link carries a prompt; they load the native runtime.
29
-vi.mock("../state/projects", () => ({}));
30
-vi.mock("../state/pull-requests", () => ({}));
31
-vi.mock("../state/server", () => ({}));
32
-vi.mock("../state/threads", () => ({}));
33
-vi.mock("../state/use-composer-drafts", () => ({}));
34
-vi.mock("../state/workspace", () => ({}));
35
-vi.mock("../state/use-remote-environment-registry", () => ({ pairEnvironment: harness.pair }));
36
-vi.mock("../features/workspace/workspace-selection-store", () => ({
37
- settingsLinkPage: () => undefined,
38
- workspaceHasColumns: () => false,
39
-}));
40
-
41
-import { findLinkedRoute } from "./appLinking";
42
-import { getAppStateFromPath } from "./appLinkState";
43
-
44
-const PAIRING_URL = "http://192.168.1.10:3773/pair#token=abc";
45
-
46
-// RootStack imports every screen, which Node cannot load; these are its paths for the pairing form.
47
-const linking = {
48
- initialRouteName: "Home",
49
- screens: {
50
- Home: "",
51
- Settings: "settings",
52
- SettingsEnvironmentNew: "settings/environment-new",
53
- ConnectionsNew: "connections/new",
54
- },
55
-};
56
-
57
-it("a link cannot aim a pairing at a saved environment", () => {
58
- harness.pair.mockResolvedValue({ ok: false, error: null });
59
- for (const path of ["connections/new", "settings/environment-new"]) {
60
- harness.pair.mockClear();
61
- const state = getAppStateFromPath(
62
- `${path}?routeFor=victim&pairingUrl=${encodeURIComponent(PAIRING_URL)}&autoConnect=1`,
63
- linking,
64
- );
65
-
66
- expect(findLinkedRoute(state, ["ConnectionsNew", "SettingsEnvironmentNew"])?.params).toEqual({
67
- pairingUrl: PAIRING_URL,
68
- autoConnect: "1",
69
- });
70
- expect(harness.pair).toHaveBeenCalledExactlyOnceWith(PAIRING_URL);
71
- }
72
-});
apps/mobile/src/lib/appLinkState.ts
deleted
-27
@@ -1,27 +0,0 @@
1
-import { getStateFromPath } from "@react-navigation/native";
2
-
3
-import { startDevAutoConnect, withoutPairingTarget } from "../features/connection/devAutoConnect";
4
-import { takeNewTaskPromptLink } from "../features/prompt-links/newTaskPromptLink";
5
-import { takeThreadPromptLink } from "../features/prompt-links/threadPromptLink";
6
-import { takeScheduledTaskNewLink } from "../features/settings/scheduled-task-editor-state";
7
-import { restoreSettingsLinkState } from "../features/settings/settings-navigation";
8
-import { settingsLinkPage } from "../features/workspace/workspace-selection-store";
9
-import { restoreDraftLinkState } from "./appLinking";
10
-
11
-/** Parses an app link into navigation state, taking each link-owned side effect on the way. */
12
-export function getAppStateFromPath(path: string, options: Parameters<typeof getStateFromPath>[1]) {
13
- return takeScheduledTaskNewLink(
14
- startDevAutoConnect(
15
- withoutPairingTarget(
16
- takeNewTaskPromptLink(
17
- takeThreadPromptLink(
18
- restoreSettingsLinkState(
19
- restoreDraftLinkState(getStateFromPath(path, options), path),
20
- settingsLinkPage(),
21
- ),
22
- ),
23
- ),
24
- ),
25
- ),
26
- );
27
-}