From 964433cfc64f6f2fe0a14283511f9bf68b21dc41 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Sat, 24 Oct 2026 14:33:57 +0200 Subject: [PATCH] :bug: Keep orientation inherited from the old variant on switch A switch keeps the old root orientation even when its main supplied it. Record that retained choice as geometry when it differs from the new expected placement. Continue inheriting placement from enclosing copies when the switch carries no root geometry override. Portable regression: three failures before the fix; now passes through full sync. Focused JVM checks: 182 tests, 2137 assertions. Existing goldens match. Full frontend: 1528 tests, 8877 assertions. Live WASM passes. Component benchmark ratios: mains 0.58/0.57/0.60; levels 0.49; chain 0.50; library 0.60; many shapes 0.46; variant switch 0.65. All worlds pass with task stress JVMs paused. An earlier run during concurrent JVM startup exceeded the timing gate; the baseline is unchanged. AI-assisted-by: GPT-6 --- common/src/app/common/logic/variants.cljc | 28 +++++++++++-------- .../logic/variants_switch_test.cljc | 27 ++++++++++++++++++ 2 files changed, 44 insertions(+), 11 deletions(-) diff --git a/common/src/app/common/logic/variants.cljc b/common/src/app/common/logic/variants.cljc index 204e8978b0..666a97329d 100644 --- a/common/src/app/common/logic/variants.cljc +++ b/common/src/app/common/logic/variants.cljc @@ -465,19 +465,25 @@ (clsw/update-attrs-on-switch changes new old new-shape original-shape old-ref container))) changes pairs) - changes (cond-> changes - (some #(and (= (:id %) (:id original-shape)) - (ctk/touched-group? % :geometry-group)) orig-touched) - (keep-orientation-override original-shape new-shape page - (or (get-in libraries [(:component-file new-shape) :data]) ldata) - (:component-id new-shape) nil)) + root-geometry? (some #(and (= (:id %) (:id original-shape)) + (ctk/touched-group? % :geometry-group)) orig-touched) + parent (get page-objects (:parent-id original-shape)) + ;; A switch keeps orientation even when the old main supplied it. + ;; If no geometry was carried, placement from an enclosing copy is + ;; still inherited rather than authored by this switch. + position (when (and (not root-geometry?) (:shape-ref parent)) + (ctf/find-ref-shape nil page libraries original-shape + :include-deleted? true :with-context? true)) + changes (keep-orientation-override changes original-shape new-shape page + (or (get-in libraries [(:component-file new-shape) :data]) ldata) + (:component-id new-shape) position) ;; A carried size changes the frame its untouched children follow. ;; Place them through the same constraints as an ordinary copy sync. - changes (cond-> changes - (some #(ctk/touched-group? % :geometry-group) orig-touched) - (cll/generate-sync-shape-direct - nil libraries (assoc container :objects (pcb/get-objects changes)) - (:id new-shape) false))] + changes (cond-> changes + (some #(ctk/touched-group? % :geometry-group) orig-touched) + (cll/generate-sync-shape-direct + nil libraries (assoc container :objects (pcb/get-objects changes)) + (:id new-shape) false))] [changes (mapv (comp :parent-id :new) pairs)])) (defn- shape-index diff --git a/common/test/common_tests/logic/variants_switch_test.cljc b/common/test/common_tests/logic/variants_switch_test.cljc index 57cb460738..8d93bae933 100644 --- a/common/test/common_tests/logic/variants_switch_test.cljc +++ b/common/test/common_tests/logic/variants_switch_test.cljc @@ -16,6 +16,8 @@ [app.common.math :as mth] [app.common.test-helpers.components :as thc] [app.common.test-helpers.composable.comp.nodes :as n] + [app.common.test-helpers.composable.comp.runner :as r] + [app.common.test-helpers.composable.core :as tm] [app.common.test-helpers.compositions :as tho] [app.common.test-helpers.files :as thf] [app.common.test-helpers.ids-map :as thi] @@ -31,6 +33,31 @@ (t/use-fixtures :each thi/test-fixture) +(t/deftest switching-an-untouched-rotated-copy-authors-its-retained-orientation + (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 :m01 45)) r/settle) + before (tm/resolve-shape initial :copy01) + 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))) + file (tm/file switched) + full (:file (r/sync-cascade file {} (keys (get-in file [:data :components]))))] + (t/is (empty? (:touched before))) + (t/is (mth/close? 45 (:rotation before) 0.001)) + (t/is (= #{:geometry-group} (:touched head))) + (t/is (mth/close? 45 (:rotation head) 0.001)) + (t/is (gsh/close-attrs? :points (:points head) + (:points (ths/get-shape-by-id full (:id head))) 0.001)) + (t/is (gsh/close-attrs? :points (:points child) + (:points (ths/get-shape-by-id full (:id child))) 0.001)))) + (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}