mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-09-05 08:06:19 +00:00
fix: auto-scroll chat during streaming responses
This commit is contained in:
parent
55558f5562
commit
8ac23eaf7d
1 changed files with 39 additions and 0 deletions
|
|
@ -553,6 +553,45 @@ export function ChatSidebar({
|
|||
checkIfScrolledToBottom()
|
||||
}, [messages, checkIfScrolledToBottom])
|
||||
|
||||
useEffect(() => {
|
||||
const isStreaming = status === "streaming"
|
||||
const lastMessage = messages[messages.length - 1]
|
||||
const isLastMessageFromAssistant = lastMessage?.role === "assistant"
|
||||
|
||||
if (isStreaming && isLastMessageFromAssistant && isScrolledToBottom) {
|
||||
scrollToBottom()
|
||||
}
|
||||
}, [status, messages, isScrolledToBottom, scrollToBottom])
|
||||
|
||||
useEffect(() => {
|
||||
const container = messagesContainerRef.current
|
||||
if (!container) return
|
||||
|
||||
const isStreaming = status === "streaming"
|
||||
if (!isStreaming) return
|
||||
|
||||
const mutationObserver = new MutationObserver(() => {
|
||||
if (isScrolledToBottom) {
|
||||
requestAnimationFrame(() => {
|
||||
scrollToBottom()
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
const messagesWrapper = container.firstElementChild
|
||||
if (messagesWrapper) {
|
||||
mutationObserver.observe(messagesWrapper, {
|
||||
childList: true,
|
||||
subtree: true,
|
||||
characterData: true,
|
||||
})
|
||||
}
|
||||
|
||||
return () => {
|
||||
mutationObserver.disconnect()
|
||||
}
|
||||
}, [status, isScrolledToBottom, scrollToBottom])
|
||||
|
||||
// Add scroll event listener to track scroll position
|
||||
useEffect(() => {
|
||||
const container = messagesContainerRef.current
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue