From 3f5226485b600f1ea8d96102fd01efe7c38b64c4 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Wed, 8 Apr 2026 16:10:44 +0200 Subject: [PATCH 1/3] :bug: Fix problem when changing font and grow text --- .../src/app/main/data/workspace/texts.cljs | 25 +++++++++++++++---- frontend/src/app/render_wasm/api/fonts.cljs | 7 ++++-- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/frontend/src/app/main/data/workspace/texts.cljs b/frontend/src/app/main/data/workspace/texts.cljs index 451b4fb8ae..fe12f88804 100644 --- a/frontend/src/app/main/data/workspace/texts.cljs +++ b/frontend/src/app/main/data/workspace/texts.cljs @@ -400,7 +400,11 @@ shape-ids (cond (cfh/text-shape? shape) [id] (cfh/group-shape? shape) (cfh/get-children-ids objects id))] - (rx/of (dwsh/update-shapes shape-ids update-fn)))))) + (rx/concat + (rx/of (dwsh/update-shapes shape-ids update-fn)) + (if (features/active-feature? state "render-wasm/v1") + (dwwt/resize-wasm-text-debounce id) + (rx/empty))))))) (defn update-root-attrs [{:keys [id attrs]}] @@ -786,11 +790,18 @@ (rx/of (update-position-data id position-data)))) (rx/empty)))))) +(defn font-loaded-event? + [font-id] + (fn [event] + (and + (= :font-loaded (ptk/type event)) + (= (:font-id (deref event)) font-id)))) + (defn update-attrs [id attrs] (ptk/reify ::update-attrs ptk/WatchEvent - (watch [_ state _] + (watch [_ state stream] (let [text-editor-instance (:workspace-editor state)] (if (and (features/active-feature? state "text-editor/v2") (some? text-editor-instance)) @@ -828,9 +839,13 @@ (:shape-id result) (:content result) :update-name? true)))))))) ;; Resize (with delay for font-id changes) - (cond->> (rx/of (dwwt/resize-wasm-text id)) - (contains? attrs :font-id) - (rx/delay 200)))))))) + (if (contains? attrs :font-id) + (->> stream + (rx/filter (font-loaded-event? (:font-id attrs))) + (rx/take 1) + (rx/observe-on :async) + (rx/map #(dwwt/resize-wasm-text id))) + (rx/of (dwwt/resize-wasm-text id))))))))) ptk/EffectEvent (effect [_ state _] diff --git a/frontend/src/app/render_wasm/api/fonts.cljs b/frontend/src/app/render_wasm/api/fonts.cljs index 474a705979..3c011cd3db 100644 --- a/frontend/src/app/render_wasm/api/fonts.cljs +++ b/frontend/src/app/render_wasm/api/fonts.cljs @@ -21,7 +21,8 @@ [cuerdas.core :as str] [goog.object :as gobj] [lambdaisland.uri :as u] - [okulary.core :as l])) + [okulary.core :as l] + [potok.v2.core :as ptk])) (def ^:private fonts (l/derived :fonts st/state)) @@ -127,6 +128,7 @@ mem (js/Uint8Array. (.-buffer heap) ptr size)] (.set mem (js/Uint8Array. font-array-buffer)) + (st/emit! (ptk/data-event :font-loaded {:font-id (:font-id font-data)})) (h/call wasm/internal-module "_store_font" (aget font-id-buffer 0) (aget font-id-buffer 1) @@ -208,7 +210,8 @@ id-buffer (uuid/get-u32 (:wasm-id font-data)) font-data (assoc font-data :family-id-buffer id-buffer) font-stored? (font-stored? font-data emoji?)] - (when-not font-stored? + (if font-stored? + (st/async-emit! (ptk/data-event :font-loaded {:font-id (:font-id font-data)})) (fetch-font font-data uri emoji? fallback?))))) (defn serialize-font-style From e3bafab529eeca99131b1bf7ee3a98579a498ad7 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Wed, 8 Apr 2026 16:50:49 +0200 Subject: [PATCH 2/3] :bug: Fix problem with resizes in plugins --- frontend/src/app/main/data/workspace/wasm_text.cljs | 4 +++- frontend/src/app/plugins/text.cljs | 13 ++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/frontend/src/app/main/data/workspace/wasm_text.cljs b/frontend/src/app/main/data/workspace/wasm_text.cljs index c175b46bdf..e67cb77e97 100644 --- a/frontend/src/app/main/data/workspace/wasm_text.cljs +++ b/frontend/src/app/main/data/workspace/wasm_text.cljs @@ -23,6 +23,8 @@ [beicon.v2.core :as rx] [potok.v2.core :as ptk])) +(def debounce-resize-text-time 40) + (defn get-wasm-text-new-size "Computes the new {width, height} for a text shape from WASM text layout. For :fixed grow-type, updates WASM content and returns current dimensions (no resize)." @@ -144,7 +146,7 @@ (rx/merge (->> stream (rx/filter (ptk/type? ::resize-wasm-text-debounce-inner)) - (rx/debounce 40) + (rx/debounce debounce-resize-text-time) (rx/take 1) (rx/map (fn [evt] (resize-wasm-text-debounce-commit diff --git a/frontend/src/app/plugins/text.cljs b/frontend/src/app/plugins/text.cljs index 1154af2366..aa4539c980 100644 --- a/frontend/src/app/plugins/text.cljs +++ b/frontend/src/app/plugins/text.cljs @@ -15,6 +15,8 @@ [app.common.types.text :as txt] [app.main.data.workspace.shapes :as dwsh] [app.main.data.workspace.texts :as dwt] + [app.main.data.workspace.wasm-text :as dwwt] + [app.main.features :as features] [app.main.fonts :as fonts] [app.main.store :as st] [app.plugins.format :as format] @@ -417,8 +419,10 @@ (st/emit! (dwt/update-editor-state shape editor))) :else - (st/emit! (dwsh/update-shapes [id] - #(update % :content txt/change-text value))))))} + (do + (st/emit! (dwsh/update-shapes [id] #(update % :content txt/change-text value))) + (when (features/active-feature? @st/state "render-wasm/v1") + (st/emit! (dwwt/resize-wasm-text-debounce id)))))))} {:name "growType" :get #(-> % u/proxy->shape :grow-type d/name) @@ -434,7 +438,10 @@ (u/not-valid plugin-id :growType "Plugin doesn't have 'content:write' permission") :else - (st/emit! (dwsh/update-shapes [id] #(assoc % :grow-type value))))))} + (st/emit! + (dwsh/update-shapes [id] #(assoc % :grow-type value)) + (when (features/active-feature? @st/state "render-wasm/v1") + (st/emit! (dwwt/resize-wasm-text-debounce id)))))))} {:name "fontId" :get #(-> % u/proxy->shape text-props :font-id format/format-mixed) From 4d2d5593835c96bf9b3c5499334a93c1e7221f75 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Wed, 15 Apr 2026 15:57:12 +0200 Subject: [PATCH 3/3] :bug: Fix problem with finish render callback --- frontend/src/app/render_wasm/api.cljs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/frontend/src/app/render_wasm/api.cljs b/frontend/src/app/render_wasm/api.cljs index da5ce35e72..c23a872334 100644 --- a/frontend/src/app/render_wasm/api.cljs +++ b/frontend/src/app/render_wasm/api.cljs @@ -1120,11 +1120,13 @@ (if (or (seq pending-thumbnails) (seq pending-full)) (->> (rx/concat (->> (rx/from (vals pending-thumbnails)) - (rx/merge-map (fn [callback] (callback))) - (rx/reduce conj [])) + (rx/merge-map (fn [callback] (if (fn? callback) (callback) (rx/empty)))) + (rx/reduce conj []) + (rx/catch #(rx/empty))) (->> (rx/from (vals pending-full)) - (rx/mapcat (fn [callback] (callback))) - (rx/reduce conj []))) + (rx/mapcat (fn [callback] (if (fn? callback) (callback) (rx/empty)))) + (rx/reduce conj []) + (rx/catch #(rx/empty)))) (rx/subs! (fn [_] ;; Fonts are now loaded — recompute text layouts so Skia @@ -1134,7 +1136,7 @@ (update-text-layouts text-ids))) (request-render "images-loaded")) noop-fn - (fn [] (when on-complete (on-complete))))) + (fn [] (when (fn? on-complete) (on-complete))))) ;; No pending images — complete immediately. (when on-complete (on-complete)))))