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;