From 0436156e27da38a047314bca851bcf3ab4a466f0 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 3 Nov 2026 23:37:36 +0100 Subject: [PATCH] :bug: Keep the moved place of a copy child a pushed switch replaces A copy in a main can move one of its nested children, which marks the child's geometry as its own. When a copy of that main switches the child to another variant and the switch is pushed into the main, the new nested copy replaces the moved child at the same place, but nothing marked that place as its own. The next sync brought it back to its component's place and the main's nested copy no longer matched. The pushed head now takes the placement groups the replaced child had touched, so it keeps the place it inherits. The model expects them with the head's geometry in the main. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | world | baseline | now | ratio | |------------------------------------+----------+---------+-------| | deepest-edit-through-three-levels | 35.215 | 21.215 | 0.60 | | edit-through-a-chain-of-dependents | 68.931 | 41.146 | 0.60 | | library-update-into-copies | 83.083 | 48.017 | 0.58 | | main-edit-among-many-shapes | 4.837 | 2.678 | 0.55 | | main-edit-into-10-copies | 1.79 | 1.023 | 0.57 | | main-edit-into-100-copies | 15.415 | 9.272 | 0.60 | | main-edit-into-1000-copies | 153.086 | 94.933 | 0.62 | | variant-switch-into-copies | 32.052 | 24.787 | 0.77 | AI-assisted-by: claude-opus-5-5 --- common/src/app/common/logic/libraries.cljc | 8 ++++++-- common/test/common_tests/logic/composable_gen_test.cljc | 7 +++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index f356856d98..cfe1e01527 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -1203,9 +1203,13 @@ :include-deleted? true :with-context? true) take-position (ctf/take-position nil libraries objects new-head (:shape-ref replaced) position) - position-objects (get-in (meta position) [:container :objects])] + position-objects (get-in (meta position) [:container :objects]) + ;; the head takes the place the replaced child authored + placement (set/intersection (set (:touched replaced)) placement-groups)] (mapv (fn [shape] - (let [shape (take-position shape)] + (let [shape (cond-> (take-position shape) + (and (= (:id shape) (:id new-head)) (seq placement)) + (update :touched (fnil into #{}) placement))] (author-pushed-content shape (get position-objects (:shape-ref shape))))) new-shapes)) new-shapes) diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index e63dbb35c8..b60957180d 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -1056,3 +1056,10 @@ :rich-variants true :layout-copies true :text true}] :ops [[:style 24 8 1] [:swap 2 0 0 0] [:edit 3 0 1 1] [:update-main 3] [:update-main 0 0 0 0]]})))) + +(t/deftest generated-pushed-switch-takes-the-place-its-copy-authored + ;; a switched head pushed into a copy in a main takes the place the copy + ;; child it replaces had moved to, as its own geometry + (t/is (map? (cg/run {:world [2 2 {:variants true :text-styles true :variant-diff false :rich-variants true + :layout-copies true :text true}] + :ops [[:delete 5 0 0 0] [:switch 3 0 0 0] [:transform 0 0 0 3] [:update-main 0 0 0 0]]}))))