From 7176c13cb87aa91d5c68d837339ee658ba8f601b Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 10 Nov 2026 08:23:46 +0100 Subject: [PATCH] :bug: Compare a switched child with its old main in the old copy's frame A switch carries a child's override only where the old and the new variant agree on the attribute. It compared them after turning the old main's shapes by the turn from the new main to the new copy. When the variants' mains are turned or flipped differently, the old main's child took that foreign turn: it could agree with the new copy child where the variants differ, carrying a flip or turn without its transform and marking an override, and could disagree where they share a value. The old main's shapes now turn by the turn from the old main to the old copy, the frame the new copy keeps. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | :world | :baseline | :now | :mean | :ratio | |------------------------------------+-----------+--------+--------+--------| | deepest-edit-through-three-levels | 35.215 | 19.875 | 21.479 | 0.56 | | edit-through-a-chain-of-dependents | 68.931 | 38.173 | 40.003 | 0.55 | | library-update-into-copies | 83.083 | 48.724 | 51.431 | 0.59 | | main-edit-among-many-shapes | 4.837 | 2.134 | 2.372 | 0.44 | | main-edit-into-10-copies | 1.79 | 0.936 | 0.978 | 0.52 | | main-edit-into-100-copies | 15.415 | 8.966 | 9.425 | 0.58 | | main-edit-into-1000-copies | 153.086 | 91.951 | 97.661 | 0.6 | | variant-switch-into-copies | 32.052 | 21.553 | 22.054 | 0.67 | AI-assisted-by: claude-opus-5-5 --- common/src/app/common/logic/variants.cljc | 12 +++++------- .../logic/composable_gen_test.cljc | 8 ++++++++ .../logic/variants_switch_test.cljc | 19 +++++++++++++++++++ 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/common/src/app/common/logic/variants.cljc b/common/src/app/common/logic/variants.cljc index 44a7d9e0e7..deffb5c805 100644 --- a/common/src/app/common/logic/variants.cljc +++ b/common/src/app/common/logic/variants.cljc @@ -552,13 +552,11 @@ ;; A swapped child is kept as it is, and the others carry their ;; touched attributes into their new child - new-head (get objects (:id new-shape)) - new-base-ref-shape (ctf/find-remote-shape (assoc container :objects objects) libraries new-head) - ;; the old main's shapes turned as the copy turns its new main, so - ;; the switch compares them with the new copy's in one frame - orient-ref (or (when new-base-ref-shape - (cll/orient-like new-base-ref-shape new-head - (gsh/shape->center new-base-ref-shape))) + ;; the old main's shapes turned as the old copy turns them, so the + ;; switch compares them with the new copy's in one frame + orient-ref (or (when orig-base-ref-shape + (cll/orient-like orig-base-ref-shape original-shape + (gsh/shape->center orig-base-ref-shape))) identity) ;; `ref-shape` turned too as the copy turns the parent of `old` below ;; its root, so a turn a nested copy authors is not the child's own diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index efd754dea3..74f7892634 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -2044,6 +2044,14 @@ [:edit 6 0 1 1] [:update-main 6] [:add-variant 0] [:switch 3] [:edit 0 0 1 1] [:update-main 0]]})))) +(t/deftest switching-to-a-flipped-variant-carries-no-flip-the-variants-do-not-share + (t/is (map? (cg/run {:world [2 2 {:variants true :text-styles true :layout nil :variant-diff false + :layout-item-margins false :grid-square false :rich-variants true + :layout-children false :grid-empty false :layout-copies true :text true}] + :ops [[:nest 1 0 0 0] [:combine 0 0 0 0] [:combine 2] [:switch 0] [:rotate 7 0 5 0] + [:make-variant 0] [:switch 0] [:make-variant 8 0 0 0] [:make-variant 0] [:switch 2] + [:transform 10 4 0 0] [:make-variant 0] [:switch 17]]})))) + (t/deftest turning-a-flipped-copy-turns-a-child-stored-as-the-other-mirror-turn (t/is (map? (cg/run {:world [2 2 {:variants true :text-styles true :layout nil :variant-diff false :layout-item-margins false :grid-square false :rich-variants true diff --git a/common/test/common_tests/logic/variants_switch_test.cljc b/common/test/common_tests/logic/variants_switch_test.cljc index f3843f3e22..39b5b4837e 100644 --- a/common/test/common_tests/logic/variants_switch_test.cljc +++ b/common/test/common_tests/logic/variants_switch_test.cljc @@ -126,6 +126,25 @@ (t/is (gsh/close-attrs? :points (:points child) (:points (ths/get-shape-by-id full (:id child))) 0.001)))) +(t/deftest switching-to-a-turned-variant-compares-the-old-child-in-its-own-copy-frame + (let [file (-> (thf/sample-file :file) + (thv/add-variant :variant :c01 :m01 :c02 :m02 + :variant1-params {:width 100 :height 100} + :variant2-params {:width 100 :height 100}) + (ths/add-sample-shape :child1 :parent-label :m01 :width 50 :height 50) + (ths/add-sample-shape :child2 :parent-label :m02 :width 50 :height 50) + (thc/instantiate-component :c01 :copy01 :children-labels [:copy-child])) + initial (-> (tm/make-situation file) + (r/step (n/rotate :m02 45)) r/settle + (r/step (n/rotate :child2 -45)) r/settle + (r/step (n/rotate :copy-child 30)) r/settle) + switched (-> initial (r/step (n/switch-variant :copy01 "Value2")) r/settle) + head (tm/resolve-shape switched :copy01) + child (tm/shape-by-id switched (first (:shapes head)))] + (t/is (mth/close? 0 (:rotation head) 0.001)) + (t/is (mth/close? 315 (:rotation child) 0.001)) + (t/is (not (ctk/touched-group? child :geometry-group))))) + (t/deftest switch-keeps-a-resize-override-after-rotating-the-copy (doseq [sizing [nil :fix]] (let [params {:width 100 :height 100 :layout-item-v-sizing sizing}