From 0859d7c1a150480c13fbc865eb2733acc366bdf6 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Fri, 23 Oct 2026 19:12:08 +0200 Subject: [PATCH] :bug: 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 --- common/src/app/common/files/shapes_helpers.cljc | 3 ++- .../test/common_tests/logic/composable_runner_test.cljc | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/common/src/app/common/files/shapes_helpers.cljc b/common/src/app/common/files/shapes_helpers.cljc index 4540501938..fa80bb84e4 100644 --- a/common/src/app/common/files/shapes_helpers.cljc +++ b/common/src/app/common/files/shapes_helpers.cljc @@ -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])) diff --git a/common/test/common_tests/logic/composable_runner_test.cljc b/common/test/common_tests/logic/composable_runner_test.cljc index e654a9d6e1..69772f8c01 100644 --- a/common/test/common_tests/logic/composable_runner_test.cljc +++ b/common/test/common_tests/logic/composable_runner_test.cljc @@ -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))))))))