From d3aea752d6ffcf6930ad01c2073a8619881c1b5b Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Fri, 13 Nov 2026 20:04:33 +0100 Subject: [PATCH] :bug: Give a grid copy its main's tracks when syncing its main's cells Sync adds the copies of a main's new children before it removes those of the children the main lost. Grouping two children of a full grid main gave each grid copy one flow child more than its cells for a moment, so it grew a column; the removals left that column empty and the next sync dropped it. A copy that does not override its cells now takes its main's tracks on each axis it does not override (all of them on a reset) before it takes its main's cells. Benchmark (lower quantile, ms): | world | baseline | now | mean | ratio | |------------------------------------+----------+---------+---------+-------| | deepest-edit-through-three-levels | 35.215 | 20.772 | 21.537 | 0.59 | | edit-through-a-chain-of-dependents | 68.931 | 41.197 | 42.556 | 0.60 | | library-update-into-copies | 83.083 | 49.581 | 51.122 | 0.60 | | main-edit-among-many-shapes | 4.837 | 2.181 | 2.405 | 0.45 | | main-edit-into-10-copies | 1.79 | 1.108 | 1.158 | 0.62 | | main-edit-into-100-copies | 15.415 | 10.273 | 10.948 | 0.67 | | main-edit-into-1000-copies | 153.086 | 100.399 | 109.973 | 0.66 | | variant-switch-into-copies | 32.052 | 21.866 | 22.788 | 0.68 | AI-assisted-by: claude-opus-5-5 --- common/src/app/common/logic/libraries.cljc | 9 ++++++++- common/test/common_tests/logic/composable_gen_test.cljc | 7 +++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index b93304a7cf..5b18e448c1 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -2513,7 +2513,14 @@ (add-inherited-grid-cells shape-before) (assign-inherited-grid-cells shape-before objects shape-main)) ;; Take cells from main and remap the shapes to assign it to the copy - (copy-grid-cells shape-copy shape-main objects)))) + (-> shape-copy + ;; the tracks it does not override are its main's, which the + ;; children sync adds before removing others may have grown + (cond-> (or (not omit-touched?) (not (ctk/touched-group? shape-copy :layout-grid-rows))) + (assoc :layout-grid-rows (:layout-grid-rows shape-main))) + (cond-> (or (not omit-touched?) (not (ctk/touched-group? shape-copy :layout-grid-columns))) + (assoc :layout-grid-columns (:layout-grid-columns shape-main))) + (copy-grid-cells shape-main objects))))) {:ignore-touched true :with-objects? true}))) (defn- update-grid-main-attrs diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index fa588b6f3a..35e8215cc7 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -4253,3 +4253,10 @@ (t/is (map? (cg/run {:world [3 1 {:text true :text-styles false :layout :grid :layout-children true :layout-item-margins false :grid-square false :grid-empty false}] :ops [[:delete 8] [:style 0 29 1] [:style 4 1 3]]})))) + +(t/deftest generated-grouping-in-a-full-grid-main-leaves-its-copies-tracks + ;; sync adds the group's copy before it removes the shapes the group + ;; took, which grows the copy's columns; the copy ends with its main's + (t/is (map? (cg/run {:world [1 0 {:variants true :rich-variants true :text true :layout :grid + :layout-copies false :layout-children true}] + :ops [[:add-child] [:style 0 35 1] [:add-child] [:add-child 8] [:structure 12 0 3]]}))))