From 59e848ea14131c966b0e46028953176d1bb77e87 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Wed, 18 Nov 2026 00:23:34 +0100 Subject: [PATCH] :bug: Keep a copy grid's own empty cell where it was as it grows back A copy grid with its own cells that lost the row its main removed, and grew one back to hold its children, fitted its cells into the fewer tracks first. Its authored empty cell (`align-self :end` at row 2, column 2) was merged into an occupied one and lost (F594). User decision: the cell keeps its place. `assign-inherited-grid-cells` now grows the track lists its children need before fitting the cells (`grow-for-children`), so a grid that grows back the tracks it lost keeps its cells where they were. Only the track lists grow; the cells it holds keep their places. Found by a fresh gate round (seed 20261117, grid property). Test: generated `generated-a-copy-grid-keeps-an-authored-empty-cell-where-it-was-when-it-grows-back` (JVM and frontend replay). Benchmark (bench-components, alone): | :world | :baseline | :now | :mean | :ratio | |------------------------------------+-----------+---------+---------+--------| | deepest-edit-through-three-levels | 35.215 | 21.906 | 23.299 | 0.62 | | edit-through-a-chain-of-dependents | 68.931 | 46.008 | 46.834 | 0.67 | | library-update-into-copies | 83.083 | 53.933 | 55.436 | 0.65 | | main-edit-among-many-shapes | 4.837 | 2.497 | 2.639 | 0.52 | | main-edit-into-10-copies | 1.79 | 1.185 | 1.228 | 0.66 | | main-edit-into-100-copies | 15.415 | 11.262 | 11.561 | 0.73 | | main-edit-into-1000-copies | 153.086 | 108.966 | 112.568 | 0.71 | | variant-switch-into-copies | 32.052 | 23.931 | 24.195 | 0.75 | AI-assisted-by: claude-opus-5-5 --- common/src/app/common/logic/libraries.cljc | 19 +++++++++++++++++++ .../logic/composable_gen_test.cljc | 5 +++++ .../composable_tests/generated_test.cljs | 6 ++++++ 3 files changed, 30 insertions(+) diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index 3f74b75daa..475795f809 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -2474,6 +2474,22 @@ (ctsl/assign-cells objects) (assoc :shapes (:shapes shape))))) +(defn- grow-for-children + "`shape` with the default tracks its grid adds along its flow until each + child it lays out has a slot, as `ctsl/assign-cells` grows it. Only the + track lists grow: the cells the grid already holds keep their places." + [shape objects] + (let [children (count (remove #(ctsl/position-absolute? objects %) (:shapes shape))) + row-dir? (= :row (ctsl/grid-direction shape))] + (loop [shape shape] + (let [rows (count (:layout-grid-rows shape)) + cols (count (:layout-grid-columns shape))] + (if (or (zero? rows) (zero? cols) (>= (* rows cols) children)) + shape + (recur (if row-dir? + (update shape :layout-grid-columns (fnil conj []) ctsl/default-track-value) + (update shape :layout-grid-rows (fnil conj []) ctsl/default-track-value)))))))) + (defn- assign-inherited-grid-cells [shape before objects shape-main] (if-not (or (< (count (:layout-grid-rows shape)) (count (:layout-grid-rows before))) @@ -2489,6 +2505,9 @@ (and active? (empty? (:layout-grid-columns shape))) (assoc :layout-grid-columns [ctsl/default-track-value]))] (-> target + ;; the tracks the children need come first, so a grid that grows + ;; back the tracks it lost keeps its own cells where they were + (grow-for-children objects) (without-default-cells-beyond-tracks) (ctsl/check-deassigned-cells objects) (ctsl/fit-cells-to-tracks) diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 550935de91..60c975270f 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -4547,3 +4547,8 @@ ;; a few thousandths of a pixel from their new mains' places: no override (t/is (map? (cg/run {:world [3 2 {:variants true :layout :grid :rich-variants true :grid-empty true :layout-copies true :text true}] :ops [[:nest 7 2 4 2] [:rotate 6 2 4 1] [:duplicate 1 3 1 0] [:make-variant 2] [:duplicate 8 2 8 6] [:style 2 29 1] [:detach 8 6 8 2]]})))) +(t/deftest generated-a-copy-grid-keeps-an-authored-empty-cell-where-it-was-when-it-grows-back + ;; a copy grid with its own cells loses a row its main removes and grows it + ;; back for its children: its authored empty cell keeps its place (user + ;; decision) + (t/is (map? (cg/run {:world [2 1 {:variants true :layout :grid :layout-item-margins false :grid-square true :rich-variants true :layout-children true :grid-empty false :layout-copies true :text true}] :ops [[:grid-track 9 5 0 0] [:grid-direction 0 0 1 1] [:grid-cell 0 15 0 1] [:grid-track 0 2 0 0]]})))) diff --git a/frontend/test/frontend_tests/composable_tests/generated_test.cljs b/frontend/test/frontend_tests/composable_tests/generated_test.cljs index f19ccbf2cb..f7ddf2cfbc 100644 --- a/frontend/test/frontend_tests/composable_tests/generated_test.cljs +++ b/frontend/test/frontend_tests/composable_tests/generated_test.cljs @@ -1230,3 +1230,9 @@ ;; main holds, which takes it with its sizing fixed as its own override (await (replay {:world [3 2 {:text true :layout :flex}] :ops [[:nest 24 11 9 6] [:delete 1] [:restore 1] [:add-child 15 16 4 29] [:move 23 24 12 20] [:edit 25 25 27 25] [:undo 23 17 15 25] [:style 23 29 25 20] [:transform 29 11 7 27] [:update-main 2 19 2 29]]}))) +(t/deftest ^:async generated-a-copy-grid-keeps-an-authored-empty-cell-where-it-was-when-it-grows-back + ;; a copy grid with its own cells loses a row its main removes and grows it + ;; back for its children: its authored empty cell keeps its place (user + ;; decision) + (await (replay {:world [2 1 {:variants true :layout :grid :layout-item-margins false :grid-square true :rich-variants true :layout-children true :grid-empty false :layout-copies true :text true}] :ops [[:grid-track 9 5 0 0] [:grid-direction 0 0 1 1] [:grid-cell 0 15 0 1] [:grid-track 0 2 0 0]]}))) +