TypeScript
fix(web): pending questions no longer squash the composer on narrow windows (#20391)
Matthew Ferozbbe826993fb8
diff --git a/apps/web/src/components/chat/ChatComposer.tsx b/apps/web/src/components/chat/ChatComposer.tsxindex ddca044b046..26058b7993e 100644--- a/apps/web/src/components/chat/ChatComposer.tsx+++ b/apps/web/src/components/chat/ChatComposer.tsx@@ -2428,8 +2428,14 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)key: 0,active: false,});+ // A pending question stays expanded: its card moves into the banner dock,+ // so collapsing would leave the surface empty and squashed beneath it.const isComposerCollapsedMobile =- isMobileViewport && !forceExpandedOnMobile && !isComposerFocused && !hasMultilinePrompt;+ isMobileViewport &&+ !forceExpandedOnMobile &&+ !isComposerFocused &&+ !hasMultilinePrompt &&+ pendingUserInputs.length === 0;const composerEditorRef = useRef<ComposerPromptEditorHandle>(null);const pasteAsTextShortcutUntilRef = useRef(0);@@ -2787,8 +2793,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)isComposerApprovalState ||pendingUserInputs.length > 0 ||(!isComposerCollapsedMobile && showPlanFollowUpPrompt && activeProposedPlan !== null);- const showCollapsedMobilePromptRow =- isComposerCollapsedMobile && !isComposerApprovalState && pendingUserInputs.length === 0;+ const showCollapsedMobilePromptRow = isComposerCollapsedMobile && !isComposerApprovalState;const showComposerAttachAction =fileStagingLimit !== null &&(!activePendingProgress ||@@ -5937,6 +5942,15 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)setIsComposerFocused(false);});};+ const scheduleComposerCollapseCheckStable = useStableCallback(scheduleComposerCollapseCheck);++ // Answering or dismissing a question unmounts the control that held focus,+ // and React fires no blur for a removed element.+ const activePendingUserInputRequestId = activePendingUserInput?.requestId ?? null;+ useEffect(() => {+ if (activePendingUserInputRequestId !== null) return;+ scheduleComposerCollapseCheckStable();+ }, [activePendingUserInputRequestId, scheduleComposerCollapseCheckStable]);useEffect(() => {return () => {@@ -6420,7 +6434,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)/></ComposerBanner.Actions></ComposerBanner.Row>- ) : !isComposerCollapsedMobile && pendingUserInputs.length > 0 ? (+ ) : pendingUserInputs.length > 0 ? (<ComposerPendingUserInputPanelpendingUserInputs={pendingUserInputs}cwd={gitCwd ?? undefined}@@ -6442,82 +6456,6 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)key={activeProposedPlan.id}planTitle={proposedPlanTitle(activeProposedPlan.planMarkdown) ?? null}/>- ) : isComposerCollapsedMobile && pendingUserInputs.length > 0 ? (- <div data-chat-composer-collapsed-controls="true">- <ComposerPendingUserInputPanel- pendingUserInputs={pendingUserInputs}- cwd={gitCwd ?? undefined}- threadRef={routeThreadRef}- disabled={!canOperateThread}- respondingRequestIds={- activePendingIsResponding && activePendingUserInput- ? [...respondingRequestIds, activePendingUserInput.requestId]- : respondingRequestIds- }- answers={activePendingDraftAnswers}- questionIndex={activePendingQuestionIndex}- onToggleOption={onSelectActivePendingUserInputOption}- onAdvance={onAdvanceActivePendingUserInput}- onDismiss={onDismissActivePendingUserInput}- />- {!isChoiceOnlyPendingQuestion ||- activePendingProgress?.activeQuestion?.multiSelect ? (- <ComposerBanner.Body>- <div- data-chat-composer-mobile-pending-compact="true"- className={cn(- "flex min-w-0 items-center gap-2 rounded-lg border border-border/55 bg-background/55 p-1.5 pl-3 transition-colors hover:bg-background/80",- !activePendingProgress?.activeQuestion?.multiSelect && "p-0",- )}- >- {!isChoiceOnlyPendingQuestion ? (- <button- type="button"- className={cn(- "min-w-0 flex-1 truncate bg-transparent py-1.5 text-left text-sm",- activePendingProgress?.customAnswer- ? "text-foreground"- : "text-placeholder",- !activePendingProgress?.activeQuestion?.multiSelect && "px-3 py-2",- )}- onPointerDown={(event) => event.preventDefault()}- onClick={expandMobileComposerStable}- aria-label="Write custom answer"- >- {activePendingProgress?.customAnswer || "Write custom answer"}- </button>- ) : null}- {activePendingProgress?.activeQuestion?.multiSelect ? (- <ComposerPrimaryActions- compact- canOperateThread={canOperateThread}- pendingAction={pendingPrimaryAction}- isRunning={false}- canInterrupt={false}- showPlanFollowUpPrompt={false}- promptHasText={false}- isSendBusy={isSendBusy}- sendDisabledReason={sendDisabledReason}- isConnecting={isConnecting}- isEnvironmentUnavailable={- environmentUnavailable !== null ||- noProviderAvailable ||- projectSelectionRequired- }- isPreparingWorktree={false}- hasSendableContent={false}- preserveComposerFocusOnPointerDown- onPreviousPendingQuestion={onPreviousActivePendingUserInputQuestion}- onInterrupt={handleInterruptPrimaryActionStable}- onImplementPlanInNewThread={- handleImplementPlanInNewThreadPrimaryActionStable- }- />- ) : null}- </div>- </ComposerBanner.Body>- ) : null}- </div>) : null}</ComposerBanner.Root></ComposerBanner.Attachment>@@ -6582,24 +6520,14 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)data-chat-composer-transition-prompt="true"className={cn("min-w-0 flex-1 truncate bg-transparent p-0 text-left text-sm focus:outline-none",- (activePendingProgress ? activePendingProgress.customAnswer : prompt.trim())- ? "text-foreground"- : "text-placeholder",+ prompt.trim() ? "text-foreground" : "text-placeholder",)}onPointerDown={(event) => event.preventDefault()}- onClick={isChoiceOnlyPendingQuestion ? undefined : expandMobileComposerStable}- disabled={isChoiceOnlyPendingQuestion}+ onClick={expandMobileComposerStable}aria-label="Expand composer">- {activePendingProgress- ? isChoiceOnlyPendingQuestion- ? "Choose an option above"- : activePendingProgress.customAnswer ||- "Type your own answer, or leave this blank to use the selected option"- : prompt.trim() ||- (showProviderUnavailable- ? "Enable a provider in Settings"- : "Ask anything...")}+ {prompt.trim() ||+ (showProviderUnavailable ? "Enable a provider in Settings" : "Ask anything...")}</button>{collapsedComposerImagePreviews}<button