🐛 Restore the inherited sizing of a reset child of a swapped head

A nested head whose parent is a swapped layout head kept its authored
layout sizing after a reset: the reset pairs the parent with the ref's
parent through the parent's shape-ref, and a swapped head refers to its
position, not to the main of its own component. A later sync of that head
then gave the child its main's sizing. The reset now also pairs a parent
that is a copy of the component whose main root holds the ref.

Test: resetting-a-nested-copy-of-a-swapped-layout-head-restores-its-sizing
(the variant gate program of round 12, seed 371855618). Composable
generated, reset and swap group tests: 433 tests, 0 failures.

Benchmark (scripts/bench-components, ms, lower 2.5% quantile):
|                             :world | :baseline |   :now |   :mean | :ratio |
|------------------------------------+-----------+--------+---------+--------|
|  deepest-edit-through-three-levels |    35.215 |   20.1 |  20.737 |   0.57 |
| edit-through-a-chain-of-dependents |    68.931 | 40.911 |  41.855 |   0.59 |
|         library-update-into-copies |    83.083 | 47.542 |  52.797 |   0.57 |
|        main-edit-among-many-shapes |     4.837 |  2.495 |   2.627 |   0.52 |
|           main-edit-into-10-copies |      1.79 |   0.99 |   1.045 |   0.55 |
|          main-edit-into-100-copies |    15.415 |  9.458 |   9.877 |   0.61 |
|         main-edit-into-1000-copies |   153.086 | 97.254 | 101.408 |   0.64 |
|         variant-switch-into-copies |    32.052 | 20.235 |  21.101 |   0.63 |

AI-assisted-by: claude-opus-5-5
This commit is contained in:
alonso.torres 2026-11-11 03:37:40 +01:00
parent 5f20d4c8cd
commit 5b223cb8f5
2 changed files with 17 additions and 4 deletions

View File

@ -2524,8 +2524,9 @@
(defn- reset-layout-item
"Give a reset head the layout item values it inherits: those of its ref
when its parent is the copy of the ref's layout parent. Sync passes them
from parent to children, so the reset of the head alone keeps them."
when its parent is the copy of the ref's layout parent, or a swapped head
whose main is that parent. Sync passes them from parent to children, so
the reset of the head alone keeps them."
[changes file libraries container shape-id]
(let [objects (pcb/get-objects changes)
shape (get objects shape-id)
@ -2533,8 +2534,12 @@
ref (when (and (:layout parent) (:shape-ref parent))
(ctf/find-ref-shape file (assoc container :objects objects) libraries shape
:include-deleted? true :with-context? true))
ref-parent (get-in (meta ref) [:container :objects (:parent-id ref)])]
(if (and ref (:layout ref-parent) (= (:id ref-parent) (:shape-ref parent)))
ref-parent (get-in (meta ref) [:container :objects (:parent-id ref)])
;; whether sync pairs the parent with the ref's parent
paired? (or (= (:id ref-parent) (:shape-ref parent))
(and (ctk/main-instance? ref-parent)
(= (:component-id ref-parent) (:component-id parent))))]
(if (and ref (:layout ref-parent) paired?)
(pcb/update-shapes changes [shape-id] #(propagate-attrs % ref layout-child-attrs false)
{:ignore-touched true})
changes)))

View File

@ -2151,6 +2151,14 @@
:layout-children true :grid-empty true :layout-copies true :text true}]
:ops [[:make-variant 1] [:style 4 29 1] [:style 7 12] [:update-main]]}))))
(t/deftest resetting-a-nested-copy-of-a-swapped-layout-head-restores-its-sizing
(t/is (map? (cg/run {:world [2 2 {:variants true :text-styles true :layout :grid :variant-diff true
:layout-item-margins false :grid-square false :rich-variants true
:layout-children false :grid-empty false :layout-copies true :text true}]
:ops [[:variant-property 5 1 3] [:variant-property 0 6 3] [:combine 6]
[:add-variant 0 6 7] [:combine 4 4 7] [:resize 3 7 4] [:switch 6] [:delete 5]
[:restore 0 5 7 5] [:swap 1 3 1 5] [:style 0 30 1] [:reset 3]]}))))
(t/deftest moving-a-flex-copy-child-after-a-switch-resized-its-sibling-authors-no-geometry
(t/is (map? (cg/run {:world [1 2 {:variants true :text-styles false :layout :flex :variant-diff false
:layout-item-margins false :grid-square false :rich-variants true