🪹 fix: Prevent whitespace-only Chat input Submissions (#11838)

fix(input): normalize chat input text before submit

Trim input text before checking if empty to show submit button as disabled
This commit is contained in:
Pavel Fediushin 2026-02-18 08:53:22 +07:00 committed by GitHub
parent 2ec64af551
commit dbf8cd40d3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 2 deletions

View file

@ -41,7 +41,8 @@ const SubmitButton = React.memo(
const SendButton = React.memo(
forwardRef((props: SendButtonProps, ref: React.ForwardedRef<HTMLButtonElement>) => {
const data = useWatch({ control: props.control });
return <SubmitButton ref={ref} disabled={props.disabled || !data.text} />;
const content = data?.text?.trim();
return <SubmitButton ref={ref} disabled={props.disabled || !content} />;
}),
);

View file

@ -97,6 +97,8 @@ export default function useChatFunctions({
) => {
setShowStopButton(false);
resetLatestMultiMessage();
text = text.trim();
if (!!isSubmitting || text === '') {
return;
}
@ -134,7 +136,6 @@ export default function useChatFunctions({
// construct the query message
// this is not a real messageId, it is used as placeholder before real messageId returned
text = text.trim();
const intermediateId = overrideUserMessageId ?? v4();
parentMessageId = parentMessageId ?? latestMessage?.messageId ?? Constants.NO_PARENT;