🐛 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
This commit is contained in:
alonso.torres 2026-11-07 15:34:38 +01:00
parent 56e315bd7a
commit 03f880979a
2 changed files with 16 additions and 4 deletions

View File

@ -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

View File

@ -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