An AI-powered search engine with a generative UI
TypeScript generative-aigenerative-uinextjsollamareactsearxngshadcn-uitailwindcsstavilytypescriptupstashvercel-ai-sdk
Add continuous scrolling during message streaming
Yoshiki Miura4a9d27058252
diff --git a/components/chat-messages.tsx b/components/chat-messages.tsxindex 5b032c33..ff9a7fc0 100644--- a/components/chat-messages.tsx+++ b/components/chat-messages.tsx@@ -27,13 +27,26 @@ export function ChatMessages({// Scroll to bottom functionconst scrollToBottom = () => {- messagesEndRef.current?.scrollIntoView({ behavior: 'instant' })+ messagesEndRef.current?.scrollIntoView({+ behavior: messages.length > 5 ? 'instant' : 'smooth'+ })}- // Scroll to bottom on mount and when messages change+ // Scroll to bottom on mount and when messages change or during streaminguseEffect(() => {scrollToBottom()- }, [])++ // Set up interval for continuous scrolling during streaming+ let intervalId: ReturnType<typeof setInterval> | undefined++ if (isLoading && messages[messages.length - 1]?.role === 'user') {+ intervalId = setInterval(scrollToBottom, 100)+ }++ return () => {+ if (intervalId) clearInterval(intervalId)+ }+ }, [messages.length, isLoading, messages])useEffect(() => {const lastMessage = messages[messages.length - 1]