diff --git a/common/src/app/common/types/file.cljc b/common/src/app/common/types/file.cljc index 5281e78d9..caad391b8 100644 --- a/common/src/app/common/types/file.cljc +++ b/common/src/app/common/types/file.cljc @@ -185,29 +185,24 @@ (d/seek #(= (:shape-ref %) (:id main-shape))))) (defn find-ref-shape - "Locate the near component in the local file or libraries, and retrieve the shape + "Locate the nearest component in the local file or libraries, and retrieve the shape referenced by the instance shape." [file page libraries shape & {:keys [include-deleted?] :or {include-deleted? false}}] - (let [root-shape (ctn/get-component-shape (:objects page) shape) - component-file (when root-shape - (if (and (some? file) (= (:component-file root-shape) (:id file))) - file - (get libraries (:component-file root-shape)))) - component (when component-file - (ctkl/get-component (:data component-file) (:component-id root-shape) include-deleted?)) - ref-shape (when component - (get-ref-shape (:data component-file) component shape))] + (let [parent-heads (->> (cfh/get-parents-with-self (:objects page) (:id shape)) + (filter ctk/instance-head?) + (reverse)) - (if (some? ref-shape) ; There is a case when we have a nested orphan copy. In this case there is no near - ref-shape ; component for this copy, so shape-ref points to the remote main. - (let [head-shape (ctn/get-head-shape (:objects page) shape) - head-file (if (and (some? file) (= (:component-file head-shape) (:id file))) - file - (get libraries (:component-file head-shape))) - head-component (when (some? head-file) - (ctkl/get-component (:data head-file) (:component-id head-shape) include-deleted?))] - (when (some? head-component) - (get-ref-shape (:data head-file) head-component shape)))))) + find-ref-shape-in-head + (fn [head-shape] + (let [head-file (if (and (some? file) (= (:component-file head-shape) (:id file))) + file + (get libraries (:component-file head-shape))) + head-component (when (some? head-file) + (ctkl/get-component (:data head-file) (:component-id head-shape) include-deleted?))] + (when (some? head-component) + (get-ref-shape (:data head-file) head-component shape))))] + + (d/seek find-ref-shape-in-head parent-heads))) (defn find-remote-shape "Recursively go back by the :shape-ref of the shape until find the correct shape of the original component" diff --git a/frontend/src/app/main/data/workspace/libraries_helpers.cljs b/frontend/src/app/main/data/workspace/libraries_helpers.cljs index ae5c52f66..ec6d8bf91 100644 --- a/frontend/src/app/main/data/workspace/libraries_helpers.cljs +++ b/frontend/src/app/main/data/workspace/libraries_helpers.cljs @@ -674,7 +674,6 @@ (let [omit-touched? (not reset?) clear-remote-synced? (and initial-root? reset?) set-remote-synced? (and (not initial-root?) reset?) - changes (cond-> changes :always (update-attrs shape-inst