From 44fe71e4db072ed9842ef4fa9a821803d4f09f28 Mon Sep 17 00:00:00 2001 From: lyzno1 Date: Sun, 12 Oct 2025 13:27:42 +0800 Subject: [PATCH] fix: ensure comment thread always scrolls to bottom on first render --- web/app/components/workflow/comment/thread.tsx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/web/app/components/workflow/comment/thread.tsx b/web/app/components/workflow/comment/thread.tsx index c9325bbcb3..aee576d857 100644 --- a/web/app/components/workflow/comment/thread.tsx +++ b/web/app/components/workflow/comment/thread.tsx @@ -256,8 +256,8 @@ export const CommentThread: FC = memo(({ const replies = comment.replies || [] const messageListRef = useRef(null) - const previousReplyCountRef = useRef(replies.length) - const previousCommentIdRef = useRef(comment.id) + const previousReplyCountRef = useRef(undefined) + const previousCommentIdRef = useRef(undefined) // Close dropdown when scrolling useEffect(() => { @@ -279,10 +279,13 @@ export const CommentThread: FC = memo(({ if (!container) return + const isFirstRender = previousCommentIdRef.current === undefined 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({ top: container.scrollHeight, behavior: 'smooth',