From d213bc96d4205844d2743a1e06b8dbee539938b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Thu, 25 Aug 2022 16:49:51 +0200 Subject: [PATCH] :bug: Fix some synchronization problems --- .../app/main/data/workspace/libraries.cljs | 4 ++-- .../data/workspace/libraries_helpers.cljs | 20 +++++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/frontend/src/app/main/data/workspace/libraries.cljs b/frontend/src/app/main/data/workspace/libraries.cljs index 78aaad5c9c..151273abe7 100644 --- a/frontend/src/app/main/data/workspace/libraries.cljs +++ b/frontend/src/app/main/data/workspace/libraries.cljs @@ -754,8 +754,8 @@ :library-id library-id}))) (when (and (seq (:redo-changes library-changes)) sync-components?) - (rx/of (sync-file-2nd-stage file-id library-id asset-id)))))))))) - + (rx/of (sync-file-2nd-stage file-id library-id nil)))))))))) ; In 2nd stage the original asset is not used + ; because other components may have changed (defn- sync-file-2nd-stage "If some components have been modified, we need to launch another synchronization to update the instances of the changed components." diff --git a/frontend/src/app/main/data/workspace/libraries_helpers.cljs b/frontend/src/app/main/data/workspace/libraries_helpers.cljs index 78c80455ab..a8bc5d3db5 100644 --- a/frontend/src/app/main/data/workspace/libraries_helpers.cljs +++ b/frontend/src/app/main/data/workspace/libraries_helpers.cljs @@ -242,7 +242,7 @@ (log/debug :msg "Sync component in local library" :component-id (:id container))) (let [linked-shapes (->> (vals (:objects container)) - (filter #(uses-assets? asset-type asset-id % library-id)))] + (filter #(uses-assets? asset-type asset-id % library-id (cph/component? container))))] (loop [shapes (seq linked-shapes) changes (-> (pcb/empty-changes it) (pcb/with-container container) @@ -260,22 +260,26 @@ (defmulti uses-assets? "Checks if a shape uses some asset of the given type in the given library." - (fn [asset-type _ _ _] asset-type)) + (fn [asset-type _ _ _ _] asset-type)) (defmethod uses-assets? :components - [_ component-id shape library-id] - (if (nil? component-id) - (ctk/uses-library-components? shape library-id) - (ctk/instance-of? shape library-id component-id))) + [_ component-id shape library-id component?] + (and (if (nil? component-id) + (ctk/uses-library-components? shape library-id) + (ctk/instance-of? shape library-id component-id)) + ;; Subinstances are synced with the near component, not the remote. + ;; So an instance that is not root, cannot be considered "using" + ;; the component. + (or (:component-root? shape) component?))) (defmethod uses-assets? :colors - [_ color-id shape library-id] + [_ color-id shape library-id _] (if (nil? color-id) (ctc/uses-library-colors? shape library-id) (ctc/uses-library-color? shape library-id color-id))) (defmethod uses-assets? :typographies - [_ typography-id shape library-id] + [_ typography-id shape library-id _] (if (nil? typography-id) (cty/uses-library-typographies? shape library-id) (cty/uses-library-typography? shape library-id typography-id)))