From bcee670ac6617ada6cfbf2379283438a8e7f8add Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Mon, 28 Jul 2025 07:44:56 +0200 Subject: [PATCH] :bug: Fix switching theme for wasm render --- frontend/src/app/render_wasm/api.cljs | 6 +++ frontend/src/app/render_wasm/shape.cljs | 54 ++++++++++++++----------- 2 files changed, 36 insertions(+), 24 deletions(-) diff --git a/frontend/src/app/render_wasm/api.cljs b/frontend/src/app/render_wasm/api.cljs index 0bf4096577..109532b0f5 100644 --- a/frontend/src/app/render_wasm/api.cljs +++ b/frontend/src/app/render_wasm/api.cljs @@ -1065,3 +1065,9 @@ (js/console.error cause) (p/resolved false))))) (p/resolved false)))) + +(defn shape-in-current-page? + "Check if a shape is in the current page by looking up the current page objects" + [shape-id] + (let [objects (deref refs/workspace-page-objects)] + (contains? objects shape-id))) diff --git a/frontend/src/app/render_wasm/shape.cljs b/frontend/src/app/render_wasm/shape.cljs index f5b581f674..298a7ff353 100644 --- a/frontend/src/app/render_wasm/shape.cljs +++ b/frontend/src/app/render_wasm/shape.cljs @@ -208,31 +208,13 @@ (defn set-wasm-multi-attrs! [shape properties] - (api/use-shape (:id shape)) - (let [result - (->> properties - (mapcat #(set-wasm-single-attr! shape %))) - pending (-> (d/index-by :key :callback result) vals)] - (if (and pending (seq pending)) - (->> (rx/from pending) - (rx/mapcat (fn [callback] (callback))) - (rx/reduce conj []) - (rx/subs! - (fn [_] - (api/update-shape-tiles) - (api/clear-drawing-cache) - (api/request-render "set-wasm-attrs-pending")))) - (do - (api/update-shape-tiles) - (api/request-render "set-wasm-attrs"))))) - -(defn set-wasm-attrs! - [shape k v] - (let [shape (assoc shape k v)] + ;; Only call WASM API if the shape is in the current page + (when (api/shape-in-current-page? (:id shape)) (api/use-shape (:id shape)) - (let [result (set-wasm-single-attr! shape k) + (let [result + (->> properties + (mapcat #(set-wasm-single-attr! shape %))) pending (-> (d/index-by :key :callback result) vals)] - ;; TODO: set-wasm-attrs is called twice with every set (if (and pending (seq pending)) (->> (rx/from pending) (rx/mapcat (fn [callback] (callback))) @@ -246,6 +228,28 @@ (api/update-shape-tiles) (api/request-render "set-wasm-attrs")))))) +(defn set-wasm-attrs! + [shape k v] + (let [shape (assoc shape k v)] + ;; Only call WASM API if the shape is in the current page + (when (api/shape-in-current-page? (:id shape)) + (api/use-shape (:id shape)) + (let [result (set-wasm-single-attr! shape k) + pending (-> (d/index-by :key :callback result) vals)] + ;; TODO: set-wasm-attrs is called twice with every set + (if (and pending (seq pending)) + (->> (rx/from pending) + (rx/mapcat (fn [callback] (callback))) + (rx/reduce conj []) + (rx/subs! + (fn [_] + (api/update-shape-tiles) + (api/clear-drawing-cache) + (api/request-render "set-wasm-attrs-pending")))) + (do + (api/update-shape-tiles) + (api/request-render "set-wasm-attrs"))))))) + (defn- impl-assoc [self k v] (when ^boolean shape/*wasm-sync* @@ -274,7 +278,9 @@ [self k] (when ^boolean shape/*wasm-sync* (binding [shape/*wasm-sync* false] - (set-wasm-attrs! self k nil))) + ;; Only call WASM API if the shape is in the current page + (when (api/shape-in-current-page? (.-id ^ShapeProxy self)) + (set-wasm-attrs! self k nil)))) (case k :id