fix(home): simplify enter-to-send queued message to single press (#4008)

* fix(home): simplify enter-to-send queued message to single press

* fix(home): prevent empty submit fallthrough when sending with empty input
This commit is contained in:
Waleed
2026-04-06 21:19:53 -07:00
committed by GitHub
parent 8e11c32965
commit 1e00a06e86
2 changed files with 5 additions and 33 deletions

View File

@@ -1,6 +1,6 @@
'use client'
import { useCallback, useEffect, useLayoutEffect, useRef } from 'react'
import { useCallback, useLayoutEffect, useRef } from 'react'
import { cn } from '@/lib/core/utils/cn'
import { MessageActions } from '@/app/workspace/[workspaceId]/components'
import { ChatMessageAttachments } from '@/app/workspace/[workspaceId]/home/components/chat-message-attachments'
@@ -99,41 +99,16 @@ export function MothershipChat({
const hasMessages = messages.length > 0
const initialScrollDoneRef = useRef(false)
const primedQueueIdRef = useRef<string | null>(null)
const primeTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null)
const messageQueueRef = useRef(messageQueue)
messageQueueRef.current = messageQueue
const onSendQueuedMessageRef = useRef(onSendQueuedMessage)
onSendQueuedMessageRef.current = onSendQueuedMessage
const clearPrimed = useCallback(() => {
primedQueueIdRef.current = null
if (primeTimerRef.current) {
clearTimeout(primeTimerRef.current)
primeTimerRef.current = null
}
}, [])
const handleEnterWhileEmpty = useCallback(() => {
const topMessage = messageQueueRef.current[0]
if (!topMessage) return false
if (primedQueueIdRef.current === topMessage.id) {
clearPrimed()
void onSendQueuedMessageRef.current(topMessage.id)
return true
}
primedQueueIdRef.current = topMessage.id
if (primeTimerRef.current) clearTimeout(primeTimerRef.current)
primeTimerRef.current = setTimeout(clearPrimed, 3000)
void onSendQueuedMessageRef.current(topMessage.id)
return true
}, [clearPrimed])
useEffect(() => {
return () => {
if (primeTimerRef.current) clearTimeout(primeTimerRef.current)
}
}, [])
useLayoutEffect(() => {
@@ -235,7 +210,6 @@ export function MothershipChat({
editValue={editValue}
onEditValueConsumed={onEditValueConsumed}
onEnterWhileEmpty={handleEnterWhileEmpty}
onPrimedDismiss={clearPrimed}
/>
</div>
</div>

View File

@@ -109,7 +109,6 @@ interface UserInputProps {
userId?: string
onContextAdd?: (context: ChatContext) => void
onEnterWhileEmpty?: () => boolean
onPrimedDismiss?: () => void
}
export function UserInput({
@@ -123,7 +122,6 @@ export function UserInput({
userId,
onContextAdd,
onEnterWhileEmpty,
onPrimedDismiss,
}: UserInputProps) {
const { workspaceId } = useParams<{ workspaceId: string }>()
const { data: workflowsById = {} } = useWorkflowMap(workspaceId)
@@ -456,7 +454,8 @@ export function UserInput({
(e: React.KeyboardEvent<HTMLTextAreaElement>) => {
if (e.key === 'Enter' && !e.shiftKey && !e.nativeEvent.isComposing) {
e.preventDefault()
if (isSendingRef.current && !valueRef.current.trim() && onEnterWhileEmptyRef.current?.()) {
if (isSendingRef.current && !valueRef.current.trim()) {
onEnterWhileEmptyRef.current?.()
return
}
handleSubmit()
@@ -551,9 +550,8 @@ export function UserInput({
setValue(newValue)
restartRecognition(newValue)
if (newValue.trim()) onPrimedDismiss?.()
},
[restartRecognition, onPrimedDismiss]
[restartRecognition]
)
const handleSelectAdjust = useCallback(() => {