From 2310145937ab2099b4fd1f563751096f06289f5f Mon Sep 17 00:00:00 2001 From: hjlarry Date: Thu, 9 Oct 2025 15:50:23 +0800 Subject: [PATCH] comment reply auto scoll down to bottom --- .../components/workflow/comment/thread.tsx | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/web/app/components/workflow/comment/thread.tsx b/web/app/components/workflow/comment/thread.tsx index b727d8e640..3098198a6b 100644 --- a/web/app/components/workflow/comment/thread.tsx +++ b/web/app/components/workflow/comment/thread.tsx @@ -1,7 +1,7 @@ 'use client' import type { FC, ReactNode } from 'react' -import { memo, useCallback, useEffect, useMemo, useState } from 'react' +import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react' import { useReactFlow, useViewport } from 'reactflow' import { useTranslation } from 'react-i18next' import { RiArrowDownSLine, RiArrowUpSLine, RiCheckboxCircleFill, RiCheckboxCircleLine, RiCloseLine, RiDeleteBinLine, RiMoreFill } from '@remixicon/react' @@ -193,6 +193,25 @@ export const CommentThread: FC = memo(({ }, [editingReply, onReplyEdit]) const replies = comment.replies || [] + const messageListRef = useRef(null) + const previousReplyCountRef = useRef(replies.length) + const previousCommentIdRef = useRef(comment.id) + + useEffect(() => { + const container = messageListRef.current + if (!container) + return + + const isNewComment = comment.id !== previousCommentIdRef.current + const hasNewReply = replies.length > previousReplyCountRef.current + + if (isNewComment || hasNewReply) + container.scrollTop = container.scrollHeight + + previousCommentIdRef.current = comment.id + previousReplyCountRef.current = replies.length + }, [comment.id, replies.length]) + const mentionsByTarget = useMemo(() => { const map = new Map() for (const mention of comment.mentions || []) { @@ -272,7 +291,10 @@ export const CommentThread: FC = memo(({ -
+