From 9a525661673f431d42f56d48f97f7e56ce125fcf Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Sun, 8 Nov 2026 20:31:30 +0100 Subject: [PATCH] :bug: Carry no override of a swap a main makes across a switch A main that nests a variant copy can swap a child of it for another component and override that component's fill. A copy of the main that switched its nested copy took the touched groups of the child's whole ref chain and compared them with the variant's slot, so it carried the fill authored over the swapped component onto the new variant's board. A child whose ref chain passes through a swap made by a main now has no counterpart in the new variant, and nothing carries into it. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | :world | :baseline | :now | :mean | :ratio | |------------------------------------+-----------+---------+--------+--------| | deepest-edit-through-three-levels | 35.215 | 19.723 | 20.106 | 0.56 | | edit-through-a-chain-of-dependents | 68.931 | 36.982 | 39.628 | 0.54 | | library-update-into-copies | 83.083 | 44.331 | 46.283 | 0.53 | | main-edit-among-many-shapes | 4.837 | 1.969 | 2.159 | 0.41 | | main-edit-into-10-copies | 1.79 | 1.05 | 1.078 | 0.59 | | main-edit-into-100-copies | 15.415 | 10.02 | 10.27 | 0.65 | | main-edit-into-1000-copies | 153.086 | 100.392 | 102.54 | 0.66 | | variant-switch-into-copies | 32.052 | 19.796 | 20.354 | 0.62 | AI-assisted-by: claude-opus-5-5 --- common/src/app/common/logic/variants.cljc | 13 ++++++++-- .../logic/composable_gen_test.cljc | 7 +++++ .../logic/variants_switch_test.cljc | 26 +++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/common/src/app/common/logic/variants.cljc b/common/src/app/common/logic/variants.cljc index 260985de52..42982a1301 100644 --- a/common/src/app/common/logic/variants.cljc +++ b/common/src/app/common/logic/variants.cljc @@ -507,9 +507,18 @@ orig-base-ref-shape (find-shape-ref-child-of container libraries old (:id orig-base-ref-shape))) new (get new-shapes-map (get o-ref-shapes-p-map (:id old-ref))) - swapped? (and (not root?) (ctk/swapped? old))] + swapped? (and (not root?) (ctk/swapped? old)) + ;; a main between the shape and the variant swapped it, so its + ;; content and overrides belong to another component + swapped-in-chain? + (and (not root?) (not swapped?) + (some #(and (ctk/swapped? %) (not= (:id %) (:id old-ref))) + (rest (ctf/get-ref-chain-until-target-ref container libraries old + (:id old-ref)))))] ;; a swap is kept only where the new variant holds a copy - (when (and new (or (not swapped?) (ctk/instance-head? new))) + (when (and new + (not swapped-in-chain?) + (or (not swapped?) (ctk/instance-head? new))) {:old old :old-ref old-ref :new new :swapped? swapped?}))) orig-touched) diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index ab4b12f498..2adba1681f 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -1857,6 +1857,13 @@ [:make-variant 0 0 0 0] [:detach 0 0 0 0] [:variant-property 0 0 0 0] [:switch 12]]})))) +(t/deftest switching-a-copy-carries-no-override-of-a-swap-its-main-makes + (t/is (map? (cg/run {:world [3 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 [[:edit 3 0 0 1] [:variant-property 0 6 0 0] [:switch 0] [:make-variant 5] + [:switch 13] [:make-variant 13 0 0 0] [:add-variant 0] [:switch 10]]})))) + (t/deftest random-variant-compositions (let [coverage (atom {}) failure (atom nil)] diff --git a/common/test/common_tests/logic/variants_switch_test.cljc b/common/test/common_tests/logic/variants_switch_test.cljc index cfe7b932dd..e8c84a6763 100644 --- a/common/test/common_tests/logic/variants_switch_test.cljc +++ b/common/test/common_tests/logic/variants_switch_test.cljc @@ -3573,6 +3573,32 @@ (t/is (gpt/close? (offset-in-root file :m02 :m02-icon) (offset-in-root file' :copy02 :copy-icon-b))))) +(t/deftest test-switch-carries-no-override-of-a-swap-its-main-makes + (let [;; ==== Setup: a main nests a copy of the first variant, swaps its icon + ;; for icon B and fills it; a copy of that main holds the nested copy + red [{:fill-color "#ff0000" :fill-opacity 1}] + file (-> (thf/sample-file :file1) + (tho/add-simple-component :icon-a :icon-a-root :icon-a-child) + (tho/add-simple-component :icon-b :icon-b-root :icon-b-child) + (thv/add-variant-with-copy :v01 :c01 :m01 :c02 :m02 :m01-icon :m02-icon :icon-a) + (tho/add-frame :outer-root) + (thc/instantiate-component :c01 :nested :parent-label :outer-root + :children-labels [:nested-icon]) + (thc/component-swap :nested-icon :icon-b :nested-icon-b) + (tho/change-shape :nested-icon-b #(assoc % :fills red)) + (thc/make-component :outer :outer-root) + (thc/instantiate-component :outer :copy-outer :children-labels [:copy-nested])) + + ;; ==== Action + file' (tho/swap-component-in-shape file :copy-nested :c02 {:new-shape-label :copy-nested-2 + :keep-touched? true}) + icon' (ths/get-shape-by-id file' (-> (ths/get-shape file' :copy-nested-2) :shapes first))] + + ;; ==== Check: the fill is icon B's override, which icon A does not take + (t/is (contains? (:touched (ths/get-shape file :nested-icon-b)) :fill-group)) + (t/is (not (contains? (:touched icon') :fill-group))) + (t/is (= (:fills (ths/get-shape file' :m02-icon)) (:fills icon'))))) + (t/deftest test-switch-drops-a-swap-the-new-variant-holds-no-copy-for (let [;; ==== Setup: the second variant's icon is detached into a plain board file (setup-variant-with-swapped-icon)