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',