@devries-cameron20 / t3code-1 / commits / 25c06e571e
Fork 0

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

fix(mobile): iPad reopens agent-started threads after a restart (#31260)

Julius Marminge committed Nov 16, 2026 at 17:14 UTC 25c06e571e36731b274f1141ea7835ae8bb37b4e
2 files changed +82 -3
apps/mobile/src/features/layout/workspace/workspace-selection-store.test.ts new
+80
@@ -0,0 +1,80 @@
1 +import * as NodeModule from "node:module";
2 +import { expect, it, vi } from "vite-plus/test";
3 +
4 +const requireFromNative = NodeModule.createRequire(
5 + NodeModule.createRequire(import.meta.url).resolve("@react-navigation/native/package.json"),
6 +);
7 +const { getStateFromPath } = requireFromNative("@react-navigation/core") as {
8 + readonly getStateFromPath: typeof import("@react-navigation/native").getStateFromPath;
9 +};
10 +
11 +const ENVIRONMENT_ID = "environment-1";
12 +const MCP_THREAD_ID = "mcp:7b5c0f3e-2a41-4c8e-9d6b-1f2e3a4b5c6d";
13 +
14 +vi.mock("react-native", () => ({
15 + AppState: { addEventListener: vi.fn() },
16 + Dimensions: { get: () => ({ width: 1180, height: 820 }) },
17 + Platform: { OS: "ios" },
18 +}));
19 +// The real createURL, configured as a development build with the dev scheme.
20 +const expoLinking = await vi.hoisted(async () => {
21 + const { createRequire } = await import("node:module");
22 + const packageJson = createRequire(import.meta.url).resolve("expo-linking/package.json");
23 + return {
24 + createURL: packageJson.replace(/package\.json$/, "build/createURL.js"),
25 + modulesCore: createRequire(packageJson).resolve("expo-modules-core"),
26 + };
27 +});
28 +vi.mock(expoLinking.modulesCore, () => ({
29 + Platform: { select: (options: { readonly ios?: unknown }) => options.ios },
30 +}));
31 +vi.mock("expo-constants", () => ({
32 + default: { executionEnvironment: "bare", expoConfig: { scheme: "t3code-dev" } },
33 + ExecutionEnvironment: { Bare: "bare", Standalone: "standalone", StoreClient: "storeClient" },
34 +}));
35 +vi.mock("expo/internal/bundle-origin", () => ({ getBundleOrigin: () => null }));
36 +vi.mock("expo-linking", () => import(expoLinking.createURL));
37 +vi.mock("../../../persistence/imperative", () => ({
38 + loadPreferences: async () => ({
39 + workspaceSelections: { threads: { environmentId: ENVIRONMENT_ID, threadId: MCP_THREAD_ID } },
40 + }),
41 + savePreferencesPatch: async () => undefined,
42 +}));
43 +vi.mock("../../../native/native-layout-metrics", () => ({
44 + currentNativeLayoutMetrics: () => null,
45 + firstNativeLayoutMetrics: async () => null,
46 +}));
47 +vi.mock("../../../native/NativeWorkspaceColumns", () => ({
48 + NATIVE_METRICS_TIMEOUT_MS: 0,
49 + nativeWorkspaceColumnsSupportedFor: () => true,
50 +}));
51 +vi.mock("../../../lib/layout", () => ({ deriveLayout: () => ({ usesSplitView: true }) }));
52 +// The environment catalog and the chat's snapshot have not loaded yet, as on a cold start.
53 +vi.mock("../../../connection/catalog", () => ({
54 + environmentCatalog: { catalogValueAtom: { isReady: false } },
55 +}));
56 +vi.mock("../../../state/presentation", () => ({ environmentPresentations: {} }));
57 +vi.mock("../../../state/atom-registry", () => ({
58 + appAtomRegistry: { get: (atom: unknown) => atom },
59 +}));
60 +vi.mock("../../../state/threads", () => ({
61 + environmentThreadShells: {},
62 + startOpeningEnvironmentThread: vi.fn(),
63 + threadEnvironment: { snapshotAtom: () => undefined },
64 +}));
65 +
66 +import { launchWorkspaceURL } from "./workspace-selection-store";
67 +
68 +it("reopens a remembered chat whose id has reserved characters at that same chat", async () => {
69 + const url = await launchWorkspaceURL();
70 + expect(url).not.toBeNull();
71 +
72 + const state = getStateFromPath(url!.replace(/^t3code-dev:\/\//, ""), {
73 + screens: { Thread: "threads/:environmentId/:threadId" },
74 + });
75 +
76 + expect(state?.routes.at(-1)).toMatchObject({
77 + name: "Thread",
78 + params: { environmentId: ENVIRONMENT_ID, threadId: MCP_THREAD_ID },
79 + });
80 +});
apps/mobile/src/features/layout/workspace/workspace-selection-store.ts
+2 -3
@@ -153,9 +153,8 @@ export async function launchWorkspaceURL(): Promise<string | null> {
153 }
154 await metrics;
155 if (!thread || !workspaceHasColumns() || !workspaceSelectionCheck.thread(thread)) return null;
156 - return Linking.createURL(
157 - `threads/${encodeURIComponent(thread.environmentId)}/${encodeURIComponent(thread.threadId)}`,
158 - );
156 + // createURL runs encodeURI over its path, which would encode each segment a second time.
157 + return `${Linking.createURL("/")}threads/${encodeURIComponent(thread.environmentId)}/${encodeURIComponent(thread.threadId)}`;
158 }
159
160 /** Whether the workspace shows its first detail page, directly above its list. */