fix: scroll bottom when generation text (#4323)

* fix: scroll bottom when generation text

* chore: update logic when prepare generate

* chore: fix case no switch thread

* chore: remore dep thread id

* chore: handle fix generation without have dep thread id
This commit is contained in:
Faisal Amir 2024-12-23 18:55:51 +08:00 committed by GitHub
parent df1c465fd9
commit 56d1ffa136
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -85,24 +85,33 @@ const ChatBody = memo(
overscan: 5,
})
useEffect(() => {
if (parentRef.current) {
parentRef.current.scrollTo({ top: parentRef.current.scrollHeight })
virtualizer.scrollToIndex(count - 1)
}
}, [count, virtualizer])
useEffect(() => {
if (parentRef.current && isGeneratingResponse) {
requestAnimationFrame(() => {
if (parentRef.current) {
parentRef.current.scrollTo({ top: parentRef.current.scrollHeight })
}
})
parentRef.current.scrollTo({ top: parentRef.current.scrollHeight })
virtualizer.scrollToIndex(count - 1)
}
}, [count, virtualizer, isGeneratingResponse])
useEffect(() => {
if (parentRef.current && isGeneratingResponse) {
parentRef.current.scrollTo({ top: parentRef.current.scrollHeight })
virtualizer.scrollToIndex(count - 1)
}
}, [count, virtualizer, isGeneratingResponse, currentThread?.id])
useEffect(() => {
isUserManuallyScrollingUp.current = false
requestAnimationFrame(() => {
if (parentRef.current) {
parentRef.current.scrollTo({ top: parentRef.current.scrollHeight })
virtualizer.scrollToIndex(count - 1)
}
})
if (parentRef.current) {
parentRef.current.scrollTo({ top: parentRef.current.scrollHeight })
virtualizer.scrollToIndex(count - 1)
}
}, [count, currentThread?.id, virtualizer])
const items = virtualizer.getVirtualItems()