From 4cf38cfad19077a8d1d72e69563fc268ded46496 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Sun, 8 Nov 2026 10:20:11 +0100 Subject: [PATCH] :bug: Sync a switched copy whose child's swap the switch ends A switch keeps a child the copy swapped for another component, and when the new variant holds that same component at the child's place the swap ends: the child becomes a plain copy of its new position. It kept the values it had, though, untouched, so it showed its old size or opacity where its new main authored others, until some later sync. When a switch ends a kept child's swap, the switched copy now syncs as an ordinary copy, as it already did when it carries a size. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | world | baseline | now | ratio | |------------------------------------+----------+---------+-------| | deepest-edit-through-three-levels | 35.215 | 20.516 | 0.58 | | edit-through-a-chain-of-dependents | 68.931 | 40.411 | 0.59 | | library-update-into-copies | 83.083 | 52.359 | 0.63 | | main-edit-among-many-shapes | 4.837 | 2.024 | 0.42 | | main-edit-into-10-copies | 1.790 | 0.954 | 0.53 | | main-edit-into-100-copies | 15.415 | 9.210 | 0.60 | | main-edit-into-1000-copies | 153.086 | 91.498 | 0.60 | | variant-switch-into-copies | 32.052 | 19.466 | 0.61 | AI-assisted-by: claude-opus-5-5 --- common/src/app/common/logic/variants.cljc | 10 +++++++--- .../test/common_tests/logic/composable_gen_test.cljc | 8 ++++++++ common/test/common_tests/logic/swap_group_test.cljc | 12 ++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/common/src/app/common/logic/variants.cljc b/common/src/app/common/logic/variants.cljc index e3d28f7c8e..d5bd2b1298 100644 --- a/common/src/app/common/logic/variants.cljc +++ b/common/src/app/common/logic/variants.cljc @@ -568,10 +568,14 @@ :include-deleted? true :with-context? true)) changes (keep-orientation-override changes original-shape new-shape page new-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. + ;; A kept child whose swap ended is a plain copy of its new position + ended-swap? (some (fn [{:keys [old swapped?]}] + (and swapped? (not (ctk/swapped? (get (pcb/get-objects changes) (:id old)))))) + pairs) + ;; A carried size changes the frame its untouched children follow, + ;; and an ended swap shows its position: both sync as an ordinary copy. changes (cond-> changes - (some #(ctk/touched-group? % :geometry-group) orig-touched) + (or ended-swap? (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)) diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 1c14c77c94..c215f96249 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -1792,6 +1792,14 @@ :ops [[:grid-cell 1 0 0 0] [:delete 5 0 0 0] [:make-variant 4 0 0 0] [:variant-property 0 0 0 0] [:switch 9]]})))) +(t/deftest a-swap-a-switch-ends-shows-its-new-position + (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 [[:swap 8 0 0 0] [:resize 0 0 0 0] [:make-variant 7] [:switch 6] + [:combine 13 0 0 0] [:variant-property 0 0 0 0] [:switch 13] [:make-variant 0] + [:switch 0] [:make-variant 2 0 0 0] [:make-variant 0] [:switch 16]]})))) + (t/deftest random-variant-compositions (let [coverage (atom {}) failure (atom nil)] diff --git a/common/test/common_tests/logic/swap_group_test.cljc b/common/test/common_tests/logic/swap_group_test.cljc index 7dd6d90214..3686e0ea97 100644 --- a/common/test/common_tests/logic/swap_group_test.cljc +++ b/common/test/common_tests/logic/swap_group_test.cljc @@ -431,6 +431,18 @@ (t/is (not (ctk/swapped? head))) (t/is (= (:id (thc/get-component file :heart)) (:component-id head))))) +(t/deftest switch-to-a-variant-with-the-same-component-takes-its-values + ;; the ended swap makes the head a plain copy of its new position, so it + ;; shows what the main authored there + (let [file (-> (setup-variants) + (tho/swap-component-in-shape :child2 :heart) + (set-opacity :child2 0.3) + (tho/swap-component-in-shape :copy01 :c02 {:keep-touched? true})) + head (ths/get-shape file :copy-child)] + (t/is (= (thi/id :child2) (:shape-ref head))) + (t/is (= 0.3 (:opacity head))) + (t/is (not (ctk/touched-group? head :layer-effects-group))))) + (t/deftest switch-to-a-variant-with-the-same-component-refers-to-its-children (let [file (-> (setup-variants) (tho/swap-component-in-shape :child2 :heart)