From f140ec454136233cc1153fd581cc4cd75eee542a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Fri, 6 Oct 2023 17:27:58 +0200 Subject: [PATCH] :bug: Fix incorrect main instance creation on migration to v2 --- common/src/app/common/types/container.cljc | 28 +++++++++++----------- common/src/app/common/types/file.cljc | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/common/src/app/common/types/container.cljc b/common/src/app/common/types/container.cljc index 35ff81f06..8167a1d11 100644 --- a/common/src/app/common/types/container.cljc +++ b/common/src/app/common/types/container.cljc @@ -271,9 +271,10 @@ update-new-shape (fn [new-shape original-shape] (let [new-name (:name new-shape) - main-instance? (and main-instance? (ctk/instance-root? new-shape))] ; Only the instance root can be a main instance + root? (or (ctk/instance-root? original-shape) ; If shape is inside a component (not components-v2) + (nil? (:parent-id original-shape)))] ; we detect it by having no parent) - (when (nil? (:parent-id original-shape)) + (when root? (vswap! unames conj new-name)) (vswap! ids-map assoc (:id original-shape) (:id new-shape)) @@ -283,12 +284,15 @@ (-> (gsh/move delta) (dissoc :touched)) - main-instance? + (and main-instance? root?) (assoc :main-instance true) (not main-instance?) (dissoc :main-instance) + main-instance? + (dissoc :shape-ref) + (and (not main-instance?) (or components-v2 ; In v1, shape-ref points to the remote instance (nil? (:shape-ref original-shape)))) ; in v2, shape-ref points to the near instance @@ -300,21 +304,17 @@ :component-root true :name new-name) - (and (nil? (:parent-id original-shape)) main-instance? components-v2) - (assoc :main-instance true) - (some? (:parent-id original-shape)) (dissoc :component-root)))) [new-shape new-shapes _] - (ctst/clone-object - component-shape - nil - (if components-v2 (:objects component-page) (:objects component)) - update-new-shape - (fn [object _] object) - force-id - keep-ids?) + (ctst/clone-object component-shape + nil + (if components-v2 (:objects component-page) (:objects component)) + update-new-shape + (fn [object _] object) + force-id + keep-ids?) ;; If frame-id points to a shape inside the component, remap it to the ;; corresponding new frame shape. If not, set it to the destination frame. diff --git a/common/src/app/common/types/file.cljc b/common/src/app/common/types/file.cljc index 474067d68..bea5cd024 100644 --- a/common/src/app/common/types/file.cljc +++ b/common/src/app/common/types/file.cljc @@ -394,7 +394,7 @@ file-data position false - {:main-instance true + {:main-instance? true :force-frame-id uuid/zero :keep-ids? true}) add-shapes