Skip to content

Commit aa92532

Browse files
Use effect events for pending input option selection
- Replace the callback with `useEffectEvent` so option selection sees fresh state without extra deps - Keep keyboard auto-advance behavior unchanged
1 parent 78aadd2 commit aa92532

1 file changed

Lines changed: 15 additions & 18 deletions

File tree

‎apps/web/src/components/chat/ComposerPendingUserInputPanel.tsx‎

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { type ApprovalRequestId } from "@t3tools/contracts";
2-
import { memo, useCallback, useEffect, useRef } from "react";
2+
import { memo, useEffect, useEffectEvent, useRef } from "react";
33
import { type PendingUserInput } from "../../session-logic";
44
import {
55
derivePendingUserInputProgress,
@@ -75,22 +75,19 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
7575
};
7676
}, []);
7777

78-
const handleOptionSelection = useCallback(
79-
(questionId: string, optionLabel: string) => {
80-
onToggleOption(questionId, optionLabel);
81-
if (activeQuestion?.multiSelect) {
82-
return;
83-
}
84-
if (autoAdvanceTimerRef.current !== null) {
85-
window.clearTimeout(autoAdvanceTimerRef.current);
86-
}
87-
autoAdvanceTimerRef.current = window.setTimeout(() => {
88-
autoAdvanceTimerRef.current = null;
89-
onAdvanceRef.current();
90-
}, 200);
91-
},
92-
[activeQuestion?.multiSelect, onToggleOption],
93-
);
78+
const handleOptionSelection = useEffectEvent((questionId: string, optionLabel: string) => {
79+
onToggleOption(questionId, optionLabel);
80+
if (activeQuestion?.multiSelect) {
81+
return;
82+
}
83+
if (autoAdvanceTimerRef.current !== null) {
84+
window.clearTimeout(autoAdvanceTimerRef.current);
85+
}
86+
autoAdvanceTimerRef.current = window.setTimeout(() => {
87+
autoAdvanceTimerRef.current = null;
88+
onAdvanceRef.current();
89+
}, 200);
90+
});
9491

9592
// Keyboard shortcut: number keys 1-9 select corresponding options when focus is
9693
// outside editable fields. Multi-select prompts toggle options in place; single-
@@ -117,7 +114,7 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
117114
};
118115
document.addEventListener("keydown", handler);
119116
return () => document.removeEventListener("keydown", handler);
120-
}, [activeQuestion, handleOptionSelection, isResponding]);
117+
}, [activeQuestion, isResponding]);
121118

122119
if (!activeQuestion) {
123120
return null;

0 commit comments

Comments
 (0)