0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-09 00:10:11 -05:00

🐛 Avoid loops in main instance sync

This commit is contained in:
Andrés Moya 2022-09-12 11:24:11 +02:00
parent c4c419b971
commit 5d3eadc6db
2 changed files with 26 additions and 4 deletions

View file

@ -472,7 +472,7 @@
(defmulti components-changed (fn [_ change] (:type change)))
(defmethod components-changed :mod-obj
[file-data {:keys [id page-id _component-id operations]}]
[file-data {:keys [id page-id operations]}]
(when page-id
(let [page (ctpl/get-page file-data page-id)
shape-and-parents (map #(ctn/get-shape page %)

View file

@ -721,7 +721,13 @@
(when sync-typographies?
(dwlh/generate-sync-file it file-id :typographies asset-id library-id state))])
changes (pcb/concat-changes library-changes file-changes)]
changes (pcb/concat-changes library-changes file-changes)
changes (cond-> changes
; Store the origin component to avoid sync loops
(= asset-type :components)
(update :redo-changes
#(vary-meta % assoc :origin-component-id asset-id)))]
(log/debug :msg "SYNC-FILE finished" :js/rchanges (log-changes
(:redo-changes changes)
@ -842,10 +848,25 @@
check-changes
(fn [[event data]]
(let [{:keys [changes save-undo?]} (deref event)
(let [page (wsh/lookup-page state)
[{:keys [changes save-undo?]} (deref event)
components-changed (reduce #(into %1 (ch/components-changed data %2))
#{}
changes)]
changes)
orig-component-id (get (meta changes) :origin-component-id)
is-orig (fn [shape-id]
(let [shape (ctn/get-shape page shape-id)]
(= (:component-id shape) orig-component-id)))
;; If the changes are derived of the synchronization of a main component,
;; ignore them to avoid entering loops.
components-changed (if orig-component-id
(set (remove is-orig components-changed))
components-changed)]
(when (and (d/not-empty? components-changed) save-undo?)
(log/info :msg "DETECTED COMPONENTS CHANGED"
:ids (map str components-changed))
@ -890,6 +911,7 @@
(let [state (dissoc state :files)]
(assoc state :workspace-shared-files files)))))
(defn fetch-shared-files
[{:keys [team-id] :as params}]
(us/assert ::us/uuid team-id)