Fix: Rapid clicking results in multiple message requests being sent. (#16739)

This commit is contained in:
balibabu
2026-07-09 09:57:54 +08:00
committed by GitHub
parent 3ec9187cd2
commit 575984877f
5 changed files with 9 additions and 6 deletions

View File

@@ -126,10 +126,10 @@ export function NextMessageInput({
}, []);
const submit = React.useCallback(() => {
if (isUploading) return;
if (isUploading || sendLoading) return;
pressEnter();
setFiles([]);
}, [isUploading, pressEnter]);
}, [isUploading, sendLoading, pressEnter]);
const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
if (e.key === 'Enter' && !e.shiftKey) {
@@ -222,6 +222,7 @@ export function NextMessageInput({
"
disabled={isUploading || disabled || sendLoading}
onKeyDown={handleKeyDown}
resize={resize}
autoSize={{ minRows: 2, maxRows: 8 }}
/>

View File

@@ -415,7 +415,7 @@ export const useSendAgentMessage = ({
const handlePressEnter = useCallback(
({ exploreSessionId }: { exploreSessionId?: string } = {}) => {
if (trim(value) === '') return;
if (trim(value) === '' || !done) return;
const msgBody = buildRequestBody(value);
if (done) {
setValue('');

View File

@@ -147,7 +147,7 @@ export const useSendMessage = (controller: AbortController) => {
enableThinking,
enableInternet,
}: NextMessageInputOnPressEnterParameter) => {
if (trim(value) === '') return;
if (trim(value) === '' || !done) return;
const data = await createConversationBeforeSendMessage(value);
@@ -199,10 +199,10 @@ export const useSendMessage = (controller: AbortController) => {
},
[
value,
done,
createConversationBeforeSendMessage,
addNewestQuestion,
files,
done,
clearFiles,
setValue,
sendMessage,

View File

@@ -132,7 +132,7 @@ export const useSendSharedMessage = () => {
enableThinking,
enableInternet,
}: NextMessageInputOnPressEnterParameter) => {
if (trim(value) === '') return;
if (trim(value) === '' || !done) return;
const id = uuid();
if (done) {
setValue('');

View File

@@ -8,6 +8,7 @@ import {
import { useGetChatSearchParams } from '@/hooks/use-chat-request';
import { IMessage } from '@/interfaces/database/chat';
import api from '@/utils/api';
import { trim } from 'lodash';
import { useCallback, useEffect } from 'react';
import { useParams } from 'react-router';
import { v4 as uuid } from 'uuid';
@@ -112,6 +113,7 @@ export function useSendSingleMessage({
...params
}: NextMessageInputOnPressEnterParameter &
CreateConversationBeforeSendMessageReturnType) => {
if (trim(value) === '' || !done) return;
const id = uuid();
addNewestQuestion({