From 792c1db8611cce4ea3343257adea1b23e9d9ed60 Mon Sep 17 00:00:00 2001 From: Vorflux AI Date: Mon, 1 Jun 2026 00:14:11 +0000 Subject: [PATCH] fix: remove dangling user message when stop is hit before any response --- apps/web/components/chat/index.tsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/apps/web/components/chat/index.tsx b/apps/web/components/chat/index.tsx index 17666d42..d140b469 100644 --- a/apps/web/components/chat/index.tsx +++ b/apps/web/components/chat/index.tsx @@ -370,6 +370,17 @@ export function ChatSidebar({ } } + // When the user stops generation before any assistant response arrives, + // remove the dangling user message so it isn't duplicated on the next send. + const handleStop = useCallback(() => { + stop() + setMessages((prev) => { + const last = prev[prev.length - 1] + if (last?.role === "user") return prev.slice(0, -1) + return prev + }) + }, [stop, setMessages]) + const handleCopyMessage = useCallback((messageId: string, text: string) => { analytics.chatMessageCopied({ message_id: messageId }) navigator.clipboard.writeText(text) @@ -1137,7 +1148,7 @@ export function ChatSidebar({ value={input} onChange={(e) => setInput(e.target.value)} onSend={handleSend} - onStop={stop} + onStop={handleStop} onKeyDown={handleKeyDown} isResponding={isResponding} activeStatus={