mirror of
https://github.com/penpot/penpot.git
synced 2025-02-13 18:48:37 -05:00
🐛 Avoid loops in main instance sync
This commit is contained in:
parent
c9ad82edc3
commit
9bf0c6e681
2 changed files with 26 additions and 4 deletions
|
@ -459,7 +459,7 @@
|
||||||
(defmulti components-changed (fn [_ change] (:type change)))
|
(defmulti components-changed (fn [_ change] (:type change)))
|
||||||
|
|
||||||
(defmethod components-changed :mod-obj
|
(defmethod components-changed :mod-obj
|
||||||
[file-data {:keys [id page-id _component-id operations]}]
|
[file-data {:keys [id page-id operations]}]
|
||||||
(when page-id
|
(when page-id
|
||||||
(let [page (ctpl/get-page file-data page-id)
|
(let [page (ctpl/get-page file-data page-id)
|
||||||
shape-and-parents (map #(ctn/get-shape page %)
|
shape-and-parents (map #(ctn/get-shape page %)
|
||||||
|
|
|
@ -729,7 +729,13 @@
|
||||||
(when sync-typographies?
|
(when sync-typographies?
|
||||||
(dwlh/generate-sync-file it file-id :typographies asset-id library-id state))])
|
(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
|
(log/debug :msg "SYNC-FILE finished" :js/rchanges (log-changes
|
||||||
(:redo-changes changes)
|
(:redo-changes changes)
|
||||||
|
@ -850,10 +856,25 @@
|
||||||
|
|
||||||
check-changes
|
check-changes
|
||||||
(fn [[event data]]
|
(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))
|
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?)
|
(when (and (d/not-empty? components-changed) save-undo?)
|
||||||
(log/info :msg "DETECTED COMPONENTS CHANGED"
|
(log/info :msg "DETECTED COMPONENTS CHANGED"
|
||||||
:ids (map str components-changed))
|
:ids (map str components-changed))
|
||||||
|
@ -898,6 +919,7 @@
|
||||||
(let [state (dissoc state :files)]
|
(let [state (dissoc state :files)]
|
||||||
(assoc state :workspace-shared-files files)))))
|
(assoc state :workspace-shared-files files)))))
|
||||||
|
|
||||||
|
|
||||||
(defn fetch-shared-files
|
(defn fetch-shared-files
|
||||||
[{:keys [team-id] :as params}]
|
[{:keys [team-id] :as params}]
|
||||||
(us/assert ::us/uuid team-id)
|
(us/assert ::us/uuid team-id)
|
||||||
|
|
Loading…
Add table
Reference in a new issue