From 03f880979a0f750014f338faf88ac7f43e4f9536 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Sat, 7 Nov 2026 15:34:38 +0100 Subject: [PATCH] :bug: Keep the touched groups of the attributes a swap restores A swap restores the swap-keep-attrs (layout item attributes and interactions) of the old head on the new one, but dropped the touched groups they belong to, so a variant switch left those overrides unprotected and the next sync overwrote them (#12851). The new head now takes the touched groups of the restored attributes the old head had. Develop's layout item switch tests count the touched groups exactly; making a copy child absolute also authors its geometry here, so they leave :geometry-group out of the count. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | world | baseline | now | ratio | |------------------------------------+----------+---------+-------| | deepest-edit-through-three-levels | 35.215 | 19.816 | 0.56 | | edit-through-a-chain-of-dependents | 68.931 | 41.189 | 0.60 | | library-update-into-copies | 83.083 | 48.819 | 0.59 | | main-edit-among-many-shapes | 4.837 | 2.146 | 0.44 | | main-edit-into-10-copies | 1.79 | 0.962 | 0.54 | | main-edit-into-100-copies | 15.415 | 9.577 | 0.62 | | main-edit-into-1000-copies | 153.086 | 104.859 | 0.68 | | variant-switch-into-copies | 32.052 | 21.305 | 0.66 | AI-assisted-by: claude-opus-5-5 --- common/src/app/common/logic/swap.cljc | 14 ++++++++++++-- .../common_tests/logic/variants_switch_test.cljc | 6 ++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/common/src/app/common/logic/swap.cljc b/common/src/app/common/logic/swap.cljc index b143828985..e8f803a5bf 100644 --- a/common/src/app/common/logic/swap.cljc +++ b/common/src/app/common/logic/swap.cljc @@ -427,11 +427,21 @@ (get (pcb/get-objects changes) (:id new-shape)) changes - (generate-keep-orientation changes new-shape shape)] + (generate-keep-orientation changes new-shape shape) + + ;; the touched groups of the restored properties, so they stay overrides + kept-touched-groups + (into #{} + (comp (keep #(ctk/resolve-sync-group (:type new-shape) %)) + (filter #(ctk/touched-group? shape %))) + (keys keep-props-values))] [new-shape (-> changes ;; Restore the properties - (pcb/update-shapes [(:id new-shape)] #(d/patch-object % keep-props-values) + (pcb/update-shapes [(:id new-shape)] + #(cond-> (d/patch-object % keep-props-values) + (seq kept-touched-groups) + (update :touched (fnil into #{}) kept-touched-groups)) {:ignore-touched true}) ;; We need to set the same index as the original shape diff --git a/common/test/common_tests/logic/variants_switch_test.cljc b/common/test/common_tests/logic/variants_switch_test.cljc index 12fb3a0dd5..15da52f3ee 100644 --- a/common/test/common_tests/logic/variants_switch_test.cljc +++ b/common/test/common_tests/logic/variants_switch_test.cljc @@ -1938,7 +1938,8 @@ (doseq [group layout-item-override-groups] (t/is (contains? (:touched shape) group) (str label ": touched group " group))) - (t/is (= (count layout-item-override-groups) (count (:touched shape))) + ;; making a copy child absolute also authors its geometry, a group of its own + (t/is (= (count layout-item-override-groups) (count (disj (:touched shape) :geometry-group))) (str label ": number of touched groups"))) (def ^:private layout-item-attrs-partial @@ -1974,7 +1975,8 @@ (doseq [group layout-item-partial-override-groups] (t/is (contains? (:touched shape) group) (str label ": touched group " group))) - (t/is (= (count layout-item-partial-override-groups) (count (:touched shape))) + ;; making a copy child absolute also authors its geometry, a group of its own + (t/is (= (count layout-item-partial-override-groups) (count (disj (:touched shape) :geometry-group))) (str label ": number of touched groups"))) (t/deftest test-switch-preserves-touched-layout-item-attrs-on-root