🐛 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
This commit is contained in:
alonso.torres 2026-11-01 04:25:04 +01:00
parent 9664a1ecc6
commit aa1797e29e
2 changed files with 20 additions and 1 deletions

View File

@ -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."

View File

@ -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)))))