From aa1797e29e3ce506e5a6d254d35681e878d5da9d Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Sun, 1 Nov 2026 04:25:04 +0100 Subject: [PATCH] :bug: Drop a copy's grid cells when sync leaves it without a grid Grid cell overrides carry over only between grids. When a main swapped a nested grid head for a component without a grid, its copies kept the cells they authored, now naming a child that was removed. Sync now drops the cells and their override from a copy it leaves without a grid, and the model expects the same once the copy has synced. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | world | baseline | now | ratio | |------------------------------------+----------+--------+-------| | deepest-edit-through-three-levels | 35.215 | 20.76 | 0.59 | | edit-through-a-chain-of-dependents | 68.931 | 37.86 | 0.55 | | library-update-into-copies | 83.083 | 46.402 | 0.56 | | main-edit-among-many-shapes | 4.837 | 2.19 | 0.45 | | main-edit-into-10-copies | 1.79 | 0.976 | 0.55 | | main-edit-into-100-copies | 15.415 | 9.456 | 0.61 | | main-edit-into-1000-copies | 153.086 | 95.647 | 0.62 | | variant-switch-into-copies | 32.052 | 20.652 | 0.64 | AI-assisted-by: claude-opus-5-5 --- common/src/app/common/logic/libraries.cljc | 9 ++++++++- .../test/common_tests/logic/composable_gen_test.cljc | 12 ++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index 68537a7c58..0b654fbb42 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -694,7 +694,14 @@ (reorder-copy-children shape-inst children-main container)) (ctsl/grid-layout? shape-inst) - (update-grid-copy-attrs shape-before shape-main (not reset?)))))) + (update-grid-copy-attrs shape-before shape-main (not reset?)) + + ;; cells only carry between grids, so a copy that sync leaves + ;; without one drops its own + (and (not (ctsl/grid-layout? shape-inst)) (seq (:layout-grid-cells shape-inst))) + (pcb/update-shapes [(:id shape-inst)] + #(-> % (dissoc :layout-grid-cells) (update :touched disj :layout-grid-cells)) + {:ignore-touched true}))))) (defn generate-rename-component "Generate the changes for rename the component with the given id, in the current file library." diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index a079bdf4f5..8bda203af6 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -889,3 +889,15 @@ :layout :grid :library-depth 1 :library true :rich-variants true :layout-children true :library-text true :layout-copies true :text true}] :ops [[:style 11 35 1] [:grid-direction 13 0 0 1] [:grid-cell 13 0 0 1] [:reset 14 0 0 0]]})))) + +(t/deftest generated-swap-to-a-board-without-grid-drops-a-copys-cell-override + ;; a copy authors the cells of a nested grid head; its main swaps the head + ;; for a component without grid, so the override has no grid to carry to + (let [result (cg/run {:world [2 0 {:variants true :text-styles true :layout :grid :grid-square true :library true + :rich-variants true :layout-copies true :text true}] + :ops [[:swap 5 0 0 0] [:grid-direction 1 0 0 1] [:grid-cell 1 0 0 1] [:swap 0 0 0 0]]}) + objects (into {} (mapcat cf/object-trees) (vals (cf/all-files (:situation result))))] + (doseq [shape (vals objects) + :when (not= :grid (:layout shape))] + (t/is (empty? (:layout-grid-cells shape)) (:name shape)) + (t/is (not (contains? (:touched shape) :layout-grid-cells)) (:name shape)))))