From 1cc09e4cbc07fb37b17a357ba3518eb165856f8d Mon Sep 17 00:00:00 2001 From: xfy Date: Wed, 24 Jun 2026 10:38:33 +0800 Subject: [PATCH] fix(bridge): use unchecked_into for TiptapEditorModule (not dyn_into) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit dyn_into runs 'instanceof TiptapEditorModule', but the IIFE TiptapEditor is a plain object literal — not an instance of wasm-bindgen's registered constructor — so the check always fails with a panic. unchecked_into does only the compile-time type annotation; Reflect::get already guarantees we have the right object. --- src/tiptap_bridge.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/tiptap_bridge.rs b/src/tiptap_bridge.rs index f9fb518..fccb673 100644 --- a/src/tiptap_bridge.rs +++ b/src/tiptap_bridge.rs @@ -56,11 +56,14 @@ pub mod wasm { /// 读取 `window.TiptapEditor`(IIFE 默认导出,顶层 var 即 window 属性)。 /// 用 Reflect::get 做属性访问——extern fn 形式会被 wasm-bindgen 编成函数调用。 + /// + /// 用 unchecked_into 而非 dyn_into:TiptapEditor 是 JS 对象字面量, + /// 不是 wasm-bindgen 注册的构造函数实例,dyn_into 的 instanceof 检查必然失败。 + /// unchecked_into 只做编译期类型标注,不做运行时校验(Reflect.get 已保证拿到的是目标对象)。 pub fn get_module() -> TiptapEditorModule { let window = web_sys::window().expect("no window"); let val = js_sys::Reflect::get(&window, &"TiptapEditor".into()).expect("window.TiptapEditor missing"); - val.dyn_into::() - .expect("window.TiptapEditor is not TiptapEditorModule") + val.unchecked_into::() } // —— 编辑器实例(TiptapEditorInstance)——