From 2c918644d15539494fd4add1cf25e50b1b9c9f85 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Thu, 5 Nov 2026 22:25:51 +0100 Subject: [PATCH] :bug: Lay out a resized copy's subtree without its parent's layout A sync that turns and resizes a copy lays out the copy's main subtree at the copy's size. That layout climbed to the main's parent: in a grid whose duplicated child had no cell yet, laying out the grid crashed. The subtree is laid out under the root, so only its own layouts run and no layout of the main's parent owns the copy's size. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | world | baseline | now | ratio | |------------------------------------+----------+---------+-------| | deepest-edit-through-three-levels | 35.215 | 19.675 | 0.56 | | edit-through-a-chain-of-dependents | 68.931 | 43.856 | 0.64 | | library-update-into-copies | 83.083 | 45.859 | 0.55 | | main-edit-among-many-shapes | 4.837 | 2.118 | 0.44 | | main-edit-into-10-copies | 1.79 | 1.051 | 0.59 | | main-edit-into-100-copies | 15.415 | 9.265 | 0.60 | | main-edit-into-1000-copies | 153.086 | 92.142 | 0.60 | | variant-switch-into-copies | 32.052 | 21.434 | 0.67 | AI-assisted-by: claude-opus-5-5 --- common/src/app/common/logic/libraries.cljc | 6 ++++-- .../test/common_tests/logic/composable_gen_test.cljc | 10 ++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index 345cbf15ef..807315fd99 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -38,6 +38,7 @@ [app.common.types.text :as txt] [app.common.types.token :as cto] [app.common.types.typography :as cty] + [app.common.uuid :as uuid] [clojure.set :as set])) ;; Change this to :info :debug or :trace to debug this module, or :warn to reset to default @@ -565,9 +566,10 @@ objects (let [modif-tree (gm/set-objects-modifiers {(:id shape-main) {:modifiers (ctm/change-size shape-main width height)}} - ;; the copy keeps its own size, which no layout of the main owns + ;; the subtree alone, under the root: no layout of the main's + ;; parent owns the copy's size (-> (reduce-kv #(d/update-when %1 %2 merge %3) objects authored) - (assoc-in [(:id shape-main) :layout-item-absolute] true)))] + (update (:id shape-main) assoc :parent-id uuid/zero)))] (reduce-kv (fn [objects id {:keys [modifiers]}] (d/update-when objects id gsh/transform-shape modifiers)) objects diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index b32ed9aedb..1010dc1dce 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -1187,3 +1187,13 @@ :grid-square false :library true :rich-variants true :layout-children false :grid-empty false :layout-copies true :text true}] :ops [[:nest 6 0 0 0] [:text 6 0 0 0] [:delete 6 0 0 0] [:swap 6 0 0 0] [:switch 0 0 0 0]]})))) + +(t/deftest generated-duplicate-in-a-grid-resizes-a-copy-subtree-alone + ;; a sync that resizes a copy in a grid lays out the copy's subtree while + ;; the grid has a duplicated child with no cell yet; the program reaches + ;; that sync on every other run, so it runs twice + (dotimes [_ 2] + (t/is (map? (cg/run {:world [2 2 {:variants true :text-styles true :layout :grid :variant-diff false + :layout-item-margins false :grid-square false :rich-variants true + :layout-children false :grid-empty true :layout-copies true :text true}] + :ops [[:style 0 29 1] [:nest 9 0 0 0] [:duplicate 5 1 0 0]]})))))