From 975e331dd5712a4719cc1f831db4c51d8c675793 Mon Sep 17 00:00:00 2001 From: xfy Date: Tue, 23 Jun 2026 14:44:18 +0800 Subject: [PATCH] fix(write): split tags on fullwidth punctuation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The tag splitter matched ASCII ',' and ';' twice instead of the fullwidth ',' (U+FF0C) / ';' (U+FF1B) the comment intended, so tags separated by fullwidth punctuation (common under Chinese IMEs) collapsed into a single tag. Also resolves the compiler warnings surfaced in the same build: - tiptap_bridge: drop unused Readable/Writable imports and EditorInstance/TiptapEditorModule re-exports - tiptap_bridge: migrate deprecated RequestInit::method/body/ credentials builders to set_method/set_body/set_credentials - write: remove redundant `mut` on Dioxus signals that are only read/set, never reassigned - image_viewer: gate the server-only `mut` reassignment so the WASM build (which strips the cfg block) doesn't warn --- src/components/image_viewer.rs | 3 +++ src/pages/admin/write.rs | 8 ++++---- src/tiptap_bridge.rs | 17 +++++++++-------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/components/image_viewer.rs b/src/components/image_viewer.rs index 6b5ef7d..08eba13 100644 --- a/src/components/image_viewer.rs +++ b/src/components/image_viewer.rs @@ -73,6 +73,9 @@ pub fn ImageViewer( // 计算 aspect-ratio:SSR 时读图片真实尺寸。WASM 端不读(--ar 已在 SSR 写入 HTML)。 // 非 /uploads/ 的外链图或读不到尺寸时不设 --ar。 let ar_style = { + // `mut` 仅 server 构建需要:WASM 构建剥离 #[cfg(feature = "server")] 块后, + // s 从未被重新赋值,故对 WASM 抑制 unused_mut。 + #[cfg_attr(not(feature = "server"), allow(unused_mut))] let mut s = String::new(); #[cfg(feature = "server")] { diff --git a/src/pages/admin/write.rs b/src/pages/admin/write.rs index 4d73255..0b284f4 100644 --- a/src/pages/admin/write.rs +++ b/src/pages/admin/write.rs @@ -78,11 +78,11 @@ fn write_editor(post_id: Option) -> Element { let mut editor: Signal> = use_signal(|| None); // WASM 前端:编辑器就绪标志(onReady 回调驱动,替代 __tiptap_ready 轮询)。 #[cfg(target_arch = "wasm32")] - let mut ready = use_signal(|| false); + let ready = use_signal(|| false); // 上传状态:当前进行中计数(保存拦截)+ 顶部失败提示堆叠(用户手动关闭) - let mut uploads_in_flight = use_signal(UploadsInFlight::default); - let mut upload_errors: Signal> = use_signal(Vec::new); + let uploads_in_flight = use_signal(UploadsInFlight::default); + let upload_errors: Signal> = use_signal(Vec::new); // 编辑模式:文章数据加载完成后,将字段回填到表单信号。 use_effect(move || { @@ -261,7 +261,7 @@ fn write_editor(post_id: Option) -> Element { // 将逗号分隔的标签字符串转换为列表。 // 同时支持半角/全角逗号与分号,避免中文输入法下的全角标点被误并入单个标签。 let tags_list: Vec = tags() - .split(|c| matches!(c, ',' | ',' | ';' | ';')) + .split(|c| matches!(c, ',' | ',' | ';' | ';')) .map(|t| t.trim().to_string()) .filter(|t| !t.is_empty()) .collect(); diff --git a/src/tiptap_bridge.rs b/src/tiptap_bridge.rs index 0225baf..a3c180a 100644 --- a/src/tiptap_bridge.rs +++ b/src/tiptap_bridge.rs @@ -29,8 +29,8 @@ pub struct UploadErrorEntry { #[cfg(target_arch = "wasm32")] pub mod wasm { use super::{UploadErrorEntry, UploadsInFlight}; - // WritableExt 提供 .write();Writable 提供 .set()。Signal 方法需 trait 在作用域内。 - use dioxus::prelude::{Readable, Writable, WritableExt}; + // WritableExt 提供 .write()(Signal 在 Copy 语义下不需要 mut 绑定)。 + use dioxus::prelude::WritableExt; use wasm_bindgen::prelude::*; use wasm_bindgen::JsCast; @@ -251,10 +251,11 @@ pub mod wasm { .map_err(|_| js_sys::Error::new("无法附加文件"))?; // 构造 POST 请求,credentials same-origin 携带 session cookie - let mut init = web_sys::RequestInit::new(); - init.method("POST"); - init.body(Some(&form)); - init.credentials(web_sys::RequestCredentials::SameOrigin); + let init = web_sys::RequestInit::new(); + init.set_method("POST"); + // set_body 接收 &JsValue(非 Option);FormData: AsRef。 + init.set_body(form.as_ref()); + init.set_credentials(web_sys::RequestCredentials::SameOrigin); let request = web_sys::Request::new_with_str_and_init("/api/upload", &init) .map_err(|_| js_sys::Error::new("无法构造上传请求"))?; @@ -300,6 +301,6 @@ pub mod wasm { #[cfg(target_arch = "wasm32")] pub use wasm::{ - consume_upload_event, make_upload_closure, EditorHandle, EditorInstance, EditorOptions, - TiptapEditorModule, UploadEventJs, get_module, + consume_upload_event, make_upload_closure, EditorHandle, EditorOptions, UploadEventJs, + get_module, };