From ce5c425251471a798b19ff662a5da37acbea083d Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Sun, 8 Nov 2026 20:19:40 +0100 Subject: [PATCH] :bug: Drop a switched typography by the text overrides a switch carries A copy text marked as owning its typography, though neither it nor its main applies one, kept its size over a switch to a variant whose text applies a typography. The size drops that typography, but the switch asked whether the copy's styles drop it of the copy's whole touched set, which holds the typography mark, and so marked the dropped reference as a typography override. The switch now asks of the text overrides it carries. Benchmark (scripts/bench-components, ms, lower 2.5% quantile): | :world | :baseline | :now | :mean | :ratio | |------------------------------------+-----------+--------+--------+--------| | deepest-edit-through-three-levels | 35.215 | 19.698 | 20.154 | 0.56 | | edit-through-a-chain-of-dependents | 68.931 | 37.739 | 39.432 | 0.55 | | library-update-into-copies | 83.083 | 45.988 | 48.369 | 0.55 | | main-edit-among-many-shapes | 4.837 | 1.93 | 2.101 | 0.4 | | main-edit-into-10-copies | 1.79 | 0.971 | 0.987 | 0.54 | | main-edit-into-100-copies | 15.415 | 9.163 | 9.653 | 0.59 | | main-edit-into-1000-copies | 153.086 | 91.955 | 96.317 | 0.6 | | variant-switch-into-copies | 32.052 | 20.339 | 23.274 | 0.63 | AI-assisted-by: claude-opus-5-5 --- common/src/app/common/logic/swap.cljc | 12 +++++++---- .../logic/composable_gen_test.cljc | 12 +++++++++++ .../logic/text_override_switch_test.cljc | 21 +++++++++++++++++++ 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/common/src/app/common/logic/swap.cljc b/common/src/app/common/logic/swap.cljc index 01a758f133..e1ca9731ad 100644 --- a/common/src/app/common/logic/swap.cljc +++ b/common/src/app/common/logic/swap.cljc @@ -329,10 +329,14 @@ updated-attrs) new-content (some #(when (= (:attr %) :content) (:val %)) roperations) text-groups (when (and (cfh/text-shape? current-shape) (some? new-content)) - (cond-> (txt/override-groups (:content current-shape) new-content) - ;; the copy's own styles drop a typography it does not apply - (txt/drops-typography? (txt/text-overrides touched)) - (disj :text-content-typography))) + (let [;; the text overrides the switch carries: those both variants agree on + carried (set/difference (txt/text-overrides touched) + (txt/override-groups (:content origin-ref-shape) + (:content current-shape)))] + (cond-> (txt/override-groups (:content current-shape) new-content) + ;; the copy's own styles drop a typography it does not apply + (txt/drops-typography? carried) + (disj :text-content-typography)))) new-touched (set/union (or (:touched current-shape) #{}) updated-sync-groups text-groups diff --git a/common/test/common_tests/logic/composable_gen_test.cljc b/common/test/common_tests/logic/composable_gen_test.cljc index ed4687d6f9..ab4b12f498 100644 --- a/common/test/common_tests/logic/composable_gen_test.cljc +++ b/common/test/common_tests/logic/composable_gen_test.cljc @@ -1906,6 +1906,18 @@ [:library-text-style 0 8 1] [:delete 0 0 0 0] [:library-edit 0 0 0] [:edit 0 1 1 2] [:library-sync] [:text-style 14 8 0 0]]})))) +(t/deftest switching-a-copy-text-marked-with-an-unapplied-typography-holds-none + (t/is (map? (cg/run {:world [2 1 {:variants true :text-styles true :library-variants true + :stale-libraries true :layout nil :layout-item-margins false + :grid-square false :library-depth 1 :library true + :rich-variants true :layout-children false :library-text true + :grid-empty false :layout-copies true :text true}] + :ops [[:library-add-variant 0] [:library-sync] [:switch 3] [:library-text-style 11 8 1] + [:library-make-variant 20 0 0 0] [:nest 0 0 0 0] [:library-make-variant 0] + [:library-sync] [:switch 0] [:nest 12 0 0 0] [:text 12 15 1] [:nest 4 0 0 0] + [:library-text-style 19 0 1] [:library-delete 0 0 0 0] + [:library-variant-property 0 0 0 0] [:library-sync] [:switch 19]]})))) + (t/deftest random-library-compositions (let [coverage (atom {}) failure (atom nil)] diff --git a/common/test/common_tests/logic/text_override_switch_test.cljc b/common/test/common_tests/logic/text_override_switch_test.cljc index 5950077914..1598a5891b 100644 --- a/common/test/common_tests/logic/text_override_switch_test.cljc +++ b/common/test/common_tests/logic/text_override_switch_test.cljc @@ -149,3 +149,24 @@ copy-t (ths/get-shape-by-id file (first (:shapes (ths/get-shape file :copy-2))))] (t/is (not-any? :typography-ref-id (tree-seq map? :children (:content copy-t)))) (t/is (= #{:content-group :text-content-size} (:touched copy-t))))) + +(t/deftest copy-owning-no-typography-holds-none-of-the-new-variant + ;; the copy is marked as owning its typography, though neither it nor its + ;; main applies one; the variants disagree on the typography, so only the + ;; size carries and drops the typography the new variant applies + (let [large [[["Add to cart" {:size 24}]]] + heading (thtx/apply-typography small :heading {:size 24 :weight 700}) + file (-> (thf/sample-file :file1) + (ths/add-sample-typography :heading) + (thv/add-variant-with-text :v01 :c01 :m01 :c02 :m02 :t01 :t02 "" "" + :text1-params {:content (thtx/content large)} + :text2-params {:content (thtx/content heading)}) + (thc/instantiate-component :c01 :copy :children-labels [:copy-t]) + (thtx/set-text :copy-t (thtx/restyle large :size 18)) + (ths/update-shape :copy-t :touched #{:content-group :text-content-size + :text-content-typography}) + (tho/swap-component-in-shape :copy :c02 {:new-shape-label :copy-2 + :keep-touched? true})) + copy-t (ths/get-shape-by-id file (first (:shapes (ths/get-shape file :copy-2))))] + (t/is (not-any? :typography-ref-id (tree-seq map? :children (:content copy-t)))) + (t/is (= #{:content-group :text-content-size} (:touched copy-t)))))