fix(comments): address code quality issues in CommentForm

- Add mount guard (loaded signal) to use_effect to prevent re-firing
- Add in-flight guard at top of onclick handler to prevent double submits
- Prevent overwriting user input when clearing form fields
This commit is contained in:
xfy 2026-06-11 14:49:48 +08:00
parent f855a9a6cd
commit aa68dc4c55

View File

@ -19,11 +19,13 @@ pub fn CommentForm(post_id: i32, parent_id: Option<i64>) -> Element {
let mut honeypot = use_signal(String::new);
let mut submitting = use_signal(|| false);
let mut message = use_signal(|| Option::<(String, &'static str)>::None);
let mut loaded = use_signal(|| false);
use_effect(move || {
if !author_name().is_empty() {
if loaded() {
return;
}
loaded.set(true);
if let Some(info) = comment_storage::load_author() {
author_name.set(info.name);
author_email.set(info.email);
@ -117,6 +119,10 @@ pub fn CommentForm(post_id: i32, parent_id: Option<i64>) -> Element {
class: BUTTON_PRIMARY_CLASS,
disabled: submitting(),
onclick: move |_| {
if submitting() {
return;
}
let post_id = post_id;
let parent_id = parent_id;
let name = author_name();