Skip to content

Commit af0214f

Browse files
refactor(mobile): drop the unreachable pending-task editor from new-task drafts
Since #23467 a pending task on the home list opens as a Thread route, so nothing sets draft.pendingTaskId any more (no navigation, deep link, notification or URL producer). The new-task draft still carried a full editor for it: route param plumbing, begin/cancel/finish editing, a compare-and-swap write module, an outbox subscription to end stale edits, and an unmount flush. Remove that editor: state/pending-task-editor-writes.ts and its test, the pendingTaskId route param and Stack plumbing, and the editingPendingTask paths in NewTaskFlowProvider, NewTaskDraftScreen and NewTaskDraftRouteScreen. resolvePendingTaskInteractionMode loses the queued-mode fallback that only the editor used. NewTaskFlowProvider wraps the whole root stack and subscribed to the thread outbox only to notice a deleted in-edit task, so every outbox change re-rendered it. That subscription is gone. Effects removed (5): provider stale-edit effect, provider flush-ref effect, provider unmount flush; draft screen begin-editing effect and its cleanup effect. holdEditingQueuedMessage/releaseEditingQueuedMessage stay (home list delete and queued-message edit use them). Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent abf8f43 commit af0214f

8 files changed

Lines changed: 35 additions & 674 deletions

‎apps/mobile/src/Stack.tsx‎

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -509,16 +509,11 @@ function RootStackLayout(props: {
509509
);
510510
const draftRoute = props.state.routes.findLast((route) => route.name === "Thread");
511511
const draftParams = (
512-
draftRoute?.params as
513-
| { draft?: { draftId?: string | string[]; pendingTaskId?: string | string[] } }
514-
| undefined
512+
draftRoute?.params as { draft?: { draftId?: string | string[] } } | undefined
515513
)?.draft;
516514
const routeDraftId = Array.isArray(draftParams?.draftId)
517515
? draftParams.draftId[0]
518516
: draftParams?.draftId;
519-
const routePendingTaskId = Array.isArray(draftParams?.pendingTaskId)
520-
? draftParams.pendingTaskId[0]
521-
: draftParams?.pendingTaskId;
522517
useAgentNotificationNavigation(workspaceLocation.pathname);
523518
useConnectOnboardingNavigation();
524519
useAppShortcuts(props.state);
@@ -540,11 +535,7 @@ function RootStackLayout(props: {
540535
}, [navigation, pendingShare, props.state]);
541536

542537
return (
543-
<NewTaskFlowProvider
544-
active={isDraftThreadRoute(draftRoute)}
545-
routeDraftId={routeDraftId}
546-
routePendingTaskId={routePendingTaskId}
547-
>
538+
<NewTaskFlowProvider active={isDraftThreadRoute(draftRoute)} routeDraftId={routeDraftId}>
548539
<HardwareKeyboardCommandProvider pathname={pathname}>
549540
<ThreadOutboxDrainWorker />
550541
<ShowcaseCaptureCoordinator pathname={pathname} />

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ export function NewTaskDraftRouteScreen({ route }: StaticScreenProps<NewTaskDraf
4040
// oxlint-disable-next-line react/set-state-in-effect -- Draft reset runs once before first paint; initialized gates the screen until then.
4141
setInitialized(true);
4242
}, [reset]);
43-
const pendingTaskId = Array.isArray(params.pendingTaskId)
44-
? params.pendingTaskId[0]
45-
: params.pendingTaskId;
4643
const draftId = Array.isArray(params.draftId) ? params.draftId[0] : params.draftId;
4744
const projects = useProjects();
4845
const { state: catalogState } = useWorkspaceState();
@@ -75,7 +72,7 @@ export function NewTaskDraftRouteScreen({ route }: StaticScreenProps<NewTaskDraf
7572
);
7673
const environmentId = project?.environmentId;
7774
const workspaceRoot = project?.workspaceRoot;
78-
const needsPreparation = Boolean(initialProjectRef.branch && !pendingTaskId && !draftId);
75+
const needsPreparation = Boolean(initialProjectRef.branch && !draftId);
7976

8077
const [pendingCheckouts, setPendingCheckouts] = useState(0);
8178
const checkoutTail = useRef(Promise.resolve());
@@ -200,7 +197,6 @@ export function NewTaskDraftRouteScreen({ route }: StaticScreenProps<NewTaskDraf
200197
? params.incomingShareId[0]
201198
: params.incomingShareId
202199
}
203-
pendingTaskId={pendingTaskId}
204200
draftId={draftId}
205201
/>
206202
)}

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

Lines changed: 14 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ export function NewTaskDraftScreen(props: {
150150
readonly worktreePath?: string | null;
151151
readonly cloning?: boolean;
152152
};
153-
readonly pendingTaskId?: string;
154153
readonly draftId?: string;
155154
readonly incomingShareId?: string;
156155
}) {
@@ -386,11 +385,11 @@ export function NewTaskDraftScreen(props: {
386385
};
387386
}, []);
388387

389-
const { beginEditingPendingTask, cancelEditingPendingTask, editingPendingTask, openDraft } = flow;
388+
const { openDraft } = flow;
390389
// Cold launches load drafts and projects separately; wait for hydration and retry while shells load.
391390
const attemptedDraftIdRef = useRef<string | null>(null);
392391
useEffect(() => {
393-
if (!props.draftId || props.pendingTaskId) {
392+
if (!props.draftId) {
394393
return;
395394
}
396395
const draftId = props.draftId;
@@ -415,34 +414,12 @@ export function NewTaskDraftScreen(props: {
415414
return () => {
416415
cancelled = true;
417416
};
418-
}, [navigation, openDraft, projects, props.draftId, props.pendingTaskId]);
419-
420-
const attemptedPendingTaskIdRef = useRef<string | null>(null);
421-
useEffect(() => {
422-
if (!props.pendingTaskId || editingPendingTask?.messageId === props.pendingTaskId) {
423-
return;
424-
}
425-
if (attemptedPendingTaskIdRef.current === props.pendingTaskId) {
426-
return;
427-
}
428-
attemptedPendingTaskIdRef.current = props.pendingTaskId;
429-
if (!beginEditingPendingTask(props.pendingTaskId)) {
430-
navigation.dispatch(CommonActions.navigate("NewTaskProject"));
431-
}
432-
}, [beginEditingPendingTask, editingPendingTask?.messageId, navigation, props.pendingTaskId]);
433-
434-
useEffect(() => {
435-
if (!props.pendingTaskId) return;
436-
return () => {
437-
attemptedPendingTaskIdRef.current = null;
438-
cancelEditingPendingTask();
439-
};
440-
}, [props.pendingTaskId, cancelEditingPendingTask]);
417+
}, [navigation, openDraft, projects, props.draftId]);
441418

442419
const lastInitialProjectRefRef = useRef(props.initialProjectRef);
443420

444421
useEffect(() => {
445-
if (props.pendingTaskId || props.draftId) {
422+
if (props.draftId) {
446423
return;
447424
}
448425
if (lastInitialProjectRefRef.current !== props.initialProjectRef) {
@@ -516,9 +493,8 @@ export function NewTaskDraftScreen(props: {
516493
projects,
517494
flow.draftKey,
518495
props.initialProjectRef,
519-
// oxlint-disable-next-line react/exhaustive-effect-dependencies -- Opening a draft from a share, pending task, or draft id re-resolves its project.
496+
// oxlint-disable-next-line react/exhaustive-effect-dependencies -- Opening a draft from a share or draft id re-resolves its project.
520497
props.incomingShareId,
521-
props.pendingTaskId,
522498
props.draftId,
523499
navigation,
524500
selectedProject,
@@ -901,17 +877,7 @@ export function NewTaskDraftScreen(props: {
901877
return null;
902878
}
903879

904-
const editingPendingTask = flow.editingPendingTask;
905-
906-
const metadata = editingPendingTask
907-
? {
908-
threadId: editingPendingTask.threadId,
909-
commandId: editingPendingTask.commandId,
910-
messageId: editingPendingTask.messageId,
911-
createdAt: editingPendingTask.createdAt,
912-
}
913-
: creationMetadata;
914-
const message = flow.buildPendingTaskMessage(metadata, {
880+
const message = flow.buildPendingTaskMessage(creationMetadata, {
915881
currentCheckoutBranch: queuesInsteadOfStarting ? null : flow.currentCheckoutBranchName,
916882
});
917883
if (!message) {
@@ -939,17 +905,13 @@ export function NewTaskDraftScreen(props: {
939905
// would otherwise resurrect this draft.
940906
abortComposerDraftOperations(draftKey);
941907
const draftSnapshot = getComposerDraftSnapshot(draftKey);
942-
if (editingPendingTask) {
943-
flow.finishEditingPendingTask();
944-
} else {
945-
// The queued message owns the attachments now, so the sweep is deferred
946-
// until the write confirms it.
947-
clearComposerDraftContent(draftKey, {
948-
clearModelSelection: true,
949-
clearWorkspaceSelection: true,
950-
deferAttachmentCleanup: true,
951-
});
952-
}
908+
// The queued message owns the attachments now, so the sweep is deferred
909+
// until the write confirms it.
910+
clearComposerDraftContent(draftKey, {
911+
clearModelSelection: true,
912+
clearWorkspaceSelection: true,
913+
deferAttachmentCleanup: true,
914+
});
953915
scheduleUnusedComposerAttachmentCleanup(draftSnapshot.attachments);
954916
return message.messageId;
955917
}
@@ -1146,7 +1108,7 @@ export function NewTaskDraftScreen(props: {
11461108
const thread = draftThreadShell({
11471109
environmentId: selectedProject.environmentId,
11481110
projectId: selectedProject.id,
1149-
threadId: ThreadId.make(flow.editingPendingTask?.threadId ?? creationMetadata.threadId),
1111+
threadId: ThreadId.make(creationMetadata.threadId),
11501112
modelSelection: flow.selectedModel,
11511113
runtimeMode: flow.runtimeMode,
11521114
interactionMode: flow.interactionMode,

0 commit comments

Comments
 (0)