From b96a9e98e21cc3e62e158e02fd13fb4d73f8a3b4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 21 Sep 2025 17:49:41 +0000 Subject: [PATCH] Fix comment pagination bug - prevent comments from disappearing on load more Co-authored-by: snowykami <79104275+snowykami@users.noreply.github.com> --- web/src/components/comment/index.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/web/src/components/comment/index.tsx b/web/src/components/comment/index.tsx index dc532a5..6ba3430 100644 --- a/web/src/components/comment/index.tsx +++ b/web/src/components/comment/index.tsx @@ -34,19 +34,27 @@ export function CommentSection( const [needLoadMore, setNeedLoadMore] = useState(true); // 是否需要加载更多,当最后一次获取的评论数小于分页大小时设为false // 加载0/顶层评论 useEffect(() => { + // Reset pagination state when target changes + setPage(1); + setNeedLoadMore(true); + listComments({ targetType, targetId, depth: 0, orderBy: OrderBy.CreatedAt, desc: true, - page: page, + page: 1, size: config.commentsPerPage, commentId: 0 }).then(response => { setComments(response.data.comments); + // If we got fewer comments than requested, no more pages + if (response.data.comments.length < config.commentsPerPage) { + setNeedLoadMore(false); + } }); - }, [page, targetId, targetType]); + }, [targetId, targetType]); const onCommentSubmitted = ({ commentContent, isPrivate, showClientInfo }: { commentContent: string, isPrivate: boolean, showClientInfo: boolean }) => { createComment({