The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 21:00 UTC
fix(mobile): choosing a project for a draft whose project is gone keeps the draft (#26800)
Julius Marminge committed
Nov 11, 2026 at 17:36 UTC
a21b43fc70fe1c835dc817cb0281befbea95a58c
7 files changed
+94
-15
apps/mobile/src/features/threads/NewTaskDraftScreen.tsx
+13
-5
@@ -281,11 +281,15 @@ export function NewTaskDraftScreen(props: {
281
),
282
);
283
// A route naming a draft that is gone, or whose project is gone, also
284
- // returns to the picker.
285
- const isRouteDraftMissing =
286
- props.draftId !== undefined && flow.missingRouteDraftId === props.draftId;
284
+ // returns to the picker; a draft that survives goes along with it.
285
+ const unopenableRouteDraftKind =
286
+ props.draftId !== undefined && flow.unopenableRouteDraft?.draftId === props.draftId
287
+ ? flow.unopenableRouteDraft.kind
288
+ : null;
289
+ const pickerDraftId = unopenableRouteDraftKind === "pickProject" ? props.draftId : undefined;
290
const isProjectPickerReturnActive =
288
- (isReturningToProjectPicker && !requestedInitialProjectAvailable) || isRouteDraftMissing;
291
+ (isReturningToProjectPicker && !requestedInitialProjectAvailable) ||
292
+ unopenableRouteDraftKind !== null;
293
const isIncomingShareAwaitingServerConfig = Boolean(
294
incomingShare?.attachments.some((attachment) => attachment.type === "file") &&
295
selectedEnvironmentServerConfig === null,
@@ -388,7 +392,10 @@ export function NewTaskDraftScreen(props: {
392
// Wait for usePreventRemove to disable before replacing, or the transfer guard swallows the fallback.
393
const frame = requestAnimationFrame(() => {
394
navigation.dispatch(
391
- StackActions.replace("NewTaskProject", { incomingShareId: props.incomingShareId }),
395
+ StackActions.replace("NewTaskProject", {
396
+ incomingShareId: props.incomingShareId,
397
+ draftId: pickerDraftId,
398
+ }),
399
);
400
});
401
return () => cancelAnimationFrame(frame);
@@ -396,6 +403,7 @@ export function NewTaskDraftScreen(props: {
403
isProjectPickerReturnActive,
404
isReturningToProjectPicker,
405
navigation,
406
+ pickerDraftId,
407
props.incomingShareId,
408
requestedInitialProjectAvailable,
409
]);
apps/mobile/src/features/threads/NewTaskRouteScreen.tsx
+24
-1
@@ -29,6 +29,7 @@ import { ProjectFavicon } from "../../components/ProjectFavicon";
29
import { useProjects, useServerConfigs } from "../../state/entities";
30
import { projectEnvironment } from "../../state/projects";
31
import { useAtomCommand } from "../../state/use-atom-command";
32
+import { retargetSavedNewTaskDraft } from "../../state/use-composer-drafts";
33
import { useRemoteConnectionStatus } from "../../state/use-remote-environment-registry";
34
import type { WorkspaceState } from "../../state/workspaceModel";
35
import { useWorkspaceState } from "../../state/workspace";
@@ -44,6 +45,8 @@ import { useSelectWorkspaceDetail } from "../layout/workspace/useSelectWorkspace
45
46
type NewTaskRouteParams = {
47
readonly incomingShareId?: string | string[];
48
+ /** An existing draft whose project is gone; the chosen project takes it over. */
49
+ readonly draftId?: string | string[];
50
readonly prompt?: string | string[];
51
readonly repo?: string | string[];
52
readonly pr?: string | string[];
@@ -164,6 +167,9 @@ export function NewTaskRouteScreen({ route }: StaticScreenProps<NewTaskRoutePara
167
? route.params.incomingShareId[0]
168
: route.params?.incomingShareId;
169
const incomingShare = routeShareId ? getShare(routeShareId) : null;
170
+ const routeDraftId = Array.isArray(route.params?.draftId)
171
+ ? route.params.draftId[0]
172
+ : route.params?.draftId;
173
const incomingShareSubtitle = incomingShare
174
? incomingShare.attachments.length === 0
175
? "Choose a project for what you shared"
@@ -228,17 +234,34 @@ export function NewTaskRouteScreen({ route }: StaticScreenProps<NewTaskRoutePara
234
: navigation.getParent();
235
const rootState = root?.getState();
236
const threadRoute = rootState?.routes[rootState.index - 1];
231
- if (isDraftThreadRoute(threadRoute)) {
237
+ if (routeDraftId === undefined && isDraftThreadRoute(threadRoute)) {
238
setProject(project);
239
root?.goBack();
240
return;
241
}
242
+ // Restamp only on choice, so backing out leaves the draft as it was.
243
+ const retargeted =
244
+ routeDraftId === undefined
245
+ ? false
246
+ : await retargetSavedNewTaskDraft(routeDraftId, {
247
+ environmentId: project.environmentId,
248
+ projectId: project.id,
249
+ }).then(
250
+ (found) => found,
251
+ () => null,
252
+ );
253
+ if (retargeted === null) {
254
+ Dialog.alert("Could not change project", "Saved drafts could not be loaded. Try again.");
255
+ return;
256
+ }
257
+ const draftId = retargeted ? routeDraftId : undefined;
258
selectDetail({
259
name: "Thread",
260
params: {
261
draft: {
262
environmentId: String(project.environmentId),
263
projectId: String(project.id),
264
+ draftId,
265
incomingShareId: incomingShare?.id,
266
},
267
},
apps/mobile/src/features/threads/new-task-flow-provider.tsx
+12
-6
@@ -168,11 +168,14 @@ type NewTaskFlowContextValue = {
168
/** The flow's project, read when a continuation resumes after an await. */
169
readonly getSelectedProjectKey: () => string | null;
170
/**
171
- * The draft id of the route this flow serves when that draft, or its
172
- * project, is gone. Only the topmost draft route is served, so a screen
173
- * compares this with its own draft id.
171
+ * The route this flow serves when its draft cannot open: the draft is gone
172
+ * (`missing`) or only its project is (`pickProject`). Only the topmost draft
173
+ * route is served, so a screen compares `draftId` with its own draft id.
174
*/
175
- readonly missingRouteDraftId: string | null;
175
+ readonly unopenableRouteDraft: {
176
+ readonly draftId: string;
177
+ readonly kind: "missing" | "pickProject";
178
+ } | null;
179
readonly selectEnvironment: (environmentId: EnvironmentId) => void;
180
readonly switchEnvironment: (environmentId: EnvironmentId) => Promise<boolean>;
181
readonly switchingToEnvironmentId: EnvironmentId | null;
@@ -851,8 +854,11 @@ export function NewTaskFlowProvider(
854
providerGroups,
855
setProject,
856
getSelectedProjectKey: () => readFlow().projectKey,
854
- missingRouteDraftId:
855
- routeDraftResolution.kind === "missing" ? (props.routeDraftId ?? null) : null,
857
+ unopenableRouteDraft:
858
+ props.routeDraftId !== undefined &&
859
+ (routeDraftResolution.kind === "missing" || routeDraftResolution.kind === "pickProject")
860
+ ? { draftId: props.routeDraftId, kind: routeDraftResolution.kind }
861
+ : null,
862
selectEnvironment,
863
switchEnvironment,
864
switchingToEnvironmentId,
apps/mobile/src/features/threads/new-task-flow-state.test.ts
+5
-2
@@ -111,11 +111,14 @@ describe("resolveRouteDraft", () => {
111
).toMatchObject({ kind: "open", flow: { environmentId: environmentB } });
112
});
113
114
- it("reports a draft that is gone or whose project is gone", () => {
114
+ it("reports a draft that is gone", () => {
115
expect(resolveRouteDraft({ ...base, stamp: undefined })).toEqual({ kind: "missing" });
116
+ });
117
+
118
+ it("asks for a project for the same draft when its project is gone", () => {
119
expect(
120
resolveRouteDraft({ ...base, projects: [{ environmentId, id: ProjectId.make("other") }] }),
118
- ).toEqual({ kind: "missing" });
121
+ ).toEqual({ kind: "pickProject" });
122
});
123
});
124
apps/mobile/src/features/threads/new-task-flow-state.ts
+4
-1
@@ -75,6 +75,8 @@ export type RouteDraftResolution =
75
| { readonly kind: "none" }
76
| { readonly kind: "pending" }
77
| { readonly kind: "missing" }
78
+ /** The draft survives but its project is gone: pick another for it. */
79
+ | { readonly kind: "pickProject" }
80
| { readonly kind: "open"; readonly flow: NewTaskFlowState };
81
82
export function resolveRouteDraft(input: {
@@ -101,7 +103,8 @@ export function resolveRouteDraft(input: {
103
const loaded = input.projects.some(
104
(project) => project.environmentId === stamp.environmentId && project.id === stamp.projectId,
105
);
104
- if (!loaded) return input.stampedEnvironmentLoading ? { kind: "pending" } : { kind: "missing" };
106
+ if (!loaded)
107
+ return input.stampedEnvironmentLoading ? { kind: "pending" } : { kind: "pickProject" };
108
return {
109
kind: "open",
110
flow: {
apps/mobile/src/state/use-composer-drafts.test.ts
+25
@@ -205,6 +205,7 @@ import {
205
restoreComposerDraftSnapshotState,
206
restoreCloudComposerDrafts,
207
retargetNewTaskDraft,
208
+ retargetSavedNewTaskDraft,
209
setComposerDraftText,
210
insertComposerDraftContext,
211
insertComposerDraftText,
@@ -1933,6 +1934,30 @@ describe("mobile composer drafts", () => {
1934
expect(findNewTaskDraftKeys(appAtomRegistry.get(composerDraftsAtom), to)).toEqual([key]);
1935
});
1936
1937
+ it("retargets a saved new-task draft only after drafts load", async () => {
1938
+ const from = {
1939
+ environmentId: EnvironmentId.make("environment-1"),
1940
+ projectId: ProjectId.make("project-1"),
1941
+ };
1942
+ const to = {
1943
+ environmentId: EnvironmentId.make("environment-1"),
1944
+ projectId: ProjectId.make("project-2"),
1945
+ };
1946
+ const key = createNewTaskDraft(from);
1947
+ setComposerDraftText(key, "kept through a cold start");
1948
+ await flushComposerDrafts();
1949
+ appAtomRegistry.set(composerDraftsAtom, {});
1950
+ resetComposerDraftsLoadState();
1951
+
1952
+ await expect(retargetSavedNewTaskDraft(key, to)).resolves.toBe(true);
1953
+ expect(getComposerDraftSnapshot(key)).toMatchObject({
1954
+ text: "kept through a cold start",
1955
+ project: to,
1956
+ });
1957
+ await expect(retargetSavedNewTaskDraft(`${key}-gone`, to)).resolves.toBe(false);
1958
+ expect(appAtomRegistry.get(composerDraftsAtom)[`${key}-gone`]).toBeUndefined();
1959
+ });
1960
+
1961
it("merges persisted option memory without replacing newer choices", async () => {
1962
composerDraftFileMocks.setDocument({
1963
schemaVersion: 1,
apps/mobile/src/state/use-composer-drafts.ts
+11
@@ -1999,6 +1999,17 @@ export function retargetNewTaskDraft(
1999
});
2000
}
2001
2002
+/** Retargets a saved draft once drafts load; an absent one is not created. */
2003
+export async function retargetSavedNewTaskDraft(
2004
+ draftKey: string,
2005
+ project: { readonly environmentId: EnvironmentId; readonly projectId: ProjectId },
2006
+): Promise<boolean> {
2007
+ await waitForComposerDraftsLoaded();
2008
+ if (appAtomRegistry.get(composerDraftsAtom)[draftKey] === undefined) return false;
2009
+ retargetNewTaskDraft(draftKey, project);
2010
+ return true;
2011
+}
2012
+
2013
export function findNewTaskDraftKeys(
2014
drafts: Readonly<Record<string, ComposerDraft>>,
2015
project: { readonly environmentId: EnvironmentId; readonly projectId: ProjectId },