From a5ebdb9e8cfe172b6603ef03b17a1770d41a4789 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 10 Nov 2026 05:35:46 +0100 Subject: [PATCH] :bug: Give a cell to a copy child that a sync brings back into the flow A grid copy took one of its children out of the flow (absolute position) and changed its own width. Resetting it gave the child back its main's position, which puts it in the flow, while the copy's cells had no room for it, and placing the resized copy's subtree failed in the grid layout. The layout child attributes a sync copies onto the children did not assign the grid's cells again, and that placement read the grid as it was before the sync, with its old cells. The grid now assigns its cells again when a synced child enters or leaves its flow, and the placement takes the synced parent with only its old placement. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | :world | :baseline | :now | :mean | :ratio | |------------------------------------+-----------+--------+---------+--------| | deepest-edit-through-three-levels | 35.215 | 18.907 | 19.891 | 0.54 | | edit-through-a-chain-of-dependents | 68.931 | 42.713 | 43.599 | 0.62 | | library-update-into-copies | 83.083 | 51.226 | 52.74 | 0.62 | | main-edit-among-many-shapes | 4.837 | 2.266 | 2.385 | 0.47 | | main-edit-into-10-copies | 1.79 | 0.954 | 0.986 | 0.53 | | main-edit-into-100-copies | 15.415 | 9.427 | 9.984 | 0.61 | | main-edit-into-1000-copies | 153.086 | 94.804 | 102.222 | 0.62 | | variant-switch-into-copies | 32.052 | 22.513 | 22.828 | 0.7 | AI-assisted-by: claude-opus-5-5 --- common/src/app/common/logic/libraries.cljc | 60 ++++++++++++------- .../common_tests/logic/comp_reset_test.cljc | 25 ++++++++ .../logic/composable_gen_test.cljc | 7 +++ 3 files changed, 69 insertions(+), 23 deletions(-) diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index afe5a437be..6068ddb0db 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -660,9 +660,11 @@ (assoc shape :transform matrix :transform-inverse (gmt/inverse matrix)))) turn (orient-like (orientation before) (orientation after) (gsh/shape->center before)) delta (gpt/subtract (gsh/shape->center after) (gsh/shape->center before)) - ;; the subtree as the sync left it, under the parent before the sync + ;; the subtree as the sync left it, under the parent placed as before the sync placed (when resized? - (placed-like (assoc (pcb/get-objects changes) (:id before) before) before after {}))] + (placed-like (assoc (pcb/get-objects changes) (:id before) + (merge after (select-keys before placement-geometry-attrs))) + before after {}))] (pcb/update-shapes changes ids (if resized? #(get placed (:id %) %) @@ -1980,29 +1982,41 @@ fixes it, and the layout child attributes of each of its children, from the child of `src` it pairs with (`src-child`); a child with none is left as it is. With `omit-touched?`, an attribute whose group is touched is - left as it is." + left as it is. A grid `dest` assigns its cells again when that takes a + child in or out of its flow." [changes container dest src src-child omit-touched?] - (pcb/concat-changes - changes - (-> (pcb/empty-changes) - (pcb/with-container container) - (pcb/with-objects (:objects container)) - (pcb/update-shapes - [(:id dest)] - (fn [dest] - (cond-> dest - (contains? #{:auto :fix} (:layout-item-h-sizing src)) - (propagate-attrs src #{:layout-item-h-sizing} omit-touched?) + (let [objects (:objects container) + propagated #(if-let [src-child (src-child %)] + (propagate-attrs % src-child layout-child-attrs omit-touched?) + %) + ;; whether a child enters or leaves the flow of a grid + reflow? (and (ctsl/grid-layout? dest) + (some #(let [child (get objects %)] + (and child + (not= (ctsl/position-absolute? child) + (ctsl/position-absolute? (propagated child))))) + (:shapes dest)))] + (pcb/concat-changes + changes + (cond-> (-> (pcb/empty-changes) + (pcb/with-container container) + (pcb/with-objects objects) + (pcb/update-shapes + [(:id dest)] + (fn [dest] + (cond-> dest + (contains? #{:auto :fix} (:layout-item-h-sizing src)) + (propagate-attrs src #{:layout-item-h-sizing} omit-touched?) - (contains? #{:auto :fix} (:layout-item-v-sizing src)) - (propagate-attrs src #{:layout-item-v-sizing} omit-touched?))) - {:ignore-touched true}) - (pcb/update-shapes - (:shapes dest) - #(if-let [src-child (src-child %)] - (propagate-attrs % src-child layout-child-attrs omit-touched?) - %) - {:ignore-touched true})))) + (contains? #{:auto :fix} (:layout-item-v-sizing src)) + (propagate-attrs src #{:layout-item-v-sizing} omit-touched?))) + {:ignore-touched true}) + (pcb/update-shapes (:shapes dest) propagated {:ignore-touched true})) + reflow? + (pcb/update-shapes [(:id dest)] ctsl/assign-cells {:with-objects? true :ignore-touched true}) + + (and reflow? (= :page (:type container))) + (pcb/reorder-grid-children [(:id dest)]))))) (defn- add-inherited-grid-cells "Add default cells in newly inherited tracks without replacing authored cells." diff --git a/common/test/common_tests/logic/comp_reset_test.cljc b/common/test/common_tests/logic/comp_reset_test.cljc index 6975606485..27cb707288 100644 --- a/common/test/common_tests/logic/comp_reset_test.cljc +++ b/common/test/common_tests/logic/comp_reset_test.cljc @@ -50,6 +50,31 @@ (t/is (= 2 (column reset))) (t/is (nil? (:touched (tm/resolve-shape reset :copy-nested)))))) +(t/deftest reset-a-resized-grid-copy-gives-a-cell-to-the-child-it-brings-back-into-the-flow + (let [;; ==== Setup: the copy takes Item B out of the flow and narrows itself + file (-> (thf/sample-file :file1) + (tho/add-grid-frame :main-root) + (tho/add-rect :main-a :parent-label :main-root) + (tho/add-rect :main-b :parent-label :main-root) + (tho/place-in-grid-columns :main-root 2 {1 :main-a 2 :main-b}) + (thc/make-component :grid :main-root) + (thc/instantiate-component :grid :copy :children-labels [:copy-a :copy-b])) + initial (tm/make-situation file) + edited (-> initial + (r/step (n/change-property :copy-b :layout-item-absolute true)) r/settle + (r/step (n/transform-shape :copy :width 80)) r/settle) + + ;; ==== Action + reset (-> edited (r/step (n/reset :copy)) r/settle) + column (fn [s] + (:column (ctl/get-cell-by-shape-id (tm/resolve-shape s :copy) (thi/id :copy-b))))] + + ;; ==== Check: Item B is back in its main's cell + (t/is (nil? (column edited))) + (t/is (= 80.0 (:width (tm/resolve-shape edited :copy)))) + (t/is (= 2 (column reset))) + (t/is (nil? (:touched (tm/resolve-shape reset :copy-b)))))) + (t/deftest reset-a-nested-copy-through-a-deleted-outer-main (let [initial (setup/nested-component-with-copy) edited (-> initial diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 5684fbcf48..b87304f8ad 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -2020,6 +2020,13 @@ :ops [[:nest 6 0 0 0] [:style 3 1 1] [:library-variant-property 0 0 0 0] [:library-sync] [:switch 6]]})))) +(t/deftest resetting-a-resized-grid-copy-gives-a-cell-to-the-child-back-in-its-flow + (t/is (map? (cg/run {:world [3 2 {:variants true :text-styles true :layout :grid :variant-diff false + :layout-item-margins false :grid-square false :rich-variants true + :layout-children true :grid-empty false :layout-copies true :text true}] + :ops [[:make-variant 4 0 0 0] [:combine 0 0 0 0] [:transform 6 7 0 0] [:nest 1 0 0 0] + [:combine 3] [:switch 6] [:style 16 35 1] [:edit 8 1 1 :copy-head] [:reset 8]]})))) + (t/deftest turning-a-flipped-copy-turns-a-child-stored-as-the-other-mirror-turn (t/is (map? (cg/run {:world [2 2 {:variants true :text-styles true :layout nil :variant-diff false :layout-item-margins false :grid-square false :rich-variants true