0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-24 15:39:50 -05:00

♻️ Try to fix recursive update-file ops on text edition

on concurrent multi-user sessions
This commit is contained in:
Andrey Antukh 2024-06-18 16:31:43 +02:00 committed by Alonso Torres
parent a2cc7764fb
commit d527184dfc
5 changed files with 16 additions and 50 deletions

View file

@ -770,15 +770,6 @@
(update :undo-changes conj {:type :del-component
:id id
:main-instance main-instance})))
(defn ignore-remote
[changes]
(letfn [(add-ignore-remote
[change-list]
(->> change-list
(mapv #(assoc % :ignore-remote? true))))]
(-> changes
(update :redo-changes add-ignore-remote)
(update :undo-changes add-ignore-remote))))
(defn reorder-grid-children
[changes ids]

View file

@ -207,40 +207,16 @@
(-deref [_] {:changes changes})
ptk/WatchEvent
(watch [_ state _]
(let [page-id (:current-page-id state)
position-data-operation?
(fn [{:keys [type attr]}]
(and (= :set type)
(= attr :position-data)))
update-position-data
(fn [change]
;; Remove the position data from remote operations. Will be changed localy, otherwise
;; creates a strange "out-of-sync" behaviour.
(cond-> change
(and (= page-id (:page-id change))
(= :mod-obj (:type change)))
(update :operations #(d/removev position-data-operation? %))))
;; We update `position-data` from the incoming message
changes (->> changes
(map update-position-data)
(remove (fn [change]
(and (= page-id (:page-id change))
(:ignore-remote? change))))
(vec))]
;; The commit event is responsible to apply the data localy
;; and update the persistence internal state with the updated
;; file-revn
(rx/of (dch/commit {:file-id file-id
:file-revn revn
:save-undo? false
:source :remote
:redo-changes changes
:undo-changes []}))))))
(watch [_ _ _]
;; The commit event is responsible to apply the data localy
;; and update the persistence internal state with the updated
;; file-revn
(rx/of (dch/commit {:file-id file-id
:file-revn revn
:save-undo? false
:source :remote
:redo-changes (vec changes)
:undo-changes []})))))
(def ^:private
schema:handle-library-change

View file

@ -46,8 +46,8 @@
(defn update-shapes
([ids update-fn] (update-shapes ids update-fn nil))
([ids update-fn {:keys [reg-objects? save-undo? stack-undo? attrs ignore-tree page-id ignore-remote? ignore-touched undo-group with-objects?]
:or {reg-objects? false save-undo? true stack-undo? false ignore-remote? false ignore-touched false with-objects? false}}]
([ids update-fn {:keys [reg-objects? save-undo? stack-undo? attrs ignore-tree page-id ignore-touched undo-group with-objects?]
:or {reg-objects? false save-undo? true stack-undo? false ignore-touched false with-objects? false}}]
(dm/assert!
"expected a valid coll of uuid's"
@ -84,8 +84,7 @@
changes (add-undo-group changes state)]
(rx/concat
(if (seq (:redo-changes changes))
(let [changes (cond-> changes reg-objects? (pcb/resize-parents ids))
changes (cond-> changes ignore-remote? (pcb/ignore-remote))]
(let [changes (cond-> changes reg-objects? (pcb/resize-parents ids))]
(rx/of (dch/commit-changes changes)))
(rx/empty))

View file

@ -391,7 +391,6 @@
(rx/of (dwu/start-undo-transaction undo-id)
(dwsh/update-shapes ids update-fn {:reg-objects? true
:stack-undo? true
:ignore-remote? true
:ignore-touched true})
(ptk/data-event :layout/update {:ids ids})
(dwu/commit-undo-transaction undo-id))))))))
@ -536,7 +535,7 @@
(fn [shape]
(-> shape
(assoc :position-data (get position-data (:id shape)))))
{:stack-undo? true :reg-objects? false :ignore-remote? true}))
{:stack-undo? true :reg-objects? false}))
(rx/of (fn [state]
(dissoc state ::update-position-data-debounce ::update-position-data))))))))

View file

@ -29,7 +29,8 @@
[promesa.core :as p]
[rumext.v2 :as mf]))
(defn fix-position [shape]
(defn fix-position
[shape]
(if-let [modifiers (:modifiers shape)]
(let [shape' (gsh/transform-shape shape modifiers)