Skip to content

Commit 9f45806

Browse files
ahalekellyclaude
andcommitted
fix(mobile): a photo removed during processing stays removed
Append the kept attachments before any await, so a removal can't land between the pending check and the append, and release removed picks in the background. The picker's free slots also count photos still processing from an earlier pick. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 8e13841 commit 9f45806

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

‎apps/mobile/src/state/use-composer-attachment-actions.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
countComposerDraftAttachmentsAfterSelection,
1919
getComposerDraftSnapshot,
2020
composerPendingMediaAtom,
21-
releaseUnusedComposerAttachmentFiles,
21+
scheduleUnusedComposerAttachmentCleanup,
2222
addComposerPendingMedia,
2323
removeComposerPendingMedia,
2424
type ComposerDraftInsertion,
@@ -70,7 +70,9 @@ export function useComposerAttachmentActions(props: {
7070
await withDraftOperation(key, async (signal) => {
7171
let placeholderIds: ReadonlyArray<string> = [];
7272
await pickComposerMedia({
73-
existingCount: countComposerDraftAttachmentsAfterSelection(key, insertion),
73+
existingCount:
74+
countComposerDraftAttachmentsAfterSelection(key, insertion) +
75+
(appAtomRegistry.get(composerPendingMediaAtom)[key]?.length ?? 0),
7476
maxVideoBytes: capabilities?.fileAttachments?.maxUploadBytes,
7577
onPicked: (placeholders) => {
7678
placeholderIds = placeholders.map(({ id }) => id);
@@ -79,9 +81,10 @@ export function useComposerAttachmentActions(props: {
7981
})
8082
.then(async (result) => {
8183
// Every attachment has a placeholder; one the user removed is no longer pending.
84+
// append writes the draft before its first await, so no removal lands in between.
8285
const pending = appAtomRegistry.get(composerPendingMediaAtom)[key] ?? [];
8386
const kept = result.attachments.filter(({ id }) => pending.some((p) => p.id === id));
84-
await releaseUnusedComposerAttachmentFiles(
87+
scheduleUnusedComposerAttachmentCleanup(
8588
result.attachments.filter((attachment) => !kept.includes(attachment)),
8689
);
8790
report(

0 commit comments

Comments
 (0)