The best way to control Claude Code, Codex and more from any computer or phone
refactor(web): the pending user input panel keeps its caching without "use memo" hooks (#20762)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 16, 2026 at 23:27 UTC
4500480e03eb6bbb38f285828791a00bc1499c46
1 file changed
+11
-17
apps/web/src/components/chat/ComposerPendingUserInputPanel.tsx
+11
-17
@@ -58,16 +58,6 @@ export const ComposerPendingUserInputPanel = memo(function ComposerPendingUserIn
58
);
59
});
60
61
-// The active question keys the shortcut listener, so it must keep its identity across renders.
62
-function usePendingUserInputProgress(
63
- questions: PendingUserInput["questions"],
64
- answers: Record<string, PendingUserInputDraftAnswer>,
65
- questionIndex: number,
66
-) {
67
- "use memo";
68
- return derivePendingUserInputProgress(questions, answers, questionIndex);
69
-}
70
-
61
const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard({
62
prompt,
63
cwd,
@@ -94,8 +84,6 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
84
// Message-mode requests remain answerable after their provider turn ends.
85
const canRespond = prompt.responseCapability !== "not_resumable";
86
const responseDisabled = disabled || isResponding || !canRespond;
97
- const progress = usePendingUserInputProgress(prompt.questions, answers, questionIndex);
98
- const activeQuestion = progress.activeQuestion;
87
const autoAdvanceTimerRef = useRef<number | null>(null);
88
// The auto-advance timer fires after the render that armed it.
89
const advance = useStableCallback(onAdvance);
@@ -104,6 +92,15 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
92
optionValue: string;
93
} | null>(null);
94
const [collapsedQuestionId, setCollapsedQuestionId] = useState<string | null>(null);
95
+ // The active question keys the shortcut listener, so it must keep its identity across renders.
96
+ const progress = derivePendingUserInputProgress(prompt.questions, answers, questionIndex);
97
+ const activeQuestion = progress.activeQuestion;
98
+ const customAnswerActive = progress.customAnswer.trim().length > 0;
99
+ // Read here, before the hooks below, so the compiler can keep `activeQuestion` cached.
100
+ const draftSelectedOptions = activeQuestion?.options.map(
101
+ (option) =>
102
+ !customAnswerActive && progress.selectedOptionValues.includes(option.value ?? option.label),
103
+ );
104
const isCollapsed = collapsedQuestionId !== null && collapsedQuestionId === activeQuestion?.id;
105
106
// The optimistic pick is dropped once the draft confirms it or the question moves on.
@@ -112,7 +109,7 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
109
activeQuestion &&
110
!activeQuestion.multiSelect &&
111
(optimisticSingleSelect.questionId !== activeQuestion.id ||
115
- (progress.customAnswer.trim().length === 0 &&
112
+ (!customAnswerActive &&
113
progress.selectedOptionValues.includes(optimisticSingleSelect.optionValue)))
114
) {
115
setOptimisticSingleSelect(null);
@@ -180,8 +177,6 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
177
return null;
178
}
179
183
- const customAnswerActive = progress.customAnswer.trim().length > 0;
184
-
180
return (
181
<Collapsible
182
open={!isCollapsed}
@@ -255,8 +250,7 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
250
optimisticSingleSelect?.questionId === activeQuestion.id &&
251
optimisticSingleSelect.optionValue === optionValue;
252
const isSelected =
258
- isOptimisticallySelected ||
259
- (!customAnswerActive && progress.selectedOptionValues.includes(optionValue));
253
+ isOptimisticallySelected || draftSelectedOptions?.[index] === true;
254
const shortcutKey = index < 9 ? index + 1 : null;
255
const className = cn(
256
"group flex w-full items-center gap-2 rounded-md px-2.5 py-2 text-left outline-none transition-colors duration-150 focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-primary/25",