mirror of
https://github.com/penpot/penpot.git
synced 2026-05-29 19:58:09 +00:00
🐛 Fix shapes not being rendered after render switch
This commit is contained in:
parent
6d6f624d09
commit
4a73a97a32
@ -18,7 +18,9 @@
|
|||||||
[app.main.data.helpers :as dsh]
|
[app.main.data.helpers :as dsh]
|
||||||
[app.main.features :as features]
|
[app.main.features :as features]
|
||||||
[app.main.worker :as mw]
|
[app.main.worker :as mw]
|
||||||
|
[app.render-wasm.api :as wasm.api]
|
||||||
[app.render-wasm.shape :as wasm.shape]
|
[app.render-wasm.shape :as wasm.shape]
|
||||||
|
[app.render-wasm.wasm :as wasm]
|
||||||
[beicon.v2.core :as rx]
|
[beicon.v2.core :as rx]
|
||||||
[potok.v2.core :as ptk]))
|
[potok.v2.core :as ptk]))
|
||||||
|
|
||||||
@ -76,6 +78,31 @@
|
|||||||
(def ^:private xf:map-page-id
|
(def ^:private xf:map-page-id
|
||||||
(map :page-id))
|
(map :page-id))
|
||||||
|
|
||||||
|
(def ^:private wasm-structural-change-types
|
||||||
|
#{:add-obj :mov-objects})
|
||||||
|
|
||||||
|
(defn- redo-changes-need-wasm-object-sync?
|
||||||
|
[redo-changes]
|
||||||
|
(some #(contains? wasm-structural-change-types (:type %)) redo-changes))
|
||||||
|
|
||||||
|
(defn- sync-wasm-structural-changes
|
||||||
|
[{:keys [redo-changes]}]
|
||||||
|
(ptk/reify ::sync-wasm-structural-changes
|
||||||
|
ptk/EffectEvent
|
||||||
|
(effect [_ state _]
|
||||||
|
(when (and wasm/context-initialized?
|
||||||
|
(not @wasm/context-lost?))
|
||||||
|
(let [objects (dsh/lookup-page-objects state)]
|
||||||
|
(doseq [{:keys [type id parent-id]} redo-changes
|
||||||
|
:when (contains? wasm-structural-change-types type)
|
||||||
|
:let [shape-id (case type
|
||||||
|
:add-obj id
|
||||||
|
:mov-objects parent-id)
|
||||||
|
shape (get objects shape-id)]
|
||||||
|
:when shape]
|
||||||
|
(wasm.api/process-object shape))
|
||||||
|
(wasm.api/request-render "sync-wasm-structural-changes"))))))
|
||||||
|
|
||||||
(defn- apply-changes-localy
|
(defn- apply-changes-localy
|
||||||
[{:keys [file-id redo-changes ignore-wasm?] :as commit} pending]
|
[{:keys [file-id redo-changes ignore-wasm?] :as commit} pending]
|
||||||
(ptk/reify ::apply-changes-localy
|
(ptk/reify ::apply-changes-localy
|
||||||
@ -118,7 +145,16 @@
|
|||||||
state)
|
state)
|
||||||
|
|
||||||
;; wasm renderer deactivated
|
;; wasm renderer deactivated
|
||||||
(update-in state [:files file-id :data] apply-changes))))))
|
(update-in state [:files file-id :data] apply-changes))))
|
||||||
|
|
||||||
|
ptk/WatchEvent
|
||||||
|
(watch [_ state _]
|
||||||
|
;; `:add-obj` / `:mov-objects` are not tracked via `*shape-changes*`.
|
||||||
|
;; Emit only for structural commits, after file data is in state.
|
||||||
|
(when (and (not ignore-wasm?)
|
||||||
|
(features/active-feature? state "render-wasm/v1")
|
||||||
|
(redo-changes-need-wasm-object-sync? redo-changes))
|
||||||
|
(rx/of (sync-wasm-structural-changes {:redo-changes redo-changes}))))))
|
||||||
|
|
||||||
(defn commit
|
(defn commit
|
||||||
"Create a commit event instance"
|
"Create a commit event instance"
|
||||||
|
|||||||
@ -306,19 +306,6 @@
|
|||||||
(rx/map bundle-fetched)
|
(rx/map bundle-fetched)
|
||||||
(rx/take-until stopper-s))))))
|
(rx/take-until stopper-s))))))
|
||||||
|
|
||||||
;; FIXME: this need docstring
|
|
||||||
(defn- process-wasm-object
|
|
||||||
[id]
|
|
||||||
(ptk/reify ::process-wasm-object
|
|
||||||
ptk/EffectEvent
|
|
||||||
(effect [_ state _]
|
|
||||||
(let [objects (dsh/lookup-page-objects state)
|
|
||||||
shape (get objects id)]
|
|
||||||
;; Only process objects that exist in the current page
|
|
||||||
;; This prevents errors when processing changes from other pages
|
|
||||||
(when shape
|
|
||||||
(wasm.api/process-object shape))))))
|
|
||||||
|
|
||||||
(defn initialize-file
|
(defn initialize-file
|
||||||
[team-id file-id]
|
[team-id file-id]
|
||||||
(assert (uuid? team-id) "expected valud uuid for `team-id`")
|
(assert (uuid? team-id) "expected valud uuid for `team-id`")
|
||||||
@ -444,18 +431,6 @@
|
|||||||
(rx/take 1)
|
(rx/take 1)
|
||||||
(rx/map #(dwcm/navigate-to-comment-id comment-id))))
|
(rx/map #(dwcm/navigate-to-comment-id comment-id))))
|
||||||
|
|
||||||
(->> stream
|
|
||||||
(rx/filter dch/commit?)
|
|
||||||
(rx/filter render-wasm-ready?)
|
|
||||||
(rx/map deref)
|
|
||||||
(rx/mapcat
|
|
||||||
(fn [{:keys [redo-changes]}]
|
|
||||||
(let [added (->> redo-changes
|
|
||||||
(filter #(= (:type %) :add-obj))
|
|
||||||
(map :id))]
|
|
||||||
(->> (rx/from added)
|
|
||||||
(rx/map process-wasm-object))))))
|
|
||||||
|
|
||||||
(let [local-commits-s
|
(let [local-commits-s
|
||||||
(->> stream
|
(->> stream
|
||||||
(rx/filter dch/commit?)
|
(rx/filter dch/commit?)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user