From 312a3ce6f0b1e70dfcf04cb17a9437dbd7f6ef9e Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 10 Nov 2026 20:27:13 +0100 Subject: [PATCH] :bug: Move combined mains into the variant one at a time in combine order Combining same-name components as variants gives each one the first unused "Value N", in the order the mains enter the variant container. `generate-combine-as-variants` moved all the remaining mains in one relocation, which takes them in layer order, so the values followed the layers and not the combine order. It now moves them one at a time, in the order of the ids, as the frontend combine on develop does. Test: `test-combine-as-variants-same-name-values-follow-combine-order`. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | :world | :baseline | :now | :mean | :ratio | |------------------------------------+-----------+--------+--------+--------| | deepest-edit-through-three-levels | 35.215 | 20.749 | 21.213 | 0.59 | | edit-through-a-chain-of-dependents | 68.931 | 40.771 | 41.457 | 0.59 | | library-update-into-copies | 83.083 | 50.674 | 51.835 | 0.61 | | main-edit-among-many-shapes | 4.837 | 1.967 | 2.133 | 0.41 | | main-edit-into-10-copies | 1.79 | 1.039 | 1.059 | 0.58 | | main-edit-into-100-copies | 15.415 | 9.153 | 9.626 | 0.59 | | main-edit-into-1000-copies | 153.086 | 93.347 | 99.626 | 0.61 | | variant-switch-into-copies | 32.052 | 21.86 | 22.36 | 0.68 | AI-assisted-by: claude-opus-5-5 --- common/src/app/common/logic/variants.cljc | 4 +++- .../common_tests/logic/variants_test.cljc | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/common/src/app/common/logic/variants.cljc b/common/src/app/common/logic/variants.cljc index deffb5c805..22f75c87bd 100644 --- a/common/src/app/common/logic/variants.cljc +++ b/common/src/app/common/logic/variants.cljc @@ -223,7 +223,9 @@ (- (:y rect) (:y first-shape) 30)) :prefix prefix :wrapper? (empty? prefix)}) - (generate-move-into $ (set (rest ids)) variant-id 0) + ;; one move per main, in the order of `ids`, so the property values it + ;; generates follow that order + (reduce #(generate-move-into %1 #{%2} variant-id 0) $ (rest ids)) ;; the members in the order of `ids`: the board's children go the other ;; way, and a change of parent at index 0 reverses the shapes it takes (let [children (set (get-in (pcb/get-objects $) [variant-id :shapes])) diff --git a/common/test/common_tests/logic/variants_test.cljc b/common/test/common_tests/logic/variants_test.cljc index 1775b04c31..de9473b70f 100644 --- a/common/test/common_tests/logic/variants_test.cljc +++ b/common/test/common_tests/logic/variants_test.cljc @@ -453,6 +453,28 @@ (t/is (= "Value 3" (:variant-name (ths/get-shape file' :m03)))))) + +(t/deftest test-combine-as-variants-same-name-values-follow-combine-order + ;; The combine order differs from the layer order of the mains + (let [file (-> (thf/sample-file :file1) + (tho/add-simple-component :c01 :m01 :r01 + :root-params {:name "Tag" :x 0 :y 0 :width 100 :height 80}) + (tho/add-simple-component :c02 :m02 :r02 + :root-params {:name "Tag" :x 150 :y 0 :width 100 :height 80}) + (tho/add-simple-component :c03 :m03 :r03 + :root-params {:name "Tag" :x 300 :y 0 :width 100 :height 80})) + page (thf/current-page file) + changes (-> (pcb/empty-changes nil (:id page)) + (pcb/with-objects (:objects page)) + (pcb/with-library-data (:data file)) + (clv/generate-combine-as-variants [(thi/id :m03) (thi/id :m01) (thi/id :m02)] + (uuid/next))) + file' (thf/apply-changes file changes) + values (mapv #(-> (thc/get-component file' %) :variant-properties first :value) + [:c03 :c01 :c02])] + + (t/is (= ["Value 1" "Value 2" "Value 3"] values)))) + (t/deftest test-duplicate-variant-container (let [;; ==== Setup file (-> (thf/sample-file :file1)