From 288e43dd7a12e189277e34d21e91525c0744e7c6 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Wed, 4 Nov 2026 23:16:32 +0100 Subject: [PATCH] :bug: Make a kept swapped child follow its parent's change on switch A variant switch moves a swapped child of the old copy into the new one and gives it the place of the new variant's occupant. The new copy is created at its main's size, so in a copy that a layout had made wider the child kept the size and place the wider parent gave it: a child the user moved, with a right constraint, stayed by the old right edge, and one with a scale constraint kept its grown size, which the layout then scaled again. The child and its subtree now follow the change from the old parent to the new one through their own constraints before taking that place. The switch tests of develop's swapped and moved children placement cover it. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | world | baseline | now | ratio | |------------------------------------+----------+---------+-------| | deepest-edit-through-three-levels | 35.215 | 21.321 | 0.61 | | edit-through-a-chain-of-dependents | 68.931 | 42.794 | 0.62 | | library-update-into-copies | 83.083 | 50.007 | 0.60 | | main-edit-among-many-shapes | 4.837 | 2.297 | 0.47 | | main-edit-into-10-copies | 1.79 | 1.003 | 0.56 | | main-edit-into-100-copies | 15.415 | 9.732 | 0.63 | | main-edit-into-1000-copies | 153.086 | 98.04 | 0.64 | | variant-switch-into-copies | 32.052 | 20.73 | 0.65 | AI-assisted-by: claude-opus-5-5 --- common/src/app/common/logic/variants.cljc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/common/src/app/common/logic/variants.cljc b/common/src/app/common/logic/variants.cljc index 0c3d1bd394..3a17c941e4 100644 --- a/common/src/app/common/logic/variants.cljc +++ b/common/src/app/common/logic/variants.cljc @@ -296,6 +296,16 @@ (pcb/change-parent (:parent-id related-shape-in-new) [child-at-root] pos {:allow-altering-copies true})) + ;; the child and its subtree follow the change from the old parent to + ;; the new one, each through its own constraints + changes (-> (cll/generate-follow-parent changes + (ctn/make-container (assoc page :objects (pcb/get-objects changes)) :page) + (get (pcb/get-objects changes) (:id orig-swapped-child)) + (get (:objects page) (:parent-id orig-swapped-child)) + current-parent + nil) + (pcb/apply-changes-local)) + objects (pcb/get-objects changes) child-id (:id orig-swapped-child) file {:id (:id ldata) :data ldata}