Skip to content

Commit 1f49c48

Browse files
fix(mobile): draft routes return to the picker only for their own missing draft
- The provider now names the route draft it found missing, and a draft screen returns to the picker only when that is its own draft. A covered draft route no longer reads the topmost route's missing state. - The picker-return effect again clears the return flag once the requested project arrives, as on main. - composerDraftsLoadedAtom is a plain read of hydration state. Hydration starts at app start with the attachment upload worker, and a failed load is retried by the next ensureComposerDraftsLoaded caller (the draft route's useComposerDraft mount, draft edits, outbox delivery). Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 74420b4 commit 1f49c48

3 files changed

Lines changed: 22 additions & 18 deletions

File tree

‎apps/mobile/src/features/threads/NewTaskDraftScreen.tsx‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,10 @@ export function NewTaskDraftScreen(props: {
276276
);
277277
// A route naming a draft that is gone, or whose project is gone, also
278278
// returns to the picker.
279+
const isRouteDraftMissing =
280+
props.draftId !== undefined && flow.missingRouteDraftId === props.draftId;
279281
const isProjectPickerReturnActive =
280-
(isReturningToProjectPicker && !requestedInitialProjectAvailable) || flow.routeTargetMissing;
282+
(isReturningToProjectPicker && !requestedInitialProjectAvailable) || isRouteDraftMissing;
281283
const isIncomingShareAwaitingServerConfig = Boolean(
282284
incomingShare?.attachments.some((attachment) => attachment.type === "file") &&
283285
selectedEnvironmentServerConfig === null,
@@ -369,12 +371,11 @@ export function NewTaskDraftScreen(props: {
369371
isIncomingShareUnavailable;
370372
const appliedInitialProjectKeyRef = useRef<string | null>(null);
371373
useEffect(() => {
372-
if (!isProjectPickerReturnActive) {
373-
return;
374-
}
375374
if (isReturningToProjectPicker && requestedInitialProjectAvailable) {
376375
// oxlint-disable-next-line react/set-state-in-effect -- Ends the return-to-picker flow once the requested project arrives from the catalog.
377376
setIsReturningToProjectPicker(false);
377+
}
378+
if (!isProjectPickerReturnActive) {
378379
return;
379380
}
380381
// Wait for usePreventRemove to disable before replacing, or the transfer guard swallows the fallback.

‎apps/mobile/src/features/threads/new-task-flow-provider.tsx‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,14 @@ type NewTaskFlowContextValue = {
164164
readonly selectedProviderStatus: ServerProvider | null;
165165
readonly providerGroups: ReadonlyArray<ProviderGroup>;
166166
readonly setProject: (project: EnvironmentProject) => void;
167-
/** Returns false if the existing draft is gone, allowing fallback to a fresh draft. */
168167
/** The flow's project, read when a continuation resumes after an await. */
169168
readonly getSelectedProjectKey: () => string | null;
170-
/** The route names a draft that is gone, or whose project is gone. */
171-
readonly routeTargetMissing: boolean;
169+
/**
170+
* The draft id of the route this flow serves when that draft, or its
171+
* project, is gone. Only the topmost draft route is served, so a screen
172+
* compares this with its own draft id.
173+
*/
174+
readonly missingRouteDraftId: string | null;
172175
readonly selectEnvironment: (environmentId: EnvironmentId) => void;
173176
readonly switchEnvironment: (environmentId: EnvironmentId) => Promise<boolean>;
174177
readonly switchingToEnvironmentId: EnvironmentId | null;
@@ -833,7 +836,8 @@ export function NewTaskFlowProvider(
833836
providerGroups,
834837
setProject,
835838
getSelectedProjectKey: () => readFlow().projectKey,
836-
routeTargetMissing: routeDraftResolution.kind === "missing",
839+
missingRouteDraftId:
840+
routeDraftResolution.kind === "missing" ? (props.routeDraftId ?? null) : null,
837841
selectEnvironment,
838842
switchEnvironment,
839843
switchingToEnvironmentId,

‎apps/mobile/src/state/use-composer-drafts.ts‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -471,17 +471,16 @@ export const composerDraftsAtom = Atom.make<Record<string, ComposerDraft>>({}).p
471471
Atom.withLabel("mobile:composer-drafts"),
472472
);
473473

474-
const composerDraftsHydratedAtom = Atom.make(false).pipe(
474+
/**
475+
* Whether persisted drafts have merged in. Hydration starts with the app's
476+
* attachment upload worker; a failed load stays false until the next
477+
* `ensureComposerDraftsLoaded` caller retries it.
478+
*/
479+
export const composerDraftsLoadedAtom = Atom.make(false).pipe(
475480
Atom.keepAlive,
476-
Atom.withLabel("mobile:composer-drafts-hydrated"),
481+
Atom.withLabel("mobile:composer-drafts-loaded"),
477482
);
478483

479-
/** Whether persisted drafts have merged in; reading it starts hydration. */
480-
export const composerDraftsLoadedAtom = Atom.make((get) => {
481-
ensureComposerDraftsLoaded();
482-
return get(composerDraftsHydratedAtom);
483-
}).pipe(Atom.withLabel("mobile:composer-drafts-loaded"));
484-
485484
export const stickyComposerModelSelectionAtom = Atom.make<ModelSelection | null>(null).pipe(
486485
Atom.keepAlive,
487486
Atom.withLabel("mobile:sticky-composer-model-selection"),
@@ -518,7 +517,7 @@ const persistenceQueue = new SerializedAsyncQueue();
518517

519518
export function resetComposerDraftsLoadState(): void {
520519
loadPromise = null;
521-
appAtomRegistry.set(composerDraftsHydratedAtom, false);
520+
appAtomRegistry.set(composerDraftsLoadedAtom, false);
522521
persistRetryNeeded = false;
523522
}
524523

@@ -1051,7 +1050,7 @@ export function ensureComposerDraftsLoaded(): void {
10511050
),
10521051
});
10531052
}
1054-
appAtomRegistry.set(composerDraftsHydratedAtom, true);
1053+
appAtomRegistry.set(composerDraftsLoadedAtom, true);
10551054
});
10561055
loadPromise = loading;
10571056
void loading.catch((cause) => {

0 commit comments

Comments
 (0)