Skip to content

Commit 2e30eb7

Browse files
authored
fix: initial message no longer send to chat endpoint (#114)
The initial message is no longer send to chat endpoint. Closes #113 ![CleanShot 2025-07-07 at 18 29 21@2x](https://github.com/user-attachments/assets/c9bbe54e-dc90-4b7e-911c-2381b86afac3)
1 parent 3b2b1bd commit 2e30eb7

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/components/Chat.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -504,16 +504,21 @@ export function Chat() {
504504
setMessages,
505505
setInput,
506506
} = useChat({
507-
initialMessages: hasStartedChat ? [] : [initialMessage],
508507
body: chatBody,
509508
onError: handleError,
510509
onResponse: handleResponse,
511510
})
512511

513-
const renderEvents = useMemo<(StreamEvent | Message)[]>(
514-
() => (streaming || streamBuffer.length > 0 ? [...streamBuffer] : messages),
515-
[streaming, streamBuffer, messages],
516-
)
512+
const renderEvents = useMemo<(StreamEvent | Message)[]>(() => {
513+
if (streaming || streamBuffer.length > 0) {
514+
return [...streamBuffer]
515+
}
516+
// Show initial message only when there are no real messages and no streaming
517+
if (messages.length === 0 && !hasStartedChat) {
518+
return [initialMessage]
519+
}
520+
return messages
521+
}, [streaming, streamBuffer, messages, hasStartedChat, initialMessage])
517522

518523
const handleSendMessage = useCallback(
519524
(prompt: string) => {
@@ -550,14 +555,14 @@ export function Chat() {
550555
setHasStartedChat(false)
551556
setStreamBuffer([])
552557
setStreaming(false)
553-
setMessages([initialMessage])
558+
setMessages([]) // Clear messages completely - initialMessage will be shown via renderEvents logic
554559
setInput('')
555560
setFocusTimestamp(Date.now())
556561

557562
textBufferRef.current = ''
558563
lastAssistantIdRef.current = null
559564
pendingStreamEventsRef.current = []
560-
}, [initialMessage, setMessages, setInput])
565+
}, [setMessages, setInput])
561566

562567
const handleScrollToBottom = useCallback(() => {
563568
messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' })

0 commit comments

Comments
 (0)