From 24e389b763bd40e88ac95c9c695e7adc62e25b90 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 10 Nov 2026 10:28:04 +0100 Subject: [PATCH] :bug: Give a synced grid parent cells for the children a sync left A sync places a resized copy's subtree under the synced parent with its old placement. When the sync has just given that parent the grid of a new main, as after a swap, its children are still the old ones and the grid has no cells for them, so the layout of the placement failed on an in-flow child without a cell. The parent used for that placement now assigns cells to the children the sync left. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | :world | :baseline | :now | :mean | :ratio | |------------------------------------+-----------+---------+---------+--------| | deepest-edit-through-three-levels | 35.215 | 20.154 | 21.936 | 0.57 | | edit-through-a-chain-of-dependents | 68.931 | 39.517 | 41.605 | 0.57 | | library-update-into-copies | 83.083 | 49.772 | 51.257 | 0.6 | | main-edit-among-many-shapes | 4.837 | 2.167 | 2.466 | 0.45 | | main-edit-into-10-copies | 1.79 | 1.008 | 1.062 | 0.56 | | main-edit-into-100-copies | 15.415 | 10.197 | 11.064 | 0.66 | | main-edit-into-1000-copies | 153.086 | 102.045 | 108.458 | 0.67 | | variant-switch-into-copies | 32.052 | 21.435 | 22.715 | 0.67 | AI-assisted-by: claude-opus-5-5 --- common/src/app/common/logic/libraries.cljc | 10 ++++++---- .../test/common_tests/logic/composable_gen_test.cljc | 6 ++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index 6068ddb0db..6369264faf 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -660,11 +660,13 @@ (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)) - ;; the subtree as the sync left it, under the parent placed as before the sync + ;; the subtree as the sync left it, under the parent placed as + ;; before the sync, its grid holding the children the sync left placed (when resized? - (placed-like (assoc (pcb/get-objects changes) (:id before) - (merge after (select-keys before placement-geometry-attrs))) - before after {}))] + (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 {})))] (pcb/update-shapes changes ids (if resized? #(get placed (:id %) %) diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 74f7892634..1f9989c81b 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -2052,6 +2052,12 @@ [:make-variant 0] [:switch 0] [:make-variant 8 0 0 0] [:make-variant 0] [:switch 2] [:transform 10 4 0 0] [:make-variant 0] [:switch 17]]})))) +(t/deftest swapping-a-resized-board-for-a-grid-component-places-its-old-children-in-cells + (t/is (map? (cg/run {:world [1 0 {: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 [[:combine 2] [:switch] [:swap 3]]})))) + (t/deftest turning-a-flipped-copy-turns-a-child-stored-as-the-other-mirror-turn (t/is (map? (cg/run {:world [2 2 {:variants true :text-styles true :layout nil :variant-diff false :layout-item-margins false :grid-square false :rich-variants true