Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

fix: prevent sending messages while AI is streaming response (#674)

OasisCaterinoebcac74b8f12
diff --git a/web/components/chat/home/ChatComposer.tsx b/web/components/chat/home/ChatComposer.tsx
index d9a1019f1..0913f5d45 100644
--- a/web/components/chat/home/ChatComposer.tsx
+++ b/web/components/chat/home/ChatComposer.tsx
@@ -619,6 +619,7 @@ export default memo(function ChatComposer({
ref={inputHandleRef}
textareaRef={textareaRef}
isVisualizeMode={isVisualizeMode}
+ isStreaming={isStreaming}
canSendEmpty={hasReferences}
onSend={doSend}
onInputChange={handleInputChange}
diff --git a/web/components/chat/home/ComposerInput.tsx b/web/components/chat/home/ComposerInput.tsx
index ae1b61a27..697317a4d 100644
--- a/web/components/chat/home/ComposerInput.tsx
+++ b/web/components/chat/home/ComposerInput.tsx
@@ -24,6 +24,7 @@ import { useImeComposing } from "@/lib/use-ime-composing";
interface ComposerInputProps {
textareaRef: RefObject<HTMLTextAreaElement | null>;
isVisualizeMode: boolean;
+ isStreaming?: boolean;
// When true, parent has attachments/references queued and will accept a
// send even if the text body is empty. Without this, Enter would silently
// do nothing for an attachment-only message.
@@ -128,6 +129,7 @@ export const ComposerInput = memo(
{
textareaRef,
isVisualizeMode,
+ isStreaming = false,
canSendEmpty,
onSend,
onInputChange,
@@ -309,7 +311,7 @@ export const ComposerInput = memo(
}
if (shouldSubmitOnEnter(e, isComposingRef.current)) {
e.preventDefault();
- doSend();
+ if (!isStreaming) doSend();
} else if (e.key === "Escape") {
setShowAtPopup(false);
setShowSlashPopup(false);
@@ -317,6 +319,7 @@ export const ComposerInput = memo(
},
[
doSend,
+ isStreaming,
showSlashPopup,
handleSelectSlashPersona,
showAtPopup,