Skip to content

Commit c1d9c5e

Browse files
fix(mobile): a started side chat keeps attachments added meanwhile
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 89a9417 commit c1d9c5e

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

‎apps/mobile/src/state/thread-task-permissions.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,20 @@ describe("mobile task permissions", () => {
356356
);
357357
expect(state.enqueue).not.toHaveBeenCalled();
358358
expect(state.clearDraft).toHaveBeenCalled();
359+
360+
// An attachment added while the side chat starts stays in the draft.
361+
vi.clearAllMocks();
362+
startSideChat.mockImplementationOnce(async () => {
363+
state.draft = {
364+
...state.draft,
365+
attachments: [{ id: "added" } as DraftComposerImageAttachment],
366+
};
367+
return true;
368+
});
369+
state.draft = { ...state.draft, text: "/side again?", attachments: [] };
370+
expect(await useThreadComposerState({ startSideChat }).onSendMessage()).toBeNull();
371+
expect(startSideChat).toHaveBeenCalledOnce();
372+
expect(state.clearDraft).not.toHaveBeenCalled();
359373
});
360374

361375
it("rechecks a retained send callback before clearing or queueing the draft", async () => {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,13 @@ export function useThreadComposerState(input: {
586586
startingSideChatRef.current = false;
587587
});
588588
// Clear only what was sent; the draft may have changed while the side chat started.
589-
if (started && getComposerDraftSnapshot(threadKey).text === draft.text) {
589+
const current = getComposerDraftSnapshot(threadKey);
590+
if (
591+
started &&
592+
current.text === draft.text &&
593+
current.attachments.length === 0 &&
594+
(current.context?.records.length ?? 0) === 0
595+
) {
590596
clearComposerDraftContent(threadKey);
591597
}
592598
}

0 commit comments

Comments
 (0)