🐛 Order grid children when adding a shape

Record grid children in cell order before asynchronous reflow. This
keeps changes and their undo independent of the reflow schedule.

Red child-order regression reproduced. Focused geometry, reset, swap
and runner suites pass 121 tests / 540 assertions.

Benchmark vs Phase 1e: main 10/100/1000 0.51/0.64/0.65; levels 0.50;
chain 0.57; library 0.53; many shapes 0.47; switch 0.59. No flags.

AI-assisted-by: GPT-6
This commit is contained in:
alonso.torres 2026-10-23 19:12:08 +02:00
parent 40ff7a743c
commit 0859d7c1a1
2 changed files with 11 additions and 1 deletions

View File

@ -36,7 +36,8 @@
(cond-> (some? cell)
(pcb/update-shapes [(:parent-id shape)] #(ctl/push-into-cell % [id] row column)))
(cond-> (ctl/grid-layout? objects (:parent-id shape))
(pcb/update-shapes [(:parent-id shape)] ctl/assign-cells {:with-objects? true})))]
(-> (pcb/update-shapes [(:parent-id shape)] ctl/assign-cells {:with-objects? true})
(pcb/reorder-grid-children [(:parent-id shape)]))))]
[shape changes]))

View File

@ -16,6 +16,7 @@
[app.common.test-helpers.files :as thf]
[app.common.test-helpers.ids-map :as thi]
[app.common.test-helpers.normalize :as thn]
[app.common.types.shape.layout :as ctl]
[app.common.uuid :as uuid]
[clojure.test :as t]))
@ -617,3 +618,11 @@
(catch #?(:clj Exception :cljs js/Error) error error))]
(t/is (= ::tm/unbound-shape-name (:type (ex-data error))))
(t/is (some #{:copy-child} (:present (ex-data error))))))
(t/deftest adding-a-grid-child-records-cell-order-before-reflow
(let [initial (setup/grid-component-with-copy)
changed (-> initial (r/step (n/add-child :grid-root :new-grid-child)) r/settle)
grid (tm/resolve-shape changed :grid-root)]
(t/is (= (:shapes (ctl/reorder-grid-children grid)) (:shapes grid)))
(t/is (= (thn/normalize-file (tm/file initial))
(thn/normalize-file (tm/file (r/step changed (n/undo))))))))