From b8a17af502a49b42da9109894f5ec64ee183472e Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Thu, 5 Nov 2026 15:06:03 +0100 Subject: [PATCH] :bug: Keep the main's size when update main pushes a size a constraint keeps A copy child that authors a constraint tying one of its dimensions to its copy parent keeps the size it shows when its main changes size; that size is kept by sync, not set by the user. Update main pushed it into the main with the constraint, so a main's nested copy lost the height it authors. Update main pushes such a copy shape, and its untouched descendants, with the main's geometry: the main keeps its own size and takes only what the copy authors. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | world | baseline | now | ratio | |------------------------------------+----------+---------+-------| | deepest-edit-through-three-levels | 35.215 | 20.743 | 0.59 | | edit-through-a-chain-of-dependents | 68.931 | 41.304 | 0.60 | | library-update-into-copies | 83.083 | 51.06 | 0.61 | | main-edit-among-many-shapes | 4.837 | 2.565 | 0.53 | | main-edit-into-10-copies | 1.79 | 1.045 | 0.58 | | main-edit-into-100-copies | 15.415 | 10.021 | 0.65 | | main-edit-into-1000-copies | 153.086 | 107.311 | 0.70 | | variant-switch-into-copies | 32.052 | 22.143 | 0.69 | AI-assisted-by: claude-opus-5-5 --- common/src/app/common/logic/libraries.cljc | 32 ++++++++++++++++--- .../logic/composable_gen_test.cljc | 9 ++++++ 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index 517c9aad82..d4c44de359 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -832,14 +832,36 @@ (update :undo-changes #(into [] xf %)))))] [(part :local-change?) (part (complement :local-change?))])) +(defn- kept-geometry? + "Whether the copy shape `shape-inst` shows a geometry that sync kept for + it instead of one it authors: its own constraint keeps its size + (`constraint-kept?`), or it follows an ancestor that does (`kept?`)." + [container shape-inst shape-main kept?] + (and (not (ctk/touched-group? shape-inst :geometry-group)) + (or kept? (constraint-kept? container shape-inst shape-main)))) + +(defn- with-main-geometry + "`shape-inst` with the geometry of `shape-main`, its main shape, placed in + the copy's frame." + [shape-inst shape-main root-inst root-main] + (let [attrs (cond-> placement-geometry-attrs + (= :path (:type shape-inst)) (conj :content))] + (merge shape-inst (select-keys (reposition-shape shape-main root-main root-inst) attrs)))) + (defn- update-main-shape "Push the copy shape `shape-inst` into `shape-main`, the main shape it pairs with: the copy's values, overrides included, go into the main, and - its touched groups move there (the copy keeps a swap)." - [changes {:keys [container main-container root-inst root-main remote-synced inherited-turn]} shape-inst shape-main] + its touched groups move there (the copy keeps a swap). A geometry that + sync kept for the copy (`:kept?`) is not the copy's, so the main keeps + its own." + [changes {:keys [container main-container root-inst root-main remote-synced inherited-turn kept?]} shape-inst shape-main] (cond-> (-> changes (update-attrs shape-main - (cond-> shape-inst (some? inherited-turn) inherited-turn) + (cond-> shape-inst + (some? inherited-turn) inherited-turn + kept? (with-main-geometry shape-main + (cond-> root-inst (some? inherited-turn) inherited-turn) + root-main)) root-main (cond-> root-inst (some? inherited-turn) inherited-turn) main-container false) @@ -875,7 +897,9 @@ (let [children-inst (vec (ctn/get-direct-children container shape-inst)) children-main (vec (ctn/get-direct-children main-container shape-main)) ;; the main shapes added for copy children, by copy child id - added (volatile! {})] + added (volatile! {}) + kept? (kept-geometry? container shape-inst shape-main (:kept? ctx)) + ctx (assoc ctx :kept? kept?)] (vswap! synced-ids conj (:id shape-inst)) (cond-> (-> changes (update-main-shape ctx shape-inst shape-main) diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 70d18eb6e2..522b1c0fe8 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -1125,3 +1125,12 @@ :layout-children false :grid-empty false :layout-copies true :text true}] :ops [[:delete 5 0 0 0] [:swap 4 0 0 0] [:nest 0 0 0 0] [:duplicate 1 0 0 0] [:rotate 1 0 0 0] [:resize 1 0 0 0] [:rotate 4 0 2 0] [:update-main 0 0 0 0]]})))) + +(t/deftest generated-update-main-keeps-the-mains-size-over-a-size-a-constraint-keeps + ;; a copy child keeps its size through its own scale constraint while its + ;; main, a main's nested copy, takes a height of 80; update main pushes + ;; the constraint and the main keeps its 80 + (t/is (map? (cg/run {:world [2 0 {:variants true :text-styles true :layout nil :layout-item-margins false + :grid-square false :library true :rich-variants true :layout-children false + :grid-empty false :layout-copies true :text true}] + :ops [[:style 16 8 1] [:edit 11 11 0 0] [:resize 0 0 0 0] [:update-main 4 0 0 0]]}))))