From f54d1a288e555c9b9cca22b982d0165f6b9031bf Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 27 Oct 2026 13:24:06 +0100 Subject: [PATCH] :bug: Skip numerically equal component sync writes Compare integer and floating forms exactly for scalar values, points and selection rectangles. A library update that only changes their numeric representation must not create changes or an undo entry. Preserve every nonzero difference, including real subpixel moves. Add the reduced resize/library-sync regression and a subpixel control, plus async frontend undo/redo replay. Review and update eight golden states in case N: only equal integer/float representations changed. The recreated seed-712 audit leaves all 61 syncs and undo depths unchanged. Common JVM 1,914 tests/31,146 assertions and JS 1,845/29,810 pass. Frontend 1,563/10,880, its added replay, backend 1,610/8,104 and exporter 14/32 pass. Lint and formatting pass. Exporter needs its test-only secret. Benchmark ratios against the unchanged baseline: mains 10/100/1000 0.54/0.61/0.61, levels 0.53, chain 0.55, library 0.55, many shapes 0.62, variant switch 0.65. No regression flag. AI-assisted-by: gpt-6 --- common/src/app/common/logic/libraries.cljc | 22 +++++++++++++++++-- .../common_tests/logic/comp_sync_test.cljc | 15 +++++++++++++ .../logic/composable_gen_test.cljc | 7 ++++++ .../composable_tests/generated_test.cljs | 5 +++++ 4 files changed, 47 insertions(+), 2 deletions(-) diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index d735e05131..1587ba5a6d 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -1330,6 +1330,24 @@ (or (automatic-name content) origin-name)) origin-name))) +(defn- same-sync-value? + "Compare numeric values exactly, including integer/float representations + inside geometry. Every nonzero difference still requires a sync." + [attr value other] + (or (= value other) + (let [same-number? (fn [a b] (and (number? a) (number? b) (== a b)))] + (case attr + :selrect (and (map? value) (map? other) + (= (set (keys value)) (set (keys other))) + (every? #(same-number? (get value %) (get other %)) (keys value))) + :points (and (sequential? value) (sequential? other) + (= (count value) (count other)) + (every? (fn [[a b]] + (and (same-number? (:x a) (:x b)) + (same-number? (:y a) (:y b)))) + (map vector value other))) + (same-number? value other))))) + (defn- sync-attr-operations "The `[attr value]` pairs that sync `attr` from `origin-shape`, a main shape placed like `dest-shape`, into `dest-shape`, its copy. With @@ -1370,7 +1388,7 @@ skip? (or (and (not text-name?) - (= (get origin-shape attr) (get dest-shape attr))) + (same-sync-value? attr (get origin-shape attr) (get dest-shape attr))) (and (touched sync-group) omit-touched? ;; When it is a text-partial-change, we should generate operations @@ -1399,7 +1417,7 @@ (cond ;; If the final attr-value is the actual value, skip - (or skip? (= attr-val (get dest-shape attr))) + (or skip? (same-sync-value? attr attr-val (get dest-shape attr))) [] ;; On a text-partial-change, we want to force a position-data reset diff --git a/common/test/common_tests/logic/comp_sync_test.cljc b/common/test/common_tests/logic/comp_sync_test.cljc index 20956310f7..9a32d62012 100644 --- a/common/test/common_tests/logic/comp_sync_test.cljc +++ b/common/test/common_tests/logic/comp_sync_test.cljc @@ -33,6 +33,21 @@ (t/use-fixtures :each thi/test-fixture) +(t/deftest sync-keeps-a-real-subpixel-position-change + (let [initial (setup/simple-component-with-labeled-copy) + original (tm/resolve-shape initial :copy-child) + file (tm/file initial) + page (thf/current-page file) + changes (cls/generate-update-shapes + (pcb/empty-changes nil (:id page)) [(thi/id :main-child)] + #(gsh/move % (gpt/point 0.000001 0)) (:objects page) {}) + source (thf/apply-changes file changes) + changed (tm/with-file initial (:file (r/sync-cascade source {} (keys (get-in file [:data :components]))))) + actual (tm/resolve-shape changed :copy-child) + expected (gsh/move original (gpt/point 0.000001 0))] + (t/is (not= (:points original) (:points actual))) + (t/is (gsh/close-attrs? :points (:points expected) (:points actual) 1e-10)))) + (t/deftest grid-sync-keeps-new-main-cells (let [file (-> (thf/sample-file :file1) (tho/add-grid-frame :main-root :width 100 :height 100) diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index 2744f22696..cc50e5f759 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -382,6 +382,13 @@ (t/is (= {} (get-in result [:result-text :content-group]))) (t/is (false? (shadow/same-value? (:result-text after) :text-content-size expected))))))) +(t/deftest accepting-a-library-does-not-record-equal-numeric-geometry + (let [before (-> (cg/initial-state [2 1 {:library true :variants true}]) + (cg/step [:resize 10 2 2 10]) cg/settle-state) + after (-> before (cg/step [:library-sync 3 1 2 8]) cg/settle-state)] + (t/is (= (r/undo-depth (:situation before)) (r/undo-depth (:situation after)))) + (t/is (= (oracle/snapshot (:situation before)) (oracle/snapshot (:situation after)))))) + (t/deftest source-library-edits-wait-for-explicit-consumer-acceptance (let [initial (cg/initial-state [2 1 {:library true :stale-libraries true}]) situation (:situation initial) diff --git a/frontend/test/frontend_tests/composable_tests/generated_test.cljs b/frontend/test/frontend_tests/composable_tests/generated_test.cljs index 43450d29c7..3989b12863 100644 --- a/frontend/test/frontend_tests/composable_tests/generated_test.cljs +++ b/frontend/test/frontend_tests/composable_tests/generated_test.cljs @@ -128,6 +128,11 @@ (t/is false (str (ex-message error) "\nReplay: " (pr-str program) "\nDetails: " (pr-str (ex-data error))))))) +(t/deftest ^:async accepting-a-library-does-not-record-equal-numeric-geometry + (await (replay {:world [2 1 {:library true :variants true}] + :ops [[:resize 10 2 2 10] [:library-sync 3 1 2 8] + [:undo] [:redo]]}))) + (t/deftest ^:async nesting-a-swapped-copy-in-a-blocked-main-authors-its-lock (await (replay {:world [2 0 {:library true :variants true :rich-variants true :text true :text-styles true :layout nil :layout-copies true}]