TypeScript
fix(web): skip image inline chip when composer is empty (#12528)
mariac789cd174ae5
diff --git a/apps/web/src/components/chat/ChatComposer.tsx b/apps/web/src/components/chat/ChatComposer.tsxindex 6ae4d6fe390..3fe6e740fb9 100644--- a/apps/web/src/components/chat/ChatComposer.tsx+++ b/apps/web/src/components/chat/ChatComposer.tsx@@ -206,6 +206,7 @@ import {import { useOpenPrLink } from "~/lib/openPullRequestLink";import {collectInlineContextIds,+ stripInlineContextReferences,type ComposerContextReference,ensureInlineContextReferences,formatInlineContextReference,@@ -5241,6 +5242,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)options?: {readonly source?: ChatFileAttachment["source"];readonly selection?: { start: number; end: number };+ readonly skipImageInlineChip?: boolean;},): Promise<boolean> => {if (!activeThreadId || files.length === 0 || isRevertingCheckpointRef.current) return false;@@ -5260,6 +5262,20 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)// large image is being compressed, and the attachments and errors belong// to the thread the paste happened in.const threadId = activeThreadId;+ // Images landing with no prose live on the shelf with no chip. Read before+ // the awaits below: compression is async and the prompt may change while it+ // runs. An explicit selection replace and states where the editor refuses+ // input (connecting, approval, pending questions, project selection) still+ // get chips so the image is never invisible, unless paste-as-text explicitly+ // requests no inline image chip.+ const imageAttachmentsGetChips =+ !options?.skipImageInlineChip &&+ (options?.selection !== undefined ||+ isConnecting ||+ isComposerApprovalState ||+ pendingUserInputs.length > 0 ||+ projectSelectionRequired ||+ stripInlineContextReferences(promptRef.current).trim().length > 0);// Validation happens synchronously so concurrent pastes see each other:// accepted files reserve their attachment slots (via the pending counter)@@ -5416,7 +5432,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps): [],);const storedImages = nextImages.filter((image) => storedImageIds.has(image.id));- if (storedImages.length > 0) {+ if (storedImages.length > 0 && imageAttachmentsGetChips) {insertedAny =insertAttachmentReferences(storedImages.map(imageContextReference)) || insertedAny;}@@ -5444,6 +5460,8 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)/*** Chips for freshly attached files land at the caret; when the editor cannot take* input (approval, pending questions) they are appended so the file is never invisible.+ * Images skip this when they land with no prose and the editor takes input:+ * the shelf thumbnail is enough.*/const insertAttachmentReferences = (references: ReadonlyArray<ComposerContextReference>,@@ -5582,7 +5600,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)) {event.preventDefault();event.stopPropagation();- void addComposerAttachments(files);+ void addComposerAttachments(files, { skipImageInlineChip: bypassAutoAttachment });return;}