fix: prevent duplicate message submission while agent is working (#180)
This commit is contained in:
@@ -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?.();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user