From f901d6974d26be42be69cada34763207bd890239 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Thu, 12 Nov 2026 11:05:04 +0100 Subject: [PATCH] :bug: Keep on the copy the layout child overrides a pushed swap holds Under a main parent with no layout, an update main leaves on the copy the layout child attributes it authored, as no layout parent uses them. An update main that pushes a swap adds the copy's subtree to the main instead, with every override it holds, so a maximum width a copy shape authored under the swapped board moved to the main. Pushing a swap now keeps those overrides on the copy shapes and off the new main shapes, as pushing a pair does. Test: updating-a-main-keeps-the-max-width-override-a-switched-copy-holds (the variant gate program of seed 175377838). Benchmark (scripts/bench-components, ms, lower 2.5% quantile), measured with the previous commit's change in the tree as well: | :world | :baseline | :now | :mean | :ratio | |------------------------------------+-----------+---------+---------+--------| | deepest-edit-through-three-levels | 35.215 | 21.071 | 22.737 | 0.6 | | edit-through-a-chain-of-dependents | 68.931 | 44.394 | 45.61 | 0.64 | | library-update-into-copies | 83.083 | 53.752 | 54.632 | 0.65 | | main-edit-among-many-shapes | 4.837 | 2.372 | 2.633 | 0.49 | | main-edit-into-10-copies | 1.79 | 0.997 | 1.029 | 0.56 | | main-edit-into-100-copies | 15.415 | 10.009 | 11.143 | 0.65 | | main-edit-into-1000-copies | 153.086 | 109.767 | 112.342 | 0.72 | | variant-switch-into-copies | 32.052 | 22.182 | 23.614 | 0.69 | AI-assisted-by: claude-opus-5-5 --- common/src/app/common/logic/libraries.cljc | 18 ++++++++++++++++-- .../logic/composable_gen_test.cljc | 9 +++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index 76bf10af2a..c5212ea541 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -1373,18 +1373,32 @@ (assoc :id (:id parent-main) :shape-ref (:shape-ref parent-main))))) + ;; the layout child groups the copy authored under a parent with no + ;; layout, which stay with the copy as an update of a pair keeps them + kept-items (fn [shape] + (let [layout? (if (= (:id shape) (:id child-inst)) + (ctsl/any-layout? parent-main) + (ctsl/any-layout? (:objects container) (:parent-id shape)))] + (when-not (or layout? (= (:id shape) (:id root-inst))) + (set/intersection (set (:touched shape)) + (into #{} (map #(ctk/resolve-sync-group (:type shape) %)) + layout-child-attrs))))) + update-new-shape (fn [new-shape original-shape] (cond-> (in-main new-shape) (and (= (:id original-shape) (:id child-inst)) (ctk/swapped? child-inst) (not swap-in-copy?)) - (rehead-pushed-swap content-main placement-container))) + (rehead-pushed-swap content-main placement-container) + + (seq (kept-items original-shape)) + (update :touched #(not-empty (set/difference % (kept-items original-shape)))))) ;; the copy now follows the main, swap included update-original-shape (fn [original-shape new-shape] (-> original-shape (assoc :shape-ref (:id new-shape)) - (dissoc :touched))) + (assoc :touched (not-empty (kept-items original-shape))))) [new-head new-shapes updated-shapes] (ctst/clone-shape child-inst diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index cb885f591a..c0f87fb10d 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -2393,6 +2393,15 @@ :grid-empty false :layout-copies true :text false}] :ops [[:style 8 35 1] [:style 0 29 1] [:update-main]]})))) +(t/deftest updating-a-main-keeps-the-max-width-override-a-switched-copy-holds + (t/is (map? (cg/run {:world [3 2 {:variants true :text-styles false :layout :grid :variant-diff false + :layout-item-margins false :grid-square false :rich-variants true + :layout-children false :grid-empty false :layout-copies true :text true}] + :ops [[:nest 1 0 0 6] [:text 2] [:combine 3 0 0 16] [:style 14 32] [:delete] [:restore] + [:add-variant 20 0] [:add-variant 20] [:update-main 3 0 0] [:grid-cell 11 6] + [:add-variant 0 0 0 16] [:variant-property 0 19 12] [:switch 20] [:edit 6 0 0 1] + [:update-main 6]]})))) + (t/deftest updating-a-main-pushes-a-swapped-shape-nested-in-a-swap-with-its-children (t/is (map? (cg/run {:world [3 3 {:variants true :text-styles true :scale true :layout :flex :variant-diff true :grid-square false :copies 5 :rich-variants true :layout-children true