From c095c6cce6ffc768d06cb86e6f14d98cda834ea0 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Thu, 5 Nov 2026 06:54:30 +0100 Subject: [PATCH] :bug: Keep the reset attributes of children a resized copy carries A sync that resizes a copy shape carries its subtree through the constraints of its children. It placed that subtree from the objects as they were before the sync, so it wrote back the attributes the sync had just given the children. A reset of a resized copy root left its child's overridden layout item margin type in place, while clearing its touched flag. The subtree is placed from the objects as the sync left them, under the parent as it was before the sync. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | world | baseline | now | ratio | |------------------------------------+----------+---------+-------| | deepest-edit-through-three-levels | 35.215 | 18.845 | 0.54 | | edit-through-a-chain-of-dependents | 68.931 | 37.053 | 0.54 | | library-update-into-copies | 83.083 | 46.11 | 0.55 | | main-edit-among-many-shapes | 4.837 | 2.087 | 0.43 | | main-edit-into-10-copies | 1.79 | 0.921 | 0.51 | | main-edit-into-100-copies | 15.415 | 8.99 | 0.58 | | main-edit-into-1000-copies | 153.086 | 91.573 | 0.60 | | variant-switch-into-copies | 32.052 | 18.962 | 0.59 | AI-assisted-by: claude-opus-5-5 --- common/src/app/common/logic/libraries.cljc | 4 ++- .../common_tests/logic/comp_reset_test.cljc | 31 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index 42a5279a55..3c04750eca 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -612,7 +612,9 @@ (assoc shape :transform matrix :transform-inverse (gmt/inverse matrix)))) turn (orient-like (orientation before) (orientation after) (gsh/shape->center before)) delta (gpt/subtract (gsh/shape->center after) (gsh/shape->center before)) - placed (when resized? (placed-like (:objects container) before after {}))] + ;; the subtree as the sync left it, under the parent before the sync + placed (when resized? + (placed-like (assoc (pcb/get-objects changes) (:id before) before) before after {}))] (pcb/update-shapes changes ids (if resized? #(get placed (:id %) %) diff --git a/common/test/common_tests/logic/comp_reset_test.cljc b/common/test/common_tests/logic/comp_reset_test.cljc index 1831be64b1..6975606485 100644 --- a/common/test/common_tests/logic/comp_reset_test.cljc +++ b/common/test/common_tests/logic/comp_reset_test.cljc @@ -681,3 +681,34 @@ :library true :library-text true :layout :flex :layout-children true :layout-copies true}] :ops [[:style 11 27 1] [:reset 14 0 0 0] [:undo] [:redo]]})))) + +(t/deftest reset-of-a-resized-copy-restores-its-childs-layout-item-values + ;; The copy root is taller than its flex main; its child overrides the margin type. + (let [file (-> (thf/sample-file :file1) + (tho/add-frame :main-root {:layout :flex :layout-flex-dir :row}) + (tho/add-rect :main-child :parent-label :main-root) + (thc/make-component :component1 :main-root) + (thc/instantiate-component :component1 :copy-root + :children-labels [:copy-child])) + edit (fn [file label update-fn] + (let [page (thf/current-page file)] + (thf/apply-changes file (cls/generate-update-shapes (pcb/empty-changes nil (:id page)) + #{(thi/id label)} + update-fn + (:objects page) + {})))) + file (-> file + (edit :copy-root #(gsh/transform-shape % (ctm/change-size % (:width %) 80))) + (edit :copy-child #(assoc % :layout-item-margin-type :multiple))) + page (thf/current-page file) + changes (cll/generate-reset-component (pcb/empty-changes) file {(:id file) file} + (ctn/make-container page :page) + (thi/id :copy-root)) + file' (thf/apply-changes file changes)] + (t/is (= :multiple (:layout-item-margin-type (ths/get-shape file :copy-child)))) + (t/is (nil? (:layout-item-margin-type (ths/get-shape file' :copy-child)))) + (t/is (nil? (:touched (ths/get-shape file' :copy-child)))) + (t/is (map? (cg/run {:world [3 0 {:text true :text-styles true :layout :flex :layout-children false + :layout-item-margins false :grid-square false :grid-empty false}] + :ops [[:delete 0 0 0 0] [:resize 8 0 0 0] [:style 16 27 1] + [:edit 0 1 1 :copy-head] [:reset 0]]})))))