fix: prevent duplicate message submission while agent is working (#180)

This commit is contained in:
João Salavisa
2026-02-04 17:52:18 +00:00
committed by GitHub
parent e2fa974b0b
commit 3757ac03f8
5 changed files with 104 additions and 23 deletions
@@ -329,6 +329,9 @@ export const ChatInputContainer = forwardRef<ChatInputContainerHandle, ChatInput
// Stable submit handler using refs - doesn't change on value/menu state changes
const handleSubmit = useCallback(() => {
// Don't submit if agent is busy or already sending
if (isAgentBusy || isSending) return;
// Don't submit if a menu is open
if (menuStateRef.current.mentionOpen || menuStateRef.current.slashOpen) return;
@@ -348,9 +351,10 @@ export const ChatInputContainer = forwardRef<ChatInputContainerHandle, ChatInput
onSubmit(trimmed, allComments.length > 0 ? allComments : undefined);
setValue('');
}, [onSubmit]);
}, [onSubmit, isAgentBusy, isSending]);
const isDisabled = isStarting || isSending;
// Disable input when agent is busy (RUNNING state), starting, or sending a message
const isDisabled = isAgentBusy || isStarting || isSending;
const hasPendingClarification = pendingClarification && onClarificationResolved;
const hasPendingComments = pendingCommentsByFile && Object.keys(pendingCommentsByFile).length > 0;
@@ -187,21 +187,32 @@ export const RichTextInput = forwardRef<RichTextInputHandle, RichTextInputProps>
if (event.defaultPrevented) return;
}
// Don't allow submission if disabled (includes when agent is busy)
if (disabled) {
// Prevent default to avoid any action when disabled
if (submitKey === 'enter') {
if (event.key === 'Enter' && !event.shiftKey && !event.metaKey && !event.ctrlKey) {
event.preventDefault();
}
} else {
if (event.key === 'Enter' && (event.metaKey || event.ctrlKey)) {
event.preventDefault();
}
}
return;
}
if (submitKey === 'enter') {
// Submit on Enter (unless Shift for newline)
if (event.key === 'Enter' && !event.shiftKey && !event.metaKey && !event.ctrlKey) {
event.preventDefault();
if (!disabled) {
onSubmit?.();
}
onSubmit?.();
}
} else {
// Submit on Cmd/Ctrl+Enter (current behavior)
if (event.key === 'Enter' && (event.metaKey || event.ctrlKey)) {
event.preventDefault();
if (!disabled) {
onSubmit?.();
}
onSubmit?.();
}
}
};