Skip to content

Commit

Permalink
fix: scroll bottom when generation text (janhq#4323)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
urmauur authored Dec 23, 2024
1 parent df1c465 commit 56d1ffa
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions web/screens/Thread/ThreadCenterPanel/ChatBody/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 56d1ffa

Please sign in to comment.