From 3105afa9ae8294d66ffe1a12a6d236b3c195b294 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Wed, 11 Nov 2026 05:04:44 +0100 Subject: [PATCH] :bug: Sync the copies of a main whose children a reorder moves A copy turned its grid from rows to columns and update main pushed the direction; the layout reflow then reordered the main's children for the new flow with a reorder-children change. components-changed did not count that change, so the copies were never synced and kept the old order. A reorder that changes a parent's order now marks the components whose main holds that parent; one that keeps the order still marks none, since the reflow writes those on every pass. Tests: reordering-the-children-of-a-main-changes-its-component and pushing-a-grid-direction-orders-the-copies-like-the-reflowed-main (the variant gate program of round 12, seed 252148030). Common suite: 2429 tests, 0 failures. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | :world | :baseline | :now | :mean | :ratio | |------------------------------------+-----------+--------+---------+--------| | deepest-edit-through-three-levels | 35.215 | 19.581 | 20.465 | 0.56 | | edit-through-a-chain-of-dependents | 68.931 | 44.23 | 45.224 | 0.64 | | library-update-into-copies | 83.083 | 55.313 | 56.272 | 0.67 | | main-edit-among-many-shapes | 4.837 | 2.379 | 2.555 | 0.49 | | main-edit-into-10-copies | 1.79 | 0.984 | 1.026 | 0.55 | | main-edit-into-100-copies | 15.415 | 9.856 | 10.1 | 0.64 | | main-edit-into-1000-copies | 153.086 | 97.071 | 101.457 | 0.63 | | variant-switch-into-copies | 32.052 | 22.287 | 22.916 | 0.7 | AI-assisted-by: claude-opus-5-5 --- common/src/app/common/files/changes.cljc | 13 +++++++++++++ common/test/common_tests/logic/comp_sync_test.cljc | 13 +++++++++++++ .../common_tests/logic/composable_gen_test.cljc | 7 +++++++ 3 files changed, 33 insertions(+) diff --git a/common/src/app/common/files/changes.cljc b/common/src/app/common/files/changes.cljc index 8467b6974b..bf29c06e31 100644 --- a/common/src/app/common/files/changes.cljc +++ b/common/src/app/common/files/changes.cljc @@ -1289,6 +1289,19 @@ (into #{} xform shape-and-parents)) (when component-id #{component-id}))) +(defmethod components-changed :reorder-children + [file-data {:keys [parent-id page-id component-id shapes]}] + (if page-id + (let [page (ctpl/get-page file-data page-id) + parents (map (partial ctn/get-shape page) + (cons parent-id (cfh/get-parent-ids (:objects page) parent-id))) + xform (comp (filter :main-instance) + (map :component-id))] + ;; a reorder that keeps the order changes nothing + (when (not= (vec shapes) (vec (:shapes (ctn/get-shape page parent-id)))) + (into #{} xform parents))) + (when component-id #{component-id}))) + (defmethod components-changed :restore-component [_ {:keys [id]}] #{id}) diff --git a/common/test/common_tests/logic/comp_sync_test.cljc b/common/test/common_tests/logic/comp_sync_test.cljc index 98b8b06f26..f46d5584b4 100644 --- a/common/test/common_tests/logic/comp_sync_test.cljc +++ b/common/test/common_tests/logic/comp_sync_test.cljc @@ -1166,6 +1166,19 @@ (ch/components-changed (:data file) (change {:type :assign :value {:opacity 0.5}})))) (t/is (nil? (ch/components-changed (:data file) (change {:type :assign :value {:interactions []}})))))) +(t/deftest reordering-the-children-of-a-main-changes-its-component + (let [file (-> (thf/sample-file :file1) + (tho/add-component-with-many-children-and-copy :component1 :main-root + [:main-child1 :main-child2] :copy-root)) + page (thf/current-page file) + root (ths/get-shape file :main-root) + change (fn [shapes] + {:type :reorder-children :parent-id (:id root) :page-id (:id page) :shapes shapes})] + (t/is (= #{(thi/id :component1)} + (ch/components-changed (:data file) (change (vec (reverse (:shapes root))))))) + (t/testing "a reorder that keeps the order changes nothing" + (t/is (empty? (ch/components-changed (:data file) (change (:shapes root)))))))) + (t/deftest a-copy-grid-with-its-own-cells-orders-its-children-by-their-flow (let [page-id (thi/new-id! :page) grid {:id (thi/new-id! :grid) :type :frame :layout :grid :layout-grid-dir :row diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 5bf8d32722..4180ea2b12 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -2182,6 +2182,13 @@ (t/is (seq turned)) (t/is (every? geom/decomposes? turned)))) +(t/deftest pushing-a-grid-direction-orders-the-copies-like-the-reflowed-main + (t/is (map? (cg/run {:world [3 2 {:variants true :text-styles false :layout :grid :variant-diff false + :layout-item-margins false :grid-square true :rich-variants false + :layout-children true :grid-empty false :layout-copies false :text true}] + :ops [[:make-variant] [:make-variant 6] [:combine] [:make-variant 11] [:combine] + [:remove-child 9] [:grid-direction 0 0 13] [:update-main]]})))) + (t/deftest moving-a-flex-copy-child-after-a-switch-resized-its-sibling-authors-no-geometry (t/is (map? (cg/run {:world [1 2 {:variants true :text-styles false :layout :flex :variant-diff false :layout-item-margins false :grid-square false :rich-variants true