From 8b9d78e0376ce9d63c7fae9b99d3f64946a6526e Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 22 Nov 2026 19:28:25 +0000 Subject: [PATCH] fix(web): a photo picked on a phone attaches even when the composer collapses Opening the photo picker blurs the editor, so the phone composer collapses and unmounts its footer, taking the attach button's hidden file input with it. The picker's change event then fired on a detached input and the photo was dropped. The file input now lives outside the footer, so it stays mounted while the picker is open. Fixes pingdotgg/t3code#40993 Co-Authored-By: Claude Opus 5.5 --- .../src/components/ChatView.browser.test.tsx | 37 ++++++++ apps/web/src/components/chat/ChatComposer.tsx | 14 ++- .../chat/ComposerAttachmentStrip.tsx | 88 ++++++++++--------- apps/web/test/fakeEnvironment.ts | 7 +- 4 files changed, 100 insertions(+), 46 deletions(-) diff --git a/apps/web/src/components/ChatView.browser.test.tsx b/apps/web/src/components/ChatView.browser.test.tsx index 60c3c24ce5c2d..e721c46d48ec4 100644 --- a/apps/web/src/components/ChatView.browser.test.tsx +++ b/apps/web/src/components/ChatView.browser.test.tsx @@ -547,6 +547,43 @@ it.each(["new", "existing"] as const)( }, ); +it("a file picked after the phone composer collapses still attaches", async () => { + const thread = threadWithHistory("thread-40993", 1); + using _environment = installFakeEnvironment([thread]); + await page.viewport(390, 844); + __setClientSettingsForTests({ + ...DEFAULT_CLIENT_SETTINGS, + onboardingCompletedAt: "2026-01-01T00:00:00.000Z", + }); + const router = getRouter( + createMemoryHistory({ initialEntries: [`/${ENVIRONMENT_ID}/${thread.id}`] }), + ); + await router.load(); + await using _app = await render(, { + // AppRoot brings its own router. + router: false, + }); + using _uploads = acceptAttachmentUploads(); + const editor = page.getByTestId("composer-editor"); + await expect.element(page.getByText(`Answer 0 for ${thread.id}.`)).toBeVisible(); + await userEvent.click(editor); + await expect.element(page.getByRole("button", { name: "Attach files" })).toBeVisible(); + const input = document.querySelector( + 'form[data-chat-composer-form] input[type="file"]', + ); + expect(input).not.toBeNull(); + + // Opening the native picker blurs the editor, which collapses the phone composer. + (editor.element() as HTMLElement).blur(); + await expect.element(page.getByRole("button", { name: "Attach files" })).not.toBeInTheDocument(); + const files = new DataTransfer(); + files.items.add(new File([PNG], "picked.png", { type: "image/png" })); + input!.files = files.files; + input!.dispatchEvent(new Event("change", { bubbles: true })); + + await expect.element(page.getByRole("img", { name: "picked.png" })).toBeVisible(); +}); + it("opens the thread actions menu for an older settled thread the shell leaves out", async () => { const thread = { ...threadWithHistory("older-settled", 1), olderSettled: true as const }; using _environment = installFakeEnvironment([thread]); diff --git a/apps/web/src/components/chat/ChatComposer.tsx b/apps/web/src/components/chat/ChatComposer.tsx index af4871b451932..1ad29945f1a24 100644 --- a/apps/web/src/components/chat/ChatComposer.tsx +++ b/apps/web/src/components/chat/ChatComposer.tsx @@ -214,6 +214,7 @@ import { } from "./ComposerCommandMenu"; import { ComposerAttachButton, + ComposerAttachInput, ComposerAttachmentFileList, ComposerAttachmentMediaRow, ComposerFilePreviewDialog, @@ -1081,6 +1082,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps) const composerEditorRef = useRef(null); const pasteAsTextShortcutUntilRef = useRef(0); const composerFormRef = useRef(null); + const composerAttachInputRef = useRef(null); const composerSurfaceRef = useRef(null); const providerInputRejectedRef = useRef(false); const composerSelectLockRef = useRef(false); @@ -3551,10 +3553,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps) /> ) : null; const composerAttachButton = showComposerAttachAction ? ( - + composerAttachInputRef.current?.click()} /> ) : null; return (
+ {showComposerAttachAction ? ( + + ) : null}
; readonly addComposerAttachments: (files: File[]) => Promise; readonly focusComposer: () => void; }) { + return ( + { + const files = Array.from(event.currentTarget.files ?? []); + event.currentTarget.value = ""; + // Inserting a chip refocuses the editor after the draft renders; + // focusing synchronously here would report the editor's stale text + // over the prompt that was just written. + void addComposerAttachments(files).then((inserted) => { + if (!inserted) focusComposer(); + }); + }} + /> + ); +} + +export function ComposerAttachButton({ onOpenPicker }: { readonly onOpenPicker: () => void }) { const gt = useGT(); - const inputRef = useRef(null); return ( - <> - { - const files = Array.from(event.currentTarget.files ?? []); - event.currentTarget.value = ""; - // Inserting a chip refocuses the editor after the draft renders; - // focusing synchronously here would report the editor's stale text - // over the prompt that was just written. - void addComposerAttachments(files).then((inserted) => { - if (!inserted) focusComposer(); - }); - }} - /> - - event.preventDefault()} - onClick={() => inputRef.current?.click()} - aria-label={gt("Attach files")} - /> - } - > - {/* The clip's weight sits in its upper loop; 1px down reads as centered on the row. */} - - - - Attach files - - - + + event.preventDefault()} + onClick={onOpenPicker} + aria-label={gt("Attach files")} + /> + } + > + {/* The clip's weight sits in its upper loop; 1px down reads as centered on the row. */} + + + + Attach files + + ); } diff --git a/apps/web/test/fakeEnvironment.ts b/apps/web/test/fakeEnvironment.ts index 71e8875bb56db..734fe38dad33b 100644 --- a/apps/web/test/fakeEnvironment.ts +++ b/apps/web/test/fakeEnvironment.ts @@ -67,7 +67,12 @@ const descriptor = { // A matching version, since a mismatch adds an update banner a typical user never sees. serverVersion: APP_VERSION, orchestrationProtocolVersion: ORCHESTRATION_PROTOCOL_VERSION, - capabilities: { repositoryIdentity: true, sideChats: true, freshContext: true }, + capabilities: { + repositoryIdentity: true, + sideChats: true, + freshContext: true, + fileAttachments: { maxUploadBytes: 10_000_000 }, + }, }; const auth = { policy: "loopback-browser",