🐛 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
This commit is contained in:
alonso.torres 2026-11-11 05:04:44 +01:00
parent 83156ea5f7
commit 3105afa9ae
3 changed files with 33 additions and 0 deletions

View File

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

View File

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

View File

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