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 23, 01:45 UTC
fix(mobile): a file shared into a new task shows in the composer before you send (#21659)
Co-authored-by: PR Batch Tester <agent@local.test> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
shivam committed
Oct 19, 2026 at 19:18 UTC
5307c233b1f0ae72b8894dd39d94019aaf9e7cb8
2 files changed
+61
-10
apps/mobile/src/state/use-composer-drafts.test.ts
+42
-1
@@ -148,7 +148,10 @@ vi.mock("../features/sharing/incoming-share-storage", () => ({
148
}));
149
150
import type { DraftComposerAttachment } from "../lib/composerImages";
151
-import { formatComposerContextReference } from "@t3tools/shared/composerContextReferences";
151
+import {
152
+ collectComposerContextReferences,
153
+ formatComposerContextReference,
154
+} from "@t3tools/shared/composerContextReferences";
155
import { appAtomRegistry } from "./atom-registry";
156
import { threadOutboxManager } from "./thread-outbox";
157
import {
@@ -2304,6 +2307,44 @@ describe("mobile composer drafts", () => {
2307
expect(mergeComposerDraftContentState(edited, draftKey, content)).toBe(edited);
2308
});
2309
2310
+ it("shows a shared non-image file as a composer chip", () => {
2311
+ const draftKey = "new-task:environment-1:project-1";
2312
+ const sharedFile = {
2313
+ id: "share-1:file:0",
2314
+ type: "file" as const,
2315
+ name: "backup.json",
2316
+ mimeType: "application/json",
2317
+ sizeBytes: 41,
2318
+ fileUri: "file:///documents/backup.json",
2319
+ };
2320
+
2321
+ const existingFile = { ...sharedFile, id: "existing-file", name: "notes.txt" };
2322
+
2323
+ const merged = mergeComposerDraftContentState(
2324
+ { [draftKey]: { text: "", attachments: [existingFile] } },
2325
+ draftKey,
2326
+ { text: "", attachments: [sharedFile], sourceShareId: "share-1" },
2327
+ )[draftKey]!;
2328
+
2329
+ expect(merged.attachments).toEqual([existingFile, sharedFile]);
2330
+ const references = collectComposerContextReferences(merged.text);
2331
+ expect(references).toHaveLength(1);
2332
+ expect(merged.context?.records).toEqual([
2333
+ expect.objectContaining({
2334
+ kind: "file",
2335
+ contextId: references[0]!.contextId,
2336
+ attachmentId: sharedFile.id,
2337
+ }),
2338
+ ]);
2339
+
2340
+ // A recovery merge carries its own text; a chip appended to it would
2341
+ // break the duplicate-text check when the merge is retried.
2342
+ const recovered = { text: "Retry this", attachments: [sharedFile] };
2343
+ const once = mergeComposerDraftContentState({}, draftKey, recovered);
2344
+ expect(once[draftKey]?.text).toBe("Retry this");
2345
+ expect(mergeComposerDraftContentState(once, draftKey, recovered)).toBe(once);
2346
+ });
2347
+
2348
it("preserves existing images when shared content exceeds the draft attachment limit", () => {
2349
const draftKey = "new-task:environment-1:project-1";
2350
const image = (id: string) => ({
apps/mobile/src/state/use-composer-drafts.ts
+19
-9
@@ -489,7 +489,10 @@ function attachmentContextRecord(
489
: { ...common, kind: "file" as const };
490
}
491
492
-function restoreMissingComposerFileReferences(draft: ComposerDraft): ComposerDraft {
492
+function restoreMissingComposerFileReferences(
493
+ draft: ComposerDraft,
494
+ attachments = draft.attachments,
495
+): ComposerDraft {
496
const records = [...(draft.context?.records ?? [])];
497
const usedIds = new Set<string>(records.map((record) => record.contextId));
498
const referenced = new Set(
@@ -499,7 +502,7 @@ function restoreMissingComposerFileReferences(draft: ComposerDraft): ComposerDra
502
);
503
let text = draft.text;
504
let changed = false;
502
- for (const attachment of draft.attachments) {
505
+ for (const attachment of attachments) {
506
if (
507
attachment.type === "image" ||
508
imageMimeType(attachment) !== null ||
@@ -1578,13 +1581,20 @@ export function mergeComposerDraftContentState(
1581
}
1582
return {
1583
...current,
1581
- [draftKey]: {
1582
- ...existing,
1583
- text,
1584
- attachments,
1585
- context,
1586
- ...(importedShareIds ? { importedShareIds } : {}),
1587
- },
1584
+ // The composer shows non-image files only as inline chips, so a shared file
1585
+ // merged without one would be attached but invisible until sent. Other
1586
+ // merges carry their own text, and appending chips to it would defeat
1587
+ // mergeComposerDraftText's duplicate check on a retried merge.
1588
+ [draftKey]: restoreMissingComposerFileReferences(
1589
+ {
1590
+ ...existing,
1591
+ text,
1592
+ attachments,
1593
+ context,
1594
+ ...(importedShareIds ? { importedShareIds } : {}),
1595
+ },
1596
+ content.sourceShareId ? attachments.slice(existing.attachments.length) : [],
1597
+ ),
1598
};
1599
}
1600