From ae0326d63fcfaabf3b44249e292b6e979d860e76 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Wed, 4 Nov 2026 10:51:25 +0100 Subject: [PATCH] :bug: Keep the layout item overrides of a switched copy head A swap gives the new head the layout item values of the head it replaces, without touching it. A variant switch then carries the old head's overrides, but skips any attribute that already has the old value, so the kept layout item values lost the overrides that authored them: a later sync of a copy could replace them, and reset no longer saw them. A switch also gives the new head the touched groups of the kept attributes the old head had. The model expects the old head's layout item overrides to survive a switch. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | world | baseline | now | ratio | |------------------------------------+----------+---------+-------| | deepest-edit-through-three-levels | 35.215 | 18.466 | 0.52 | | edit-through-a-chain-of-dependents | 68.931 | 38.447 | 0.56 | | library-update-into-copies | 83.083 | 45.429 | 0.55 | | main-edit-among-many-shapes | 4.837 | 2.162 | 0.45 | | main-edit-into-10-copies | 1.79 | 1.064 | 0.59 | | main-edit-into-100-copies | 15.415 | 9.072 | 0.59 | | main-edit-into-1000-copies | 153.086 | 89.75 | 0.59 | | variant-switch-into-copies | 32.052 | 19.484 | 0.61 | AI-assisted-by: claude-opus-5-5 --- common/src/app/common/logic/variants.cljc | 17 ++++++++++++++++- .../common_tests/logic/composable_gen_test.cljc | 7 +++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/common/src/app/common/logic/variants.cljc b/common/src/app/common/logic/variants.cljc index e11f0cb5cc..0c3d1bd394 100644 --- a/common/src/app/common/logic/variants.cljc +++ b/common/src/app/common/logic/variants.cljc @@ -617,6 +617,20 @@ (pcb/update-shapes [(:id shape)] #(update % :touched ctk/set-touched-group :geometry-group) {:ignore-touched true})))) +(defn- keep-placement-overrides + "A switch gives the new head the `swap-keep-attrs` of the copy head + `original-shape` it replaces, and with them the overrides that authored + them." + [changes original-shape new-shape] + (let [groups (into #{} + (comp (keep #(ctk/resolve-sync-group (:type original-shape) %)) + (filter #(ctk/touched-group? original-shape %))) + ctk/swap-keep-attrs)] + (cond-> changes + (seq groups) + (pcb/update-shapes [(:id new-shape)] #(update % :touched (fnil into #{}) groups) + {:ignore-touched true})))) + (defn generate-component-swap-in-place "Swap the copy head `shape` of `page` for a copy of the component `component-id` of library data `ldata`. The new head takes the old one's @@ -650,7 +664,8 @@ changes (cond-> changes keep-touched? - (keep-moved-placement shape new-shape page libraries)) + (-> (keep-moved-placement shape new-shape page libraries) + (keep-placement-overrides shape new-shape))) ;; Replacement keeps the head id and its cell. Cleanup during the ;; temporary deletion must not change the parent's placement data. diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 7ddbe1763d..87feb781f1 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -1093,3 +1093,10 @@ :ops [[:edit 18 0 0 0] [:delete 0 0 0 0] [:edit 3 0 1 1] [:update-main 3] [:update-main 0 0 0 0] [:resize 6 0 0 0] [:nest 16 0 0 0] [:swap 16 0 0 0] [:detach 2 0 0 0] [:style 8 20 2 0] [:reset 13 0 0 0]]})))) + +(t/deftest generated-switch-keeps-the-layout-item-override-it-carries + ;; a nested copy in a main with its own layout item margin keeps the + ;; margin through a switch, and the override that authors it + (t/is (map? (cg/run {:world [3 2 {:variants true :text-styles true :layout :flex :variant-diff false :rich-variants true + :layout-children true :layout-copies true :text true}] + :ops [[:delete 6 0 0 0] [:swap 20 0 0 0] [:nest 7 0 0 0] [:style 13 27 1] [:switch 0 0 0 0]]}))))