mirror of
https://github.com/langgenius/dify.git
synced 2026-04-21 06:46:30 +08:00
fix: ensure comment thread always scrolls to bottom on first render
This commit is contained in:
parent
0ac32188c5
commit
44fe71e4db
@ -256,8 +256,8 @@ export const CommentThread: FC<CommentThreadProps> = memo(({
|
|||||||
|
|
||||||
const replies = comment.replies || []
|
const replies = comment.replies || []
|
||||||
const messageListRef = useRef<HTMLDivElement>(null)
|
const messageListRef = useRef<HTMLDivElement>(null)
|
||||||
const previousReplyCountRef = useRef(replies.length)
|
const previousReplyCountRef = useRef<number | undefined>(undefined)
|
||||||
const previousCommentIdRef = useRef(comment.id)
|
const previousCommentIdRef = useRef<string | undefined>(undefined)
|
||||||
|
|
||||||
// Close dropdown when scrolling
|
// Close dropdown when scrolling
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -279,10 +279,13 @@ export const CommentThread: FC<CommentThreadProps> = memo(({
|
|||||||
if (!container)
|
if (!container)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
const isFirstRender = previousCommentIdRef.current === undefined
|
||||||
const isNewComment = comment.id !== previousCommentIdRef.current
|
const isNewComment = comment.id !== previousCommentIdRef.current
|
||||||
const hasNewReply = replies.length > previousReplyCountRef.current
|
const hasNewReply = previousReplyCountRef.current !== undefined
|
||||||
|
&& replies.length > previousReplyCountRef.current
|
||||||
|
|
||||||
if (isNewComment || hasNewReply) {
|
// Scroll on first render, new comment, or new reply
|
||||||
|
if (isFirstRender || isNewComment || hasNewReply) {
|
||||||
container.scrollTo({
|
container.scrollTo({
|
||||||
top: container.scrollHeight,
|
top: container.scrollHeight,
|
||||||
behavior: 'smooth',
|
behavior: 'smooth',
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user