🐛 Keep the size a board's constraints give a nested copy on sync

A copy inside a plain board, such as a main, follows the board's resizes
through its constraints. That resize is not an override: the user did not
set the size. The next sync of the copy's own component then gave it the
component's size, undoing the constraint: a copy scaled to 80 px inside an
80 px main went back to 100 px and overflowed it.

When syncing a copy head whose parent is a plain board, keep the dimensions
its constraints tie to that board (scale or left-right horizontally, scale
or top-bottom vertically); its other attributes still sync. The main is
placed at those dimensions first, so the copy's children follow through
their constraints.

A second re-run of the seed-20261101 library property found this; it also
fails on earlier commits. The regression fails before the fix (100 px after
a fill edit of the component) and passes after it: the copy stays 80 px
tall, takes the new fill, keeps the component's width and gets no geometry
override. Full common passes lint, JVM, JavaScript and formatting: JVM 2078
tests / 33886 assertions; JavaScript 2014 / 32497. All six component
properties pass 40 programs each at seed 712 in both runtimes.

Compare lower-quantile milliseconds with the saved baseline; keep that
baseline unchanged. The machine/JVM warning makes ratios rough. No world
is flagged.

World                      Baseline       Now    Ratio
Main into 10 copies           1.790     0.895     0.50
Main into 100 copies         15.415     9.268     0.60
Main into 1000 copies       153.086    91.733     0.60
Three nesting levels         35.215    18.542     0.53
Dependency chain             68.931    37.663     0.55
Library update               83.083    44.259     0.53
Many plain shapes             4.837     2.206     0.46
Variant switch               32.052    20.658     0.64

AI-assisted-by: claude-opus-5-5
This commit is contained in:
alonso.torres 2026-10-31 13:57:28 +01:00
parent 4ef0174917
commit 9056fc9128
2 changed files with 49 additions and 2 deletions

View File

@ -586,6 +586,23 @@
{:ignore-touched true}))
changes)))
(defn- constraint-sized-main
"`shape-main` resized to the dimensions the constraints of `shape-inst`, a
copy head synced as a root, tie to its plain parent board: they follow the
board's resizes, which are not overrides, so sync keeps them. Nil when no
dimension is tied."
[container shape-inst shape-main]
(let [parent (ctn/get-shape container (:parent-id shape-inst))
width? (contains? #{:scale :leftright} (:constraints-h shape-inst))
height? (contains? #{:scale :topbottom} (:constraints-v shape-inst))]
(when (and (cfh/frame-shape? parent)
(not (cfh/root? parent))
(nil? (:shape-ref parent))
(or width? height?))
(let [width (:width (:selrect (if width? shape-inst shape-main)))
height (:height (:selrect (if height? shape-inst shape-main)))]
(gsh/transform-shape shape-main (ctm/change-size shape-main width height))))))
(defn- sync-copy-recursive
"Sync the copy shape `shape-inst` from `shape-main`, the main shape it
pairs with, then pair their children (`compare-children`) and walk each
@ -608,8 +625,12 @@
(let [;; a copy shape that keeps its own geometry passes it on to its
;; children, which follow it as they follow their main's
shape-before shape-inst
placed (when (and (not reset?) (ctk/touched-group? shape-inst :geometry-group))
(in-main-frame shape-inst (:root-inst ctx) (:root-main ctx)))
placed (cond
(and (not reset?) (ctk/touched-group? shape-inst :geometry-group))
(in-main-frame shape-inst (:root-inst ctx) (:root-main ctx))
(and (not reset?) (= (:id shape-inst) (:id (:root-inst ctx))))
(constraint-sized-main container shape-inst shape-main))
main-container (cond-> main-container
(and (some? placed) (not (close-geometry? placed shape-main)))
(update :objects placed-like shape-main placed

View File

@ -25,6 +25,8 @@
[app.common.test-helpers.composable.comp.runner :as r]
[app.common.test-helpers.composable.comp.setups :as setup]
[app.common.test-helpers.composable.core :as tm]
[app.common.test-helpers.composable.gen :as cg]
[app.common.test-helpers.composable.oracle :as oracle]
[app.common.test-helpers.compositions :as tho]
[app.common.test-helpers.files :as thf]
[app.common.test-helpers.ids-map :as thi]
@ -33,6 +35,7 @@
[app.common.test-helpers.texts :as thtx]
[app.common.types.container :as ctn]
[app.common.types.modifiers :as ctm]
[app.common.types.shape :as cts]
[clojure.test :as t]))
(t/use-fixtures :each thi/test-fixture)
@ -413,3 +416,26 @@
flips (fn [shape] (mapv #(boolean (get shape %)) [:flip-x :flip-y]))]
(t/is (= (flips shape) (flips after)))
(t/is (gsh/close-attrs? :points (:points shape) (:points after) 0.001))))))
(t/deftest a-copy-keeps-the-size-a-plain-boards-constraint-gave-it
;; A resize through constraints is derived, never an override, and the
;; next sync of the copy's own component keeps it.
(let [file (-> (thf/sample-file :file1)
(tho/add-simple-component :inner :inner-root :inner-child
:root-params {:width 100 :height 100}
:child-params {:x 30 :y 30 :width 40 :height 40})
(tho/add-frame :outer-root {:x 200 :y 0 :width 240 :height 100})
(thc/instantiate-component :inner :nested :parent-label :outer-root
:children-labels [:nested-child])
(ths/update-shape :nested :constraints-v :scale)
(thc/make-component :outer :outer-root))
shrunk (-> (tm/make-situation file) (r/step (n/change-height :outer-root 80)) r/settle)
resized (tm/resolve-shape shrunk :nested)
edited (-> shrunk (r/step (n/change-property :inner-child :fills "#dc2626")) r/settle)
after (tm/resolve-shape edited :nested)]
(t/is (mth/close? 80 (:height resized)))
(t/is (not (contains? (:touched resized) :geometry-group)))
(t/is (= "#dc2626" (get-in (tm/resolve-shape edited :nested-child) [:fills 0 :fill-color])))
(t/is (mth/close? 80 (:height after)))
(t/is (mth/close? 100 (:width after)))
(t/is (not (contains? (:touched after) :geometry-group)))))