@@ -504,16 +504,21 @@ export function Chat() {
504
504
setMessages,
505
505
setInput,
506
506
} = useChat ( {
507
- initialMessages : hasStartedChat ? [ ] : [ initialMessage ] ,
508
507
body : chatBody ,
509
508
onError : handleError ,
510
509
onResponse : handleResponse ,
511
510
} )
512
511
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 ] )
517
522
518
523
const handleSendMessage = useCallback (
519
524
( prompt : string ) => {
@@ -550,14 +555,14 @@ export function Chat() {
550
555
setHasStartedChat ( false )
551
556
setStreamBuffer ( [ ] )
552
557
setStreaming ( false )
553
- setMessages ( [ initialMessage ] )
558
+ setMessages ( [ ] ) // Clear messages completely - initialMessage will be shown via renderEvents logic
554
559
setInput ( '' )
555
560
setFocusTimestamp ( Date . now ( ) )
556
561
557
562
textBufferRef . current = ''
558
563
lastAssistantIdRef . current = null
559
564
pendingStreamEventsRef . current = [ ]
560
- } , [ initialMessage , setMessages , setInput ] )
565
+ } , [ setMessages , setInput ] )
561
566
562
567
const handleScrollToBottom = useCallback ( ( ) => {
563
568
messagesEndRef . current ?. scrollIntoView ( { behavior : 'smooth' } )
0 commit comments