From a72a167a5f2d959567a82304f522aa4188e5f912 Mon Sep 17 00:00:00 2001 From: xfy Date: Wed, 8 Jul 2026 15:38:29 +0800 Subject: [PATCH] fix(comment): resolve potential SSR hydration mismatch in CommentSection --- src/components/comments/section.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/components/comments/section.rs b/src/components/comments/section.rs index 726c0ef..3565616 100644 --- a/src/components/comments/section.rs +++ b/src/components/comments/section.rs @@ -40,17 +40,21 @@ pub struct CommentContext { /// - 空评论时展示提示文案 #[component] pub fn CommentSection(post_id: i32) -> Element { - let ctx = use_context_provider(|| { - let pending: Vec = comment_storage::load_pending_comments(post_id); - comment_storage::prune_all_expired(); - + let mut ctx = use_context_provider(|| { CommentContext { active_reply: Signal::new(None), refresh_trigger: Signal::new(false), - pending_comments: Signal::new(pending), + pending_comments: Signal::new(Vec::new()), } }); + // 挂载后从本地存储异步加载待审核评论以防 SSR Hydration Mismatch + use_effect(move || { + let pending = comment_storage::load_pending_comments(post_id); + comment_storage::prune_all_expired(); + ctx.pending_comments.set(pending); + }); + // 轮询待审核评论状态,已处理(非 pending)的评论从本地移除 use_future(move || { let mut pending = ctx.pending_comments;