Merge pull request #6984 from penpot/superalex-fix-switching-theme-form-wasm-render

🐛 Fix switching theme for wasm render
This commit is contained in:
Elena Torró 2025-07-28 11:30:41 +02:00 committed by GitHub
commit ff7e34e308
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 36 additions and 24 deletions

View file

@ -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)))

View file

@ -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