From 2588315b9a7adc17f20e938607e34a617c18d676 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Thu, 12 Nov 2026 11:16:53 +0100 Subject: [PATCH] :bug: Keep the pushed size of a swap head whose copy authors its geometry An update main that pushes a copy's swap into a copy inside the main makes the head a plain copy of its position when both have the same component, and gives it the position's size unless the replaced child authored its geometry. A head whose copy authored its own geometry took that touched group into the main but the position's size, so the main kept a geometry override it did not hold. Such a head now keeps the size it pushes. Test: updating-a-main-after-a-reset-keeps-the-size-a-switch-gave-the-copy (the scale gate program of seed 175377838). Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | :world | :baseline | :now | :mean | :ratio | |------------------------------------+-----------+--------+---------+--------| | deepest-edit-through-three-levels | 35.215 | 20.374 | 21.102 | 0.58 | | edit-through-a-chain-of-dependents | 68.931 | 40.71 | 44.564 | 0.59 | | library-update-into-copies | 83.083 | 48.986 | 51.548 | 0.59 | | main-edit-among-many-shapes | 4.837 | 2.255 | 2.557 | 0.47 | | main-edit-into-10-copies | 1.79 | 0.987 | 1.028 | 0.55 | | main-edit-into-100-copies | 15.415 | 10.394 | 10.601 | 0.67 | | main-edit-into-1000-copies | 153.086 | 99.622 | 102.888 | 0.65 | | variant-switch-into-copies | 32.052 | 21.928 | 23.985 | 0.68 | AI-assisted-by: claude-opus-5-5 --- common/src/app/common/logic/libraries.cljc | 5 +++-- common/test/common_tests/logic/composable_gen_test.cljc | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index c5212ea541..acafb8fb99 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -1424,11 +1424,12 @@ position-objects (get-in (meta position) [:container :objects]) ;; the head takes the place the replaced child authored placement (set/intersection (set (:touched replaced)) placement-groups) - ;; a plain copy of the position has its size, unless the replaced child authored its geometry + ;; a plain copy of the position has its size, unless the replaced child or the copy authored its geometry sized? (fn [shape] (and (= (:id shape) (:id new-head)) position (not (ctk/swapped? shape)) - (not (contains? placement :geometry-group)))) + (not (contains? placement :geometry-group)) + (not (ctk/touched-group? shape :geometry-group)))) positioned (mapv (fn [shape] (let [shape (take-position shape)] (cond-> shape (sized? shape) (sized-like position)))) diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index c0f87fb10d..0eaa626b26 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -2393,6 +2393,12 @@ :grid-empty false :layout-copies true :text false}] :ops [[:style 8 35 1] [:style 0 29 1] [:update-main]]})))) +(t/deftest updating-a-main-after-a-reset-keeps-the-size-a-switch-gave-the-copy + (t/is (map? (cg/run {:world [4 4 {:variants true :text-styles true :scale false :layout :flex :variant-diff false + :grid-square false :copies 6 :rich-variants true :layout-children false + :grid-empty false :layout-copies false :text false}] + :ops [[:resize] [:combine 1] [:add-variant] [:switch 5] [:switch] [:reset] [: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