From a3afd4cd76b9ede6fecf1e4be282686fafa18492 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 3 Nov 2026 16:53:04 +0100 Subject: [PATCH] :bug: Bring a swapped component's size to a copy child with its own constraint A copy child whose copy sets a constraint that ties one of its dimensions to its parent keeps the geometry it shows at sync, since the constraint applies to later resizes. That rule also held when the main swapped the child for another component, so the child kept the old component's 100x100 while the other copies showed the new 120x140, and update mains then pushed the old size into the main. The child keeps its geometry only while it shows its main's component; a swap reaching it brings the new component's size. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | world | baseline | now | ratio | |------------------------------------+----------+---------+-------| | deepest-edit-through-three-levels | 35.215 | 20.406 | 0.58 | | edit-through-a-chain-of-dependents | 68.931 | 38.828 | 0.56 | | library-update-into-copies | 83.083 | 50.763 | 0.61 | | main-edit-among-many-shapes | 4.837 | 2.508 | 0.52 | | main-edit-into-10-copies | 1.79 | 1.013 | 0.57 | | main-edit-into-100-copies | 15.415 | 9.418 | 0.61 | | main-edit-into-1000-copies | 153.086 | 91.613 | 0.60 | | variant-switch-into-copies | 32.052 | 21.561 | 0.67 | AI-assisted-by: claude-opus-5-5 --- common/src/app/common/logic/libraries.cljc | 8 +++++--- common/test/common_tests/logic/composable_gen_test.cljc | 8 ++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index 571483f47c..f356856d98 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -647,9 +647,11 @@ "Whether the copy shape `shape-inst` keeps the geometry it shows at sync: its copy authors a constraint that ties one of its dimensions to its copy parent. A constraint applies to the resizes after it, so sync does not - resize the shape through it again." - [container shape-inst] + resize the shape through it again. A swap reaching the shape from its + main (`shape-main` shows another component) brings the new size." + [container shape-inst shape-main] (and (ctk/touched-group? shape-inst :constraints-group) + (= (:component-id shape-inst) (:component-id shape-main)) (or (contains? #{:scale :leftright} (:constraints-h shape-inst)) (contains? #{:scale :topbottom} (:constraints-v shape-inst))) (some? (:shape-ref (ctn/get-shape container (:parent-id shape-inst)))))) @@ -682,7 +684,7 @@ (ctk/touched-group? shape-inst :layout-grid-cells)) placed (cond (and (not reset?) (or (ctk/touched-group? shape-inst :geometry-group) - (constraint-kept? container shape-inst))) + (constraint-kept? container shape-inst shape-main))) (in-main-frame shape-inst (:root-inst ctx) (:root-main ctx)) (and (not reset?) (= (:id shape-inst) (:id (:root-inst ctx)))) diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 92d4c82776..e63dbb35c8 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -1048,3 +1048,11 @@ (t/is (map? (cg/run {:world [2 0 {:text true :text-styles true}] :ops [[:resize 2 0 0 0] [:detach 3 0 0 0] [:detach 11 0 0 0] [:rotate 10 0 0 0] [:update-main 0 0 0 0] [:transform 0 0 0 12] [:update-main 7 0 0 0]]})))) + +(t/deftest generated-swap-brings-its-size-to-a-copy-child-with-its-own-constraint + ;; a copy child with its own scale constraint takes the size of the + ;; component its main swaps it for, as the other copies do + (t/is (map? (cg/run {:world [2 1 {:variants true :text-styles true :library true + :rich-variants true :layout-copies true :text true}] + :ops [[:style 24 8 1] [:swap 2 0 0 0] [:edit 3 0 1 1] [:update-main 3] + [:update-main 0 0 0 0]]}))))