From 230dc0b4c2e623178eb6355093ad4110a025a8d3 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Wed, 11 Nov 2026 16:12:27 +0100 Subject: [PATCH] :bug: Author the size a sync resize gives a swapped head When sync resizes a copy parent, sync-descendant-orientation places its subtree through constraints, which scales an untouched swapped head with a scale constraint. Update-swapped-placement then only moves the head, so a later sync of every component gave it back the size of its own main: the result depended on the order of the syncs. Sync cannot tell a main change from a reset of a copy sized apart from its main, which must scale the head back (#12716), as it never sees the main's earlier size. The resize now marks the geometry group of an untouched swapped head it gives another size, so later syncs keep that size. The composable model records the same: a swapped head without authored geometry whose copy parent and own size both change in a step authors its new geometry in that parent. Test: syncing-a-resized-copy-parent-authors-the-size-it-gives-a-swapped- head (the variant gate program of round 16, seed 212451915). Common suite: 2441 tests, 0 failures. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | :world | :baseline | :now | :mean | :ratio | |------------------------------------+-----------+---------+---------+--------| | deepest-edit-through-three-levels | 35.215 | 21.568 | 22.51 | 0.61 | | edit-through-a-chain-of-dependents | 68.931 | 42.762 | 46.833 | 0.62 | | library-update-into-copies | 83.083 | 52.439 | 55.324 | 0.63 | | main-edit-among-many-shapes | 4.837 | 2.443 | 2.762 | 0.51 | | main-edit-into-10-copies | 1.79 | 1.124 | 1.217 | 0.63 | | main-edit-into-100-copies | 15.415 | 10.254 | 11.046 | 0.67 | | main-edit-into-1000-copies | 153.086 | 103.629 | 107.266 | 0.68 | | variant-switch-into-copies | 32.052 | 22.861 | 23.944 | 0.71 | AI-assisted-by: claude-opus-5-5 --- common/src/app/common/logic/libraries.cljc | 20 ++++++++++++++++--- .../logic/composable_gen_test.cljc | 7 +++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index f35f051b44..5f4db5890c 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -657,7 +657,8 @@ "A parent turned or moved by sync carries its whole subtree, including geometry overrides. Resize remains the job of constraints, not matrix scale: a parent turned and resized at once resizes its subtree through - their constraints first, then turns and moves it as one piece." + their constraints first, then turns and moves it as one piece. A swapped + head the resize gives another size authors that size." [changes container before] (let [after (get (pcb/get-objects changes) (:id before)) resized? (and after @@ -684,10 +685,23 @@ (let [objects (pcb/get-objects changes) parent (cond-> (merge after (select-keys before placement-geometry-attrs)) (ctsl/grid-layout? after) (ctsl/assign-cells objects))] - (placed-like (assoc objects (:id before) parent) before after {})))] + (placed-like (assoc objects (:id before) parent) before after {}))) + ;; untouched swapped heads the resize gives another size + scaled (when resized? + (into #{} + (filter #(let [shape (get (:objects container) %) + moved (get placed %)] + (and (ctk/swapped? shape) + (not (ctk/touched-group? shape :geometry-group)) + (some? moved) + (not (and (mth/close? (:width shape) (:width moved)) + (mth/close? (:height shape) (:height moved))))))) + ids))] (pcb/update-shapes changes ids (if resized? - #(get placed (:id %) %) + #(cond-> (get placed (:id %) %) + (contains? scaled (:id %)) + (update :touched ctk/set-touched-group :geometry-group)) #(cond-> % (some? turn) turn :always (gsh/move delta))) {:ignore-touched true})) changes))) diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 03b336725a..9245da8789 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -2282,6 +2282,13 @@ [:transform 3 9 7 13] [:switch] [:undo] [:update-main 1] [:duplicate 2] [:update-main 15] [:switch]]})))) +(t/deftest syncing-a-resized-copy-parent-authors-the-size-it-gives-a-swapped-head + (t/is (map? (cg/run {:world [2 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 false :text false}] + :ops [[:add-variant 15] [:duplicate 10] [:make-variant 8] [:switch 15] [:style 21 9 1] + [:update-main] [:duplicate 16] [:resize 16]]})))) + (t/deftest pushing-a-grid-direction-orders-the-copies-like-the-reflowed-main (t/is (map? (cg/run {:world [3 2 {:variants true :text-styles false :layout :grid :variant-diff false :layout-item-margins false :grid-square true :rich-variants false