From d3f073fe82905b3f4ec47e6512dd85bfc3bfd82b Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Fri, 30 Oct 2026 20:18:55 +0100 Subject: [PATCH] :bug: Keep an inherited turn out of update main A nested copy inside a turned parent inherits that turn as placement. Update main pushed it into the copy's main as if the copy had authored it, and the copy then composed the turn twice: 45 degrees became 90. When the copy root does not author its geometry, turn the copy subtree back into the main's frame before pushing its values. A root rotation the user authored is still pushed as before. A fresh-seed JVM structure run found this. The shrunk program fails I9 before the fix and passes unchanged after it, with the main unturned and the copy at its original 45 degrees. Goldens are unchanged. Full suites ran once on the tree with this fix and the related fixes that follow it. Common passes lint, JVM, JavaScript and formatting: JVM 2059 tests / 33770 assertions; JavaScript 1995 / 32377. All six component properties pass 40 programs each at seed 712 in both runtimes. Full rebuilt frontend passes 1798 / 15737. Backend passes 1838 / 9293; exporter passes 16 / 40; consumer lint and formatting pass. 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.876 0.49 Main into 100 copies 15.415 8.403 0.55 Main into 1000 copies 153.086 85.661 0.56 Three nesting levels 35.215 17.327 0.49 Dependency chain 68.931 37.617 0.55 Library update 83.083 46.058 0.55 Many plain shapes 4.837 2.174 0.45 Variant switch 32.052 20.413 0.64 AI-assisted-by: claude-opus-5-5 --- common/src/app/common/logic/libraries.cljc | 18 ++++++++++++++---- .../logic/composable_gen_test.cljc | 12 ++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index 91074ceeef..1bdd0057c0 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -671,14 +671,20 @@ (generate-rename-component (:component-id shape-inst) (:name shape-inst) library))] (if component - (let [synced-ids (volatile! #{})] + (let [synced-ids (volatile! #{}) + root-main (ctf/get-component-root library component)] (-> (update-main-recursive changes {:container container :main-container (ctf/get-component-container library component) :component component :libraries libraries :root-inst shape-inst - :root-main (ctf/get-component-root library component) + :root-main root-main + ;; An orientation the copy root inherits from its + ;; parent places it; it is not pushed into the main. + :inherited-turn (when-not (ctk/touched-group? shape-inst :geometry-group) + (orient-like shape-inst root-main + (grc/rect->center (:selrect shape-inst)))) :remote-synced (when-not (:component-root shape-inst) true) :synced-ids synced-ids} shape-inst @@ -704,9 +710,13 @@ "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]} shape-inst shape-main] + [changes {:keys [container main-container root-inst root-main remote-synced inherited-turn]} shape-inst shape-main] (cond-> (-> changes - (update-attrs shape-main shape-inst root-main root-inst main-container false) + (update-attrs shape-main + (cond-> shape-inst (some? inherited-turn) inherited-turn) + root-main + (cond-> root-inst (some? inherited-turn) inherited-turn) + main-container false) ;; the copy keeps its swap, and the main takes the copy's overrides (set-touched shape-inst container (when (ctk/swapped? shape-inst) #{:swap-group})) ;; A previous update is not a reset of the main's authored diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 24280ef9c6..1c35405c4d 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -5,6 +5,7 @@ [app.common.geom.shapes :as gsh] [app.common.logic.shapes :as cls] [app.common.logic.variants :as clv] + [app.common.math :as mth] [app.common.schema.test :as smt] [app.common.test-helpers.composable.comp.files :as cf] [app.common.test-helpers.composable.comp.nodes :as n] @@ -671,6 +672,17 @@ :ops [[:rotate 0 0 0 0] [:edit 0 0 1 1] [:update-main 0] [:delete 0] [:restore 0] [:nest 0 0 0 0] [:swap 0 0 0 0] [:switch 0 0 0 0]]})))) +(t/deftest updating-a-main-from-a-copy-turned-by-its-parent-keeps-the-main-unturned + (let [program {:world [2 2 {:text true :text-styles true :layout nil}] + :ops [[:rotate 6 0 0 0] [:nest 13 0 0 0] [:transform 0 0 0 13] + [:update-main 3 0 0 0] [:update-main 0 0 0 0]]} + situation (:situation (cg/run program)) + rotation #(-> (tm/shape-by-id situation (thi/id %)) :rotation (or 0) (mod 360))] + ;; The nested copy inherits 45 degrees from its updated parent; its main + ;; stays unturned and the copy keeps the turn it had. + (t/is (mth/close? 0 (rotation :sync-random-0-outer-0) 0.01)) + (t/is (mth/close? 45 (rotation :sync-random-0-innercopy-1) 0.01)))) + (t/deftest detached-swapped-head-follows-its-own-component-without-position-overrides (t/is (map? (cg/run {:world [2 1 {:library true :variants true}] :ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync]