@devries-cameron20 / t3code-1 / commits / 0f50b5f66d
Fork 0

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

fix(mobile): deleting a thread clears its unsent draft (#29564)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>

Alex Southwell committed Nov 15, 2026 at 02:18 UTC 0f50b5f66debd5d6949d470b9e34b7e83d43956c
2 files changed +37 -5
apps/mobile/src/features/home/useThreadListActions.test.ts
+35 -5
@@ -21,6 +21,7 @@ const state = vi.hoisted(() => ({
21 failedAction: null as string | null,
22 titleOutcome: null as ThreadTitleRegenerationOutcome | null,
23 archivedRefreshes: [] as string[],
24 + onArchivedRefresh: undefined as (() => void) | undefined,
25 scopes: new Map<string, Set<string>>(),
26 shells: [] as EnvironmentThreadShell[],
27 requests: [] as {
@@ -59,6 +60,7 @@ vi.mock("../../components/ui/Dialog", () => ({
60 vi.mock("../archive/useArchivedThreadSnapshots", () => ({
61 refreshArchivedThreadsForEnvironment: (environmentId: string) => {
62 state.archivedRefreshes.push(environmentId);
63 + state.onArchivedRefresh?.();
64 },
65 }));
66 vi.mock("../../state/session", () => ({
@@ -71,8 +73,9 @@ vi.mock("../../state/presentation", () => ({
73 vi.mock("../../state/server", () => ({
74 environmentServerConfigsAtom: "server-configs",
75 }));
74 -vi.mock("../../state/atom-registry", () => ({
75 - appAtomRegistry: {
76 +vi.mock("../../state/atom-registry", async () => {
77 + const registry = (await import("effect/reactivity")).AtomRegistry.make();
78 + const stub = {
79 set: (_atom: string, value: boolean) => {
80 state.dropBusy = value;
81 },
@@ -103,8 +106,21 @@ vi.mock("../../state/atom-registry", () => ({
106 },
107 ]),
108 ),
106 - },
107 -}));
109 + };
110 + // Real atoms such as composerDraftsAtom go to a real registry; strings are stubbed state.
111 + return {
112 + appAtomRegistry: {
113 + get: (atom: unknown) =>
114 + typeof atom === "string"
115 + ? stub.get(atom)
116 + : registry.get(atom as Parameters<typeof registry.get>[0]),
117 + set: (atom: unknown, value: unknown) =>
118 + typeof atom === "string"
119 + ? stub.set(atom, value as boolean)
120 + : registry.set(atom as Parameters<typeof registry.set>[0], value),
121 + },
122 + };
123 +});
124 vi.mock("../../state/use-atom-command", () => ({
125 useAtomCommand: (command: unknown) => command,
126 }));
@@ -164,6 +180,8 @@ vi.mock("../../state/threads", () => ({
180 ),
181 }));
182
183 +import { appAtomRegistry } from "../../state/atom-registry";
184 +import { composerDraftsAtom } from "../../state/use-composer-drafts";
185 import { dismissThreadUndoNotice, readThreadUndoNotice } from "./thread-undo-notice";
186 import { useThreadListActions } from "./useThreadListActions";
187
@@ -197,6 +215,7 @@ beforeEach(() => {
215 state.failedAction = null;
216 state.titleOutcome = null;
217 state.archivedRefreshes = [];
218 + state.onArchivedRefresh = undefined;
219 state.pendingOrder = null;
220 state.dropBusy = false;
221 state.holdingRows = false;
@@ -250,7 +269,9 @@ describe("thread list operation permissions", () => {
269 expect(state.requests).toEqual([]);
270 });
271
253 - it("rechecks permission after a retained delete confirmation", async () => {
272 + it("rechecks permission after a retained delete confirmation, then clears the draft", async () => {
273 + const draft = { text: "unsent", attachments: [] };
274 + appAtomRegistry.set(composerDraftsAtom, { "primary:thread": draft, "primary:other": draft });
275 useThreadListActions().confirmDeleteThread(makeThread());
276 const confirm = state.dialogs[0]?.onConfirm;
277 expect(confirm).toBeTypeOf("function");
@@ -259,6 +280,15 @@ describe("thread list operation permissions", () => {
280 await confirm!();
281
282 expect(state.requests).toEqual([]);
283 + expect(Object.keys(appAtomRegistry.get(composerDraftsAtom))).toContain("primary:thread");
284 +
285 + state.scopes.get(primaryEnvironmentId)!.add(AuthOrchestrationOperateScope);
286 + const deleted = new Promise<void>((resolve) => (state.onArchivedRefresh = resolve));
287 + confirm!();
288 + await deleted;
289 +
290 + expect(state.requests).toEqual([expect.objectContaining({ action: "delete" })]);
291 + expect(Object.keys(appAtomRegistry.get(composerDraftsAtom))).toEqual(["primary:other"]);
292 });
293 });
294
apps/mobile/src/features/home/useThreadListActions.ts
+2
@@ -17,6 +17,7 @@ import { appAtomRegistry } from "../../state/atom-registry";
17 import { environmentServerConfigsAtom } from "../../state/server";
18 import { connectedEnvironmentIdsAtom } from "../../state/presentation";
19 import { readEnvironmentScope } from "../../state/session";
20 +import { clearComposerDraft } from "../../state/use-composer-drafts";
21 import {
22 environmentThreadShells,
23 steadyNavigationThreadShellsAtom,
@@ -180,6 +181,7 @@ function useThreadActionExecutor(
181 if (action === "archive" || action === "unarchive" || action === "delete") {
182 refreshArchivedThreadsForEnvironment(thread.environmentId);
183 }
184 + if (action === "delete") clearComposerDraft(key);
185 onCompleted?.(action, thread);
186 return true;
187 })();