From e6a49adfbc0876d2577fdaa8ff1d7e45b13d758e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bel=C3=A9n=20Albeza?= Date: Tue, 30 Jun 2026 13:55:06 +0200 Subject: [PATCH] :bug: Fix crash on composition update when pressing Esc on a IME (#10479) --- .../ui/workspace/shapes/text/v3_editor.cljs | 17 +++++++++-------- render-wasm/src/wasm/text_editor.rs | 4 ++-- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/shapes/text/v3_editor.cljs b/frontend/src/app/main/ui/workspace/shapes/text/v3_editor.cljs index 749c5af69f..450db8f839 100644 --- a/frontend/src/app/main/ui/workspace/shapes/text/v3_editor.cljs +++ b/frontend/src/app/main/ui/workspace/shapes/text/v3_editor.cljs @@ -81,8 +81,10 @@ (when-not composing? (reset! composing? true)) + ;; IME cancel (e.g. Escape on Linux ibus-mozc) fires compositionupdate + ;; with an empty string; that must reach WASM to clear the preview text. (let [data (.-data event)] - (when data + (when (some? data) (text-editor/text-editor-composition-update data) (sync-wasm-text-editor-content!) (wasm.api/request-render "text-composition")) @@ -93,13 +95,12 @@ (mf/use-fn (fn [^js event] (reset! composing? false) - (let [data (.-data event)] - (when data - (text-editor/text-editor-composition-end data) - (sync-wasm-text-editor-content!) - (wasm.api/request-render "text-composition")) - (when-let [node (mf/ref-val contenteditable-ref)] - (set! (.-textContent node) ""))))) + (let [data (or (.-data event) "")] + (text-editor/text-editor-composition-end data) + (sync-wasm-text-editor-content!) + (wasm.api/request-render "text-composition")) + (when-let [node (mf/ref-val contenteditable-ref)] + (set! (.-textContent node) "")))) on-paste (mf/use-fn diff --git a/render-wasm/src/wasm/text_editor.rs b/render-wasm/src/wasm/text_editor.rs index 6fc4a3e20a..189bbd8713 100644 --- a/render-wasm/src/wasm/text_editor.rs +++ b/render-wasm/src/wasm/text_editor.rs @@ -324,7 +324,7 @@ pub extern "C" fn text_editor_composition_start() -> Result<()> { #[no_mangle] #[wasm_error] pub extern "C" fn text_editor_composition_end() -> Result<()> { - let bytes = crate::mem::bytes(); + let bytes = crate::mem::bytes_or_empty(); let text = match String::from_utf8(bytes) { Ok(text) => text, Err(_) => return Ok(()), @@ -380,7 +380,7 @@ pub extern "C" fn text_editor_composition_end() -> Result<()> { #[no_mangle] #[wasm_error] pub extern "C" fn text_editor_composition_update() -> Result<()> { - let bytes = crate::mem::bytes(); + let bytes = crate::mem::bytes_or_empty(); let text = match String::from_utf8(bytes) { Ok(text) => text, Err(_) => return Ok(()),