From d933e91c6c2508c2f164150ca34f022526cbd188 Mon Sep 17 00:00:00 2001 From: Pablo Alba Date: Thu, 16 Oct 2025 10:28:52 +0200 Subject: [PATCH] :bug: Fix variants not syncronizing tokens on switch --- CHANGES.md | 1 + common/src/app/common/logic/libraries.cljc | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 633dbddf48..3747731ea8 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -14,6 +14,7 @@ - Fix pan cursor not disabling viewport guides [Github #6985](https://github.com/penpot/penpot/issues/6985) - Fix viewport resize on locked shapes [Taiga #11974](https://tree.taiga.io/project/penpot/issue/11974) +- Fix variants not syncronizing tokens on switch [Taiga #12290](https://tree.taiga.io/project/penpot/issue/12290) ## 2.11.0 (Unreleased) diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index 007927188d..757d92d1d4 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -1642,7 +1642,8 @@ (pcb/apply-changes-local))))) (defn- generate-update-tokens - [changes container dest-shape origin-shape touched omit-touched?] + [changes container dest-shape origin-shape touched omit-touched? valid-attrs] + ;; valid-attrs is a set of attrs to consider on the update. If it is nil, it will consider all the attrs (let [attrs (->> (seq (keys ctk/sync-attrs)) ;; We don't update the flex-child attrs (remove #(= :layout-grid-cells %))) @@ -1650,8 +1651,8 @@ applied-tokens (reduce (fn [applied-tokens attr] (let [attr-group (get ctk/sync-attrs attr) token-attrs (cto/shape-attr->token-attrs attr)] - (if (not (and (touched attr-group) - omit-touched?)) + (if (and (or (not omit-touched?) (not (touched attr-group))) + (or (empty? valid-attrs) (contains? valid-attrs attr))) (into applied-tokens token-attrs) applied-tokens))) #{} @@ -1808,7 +1809,7 @@ :always (check-detached-main dest-shape origin-shape) :always - (generate-update-tokens container dest-shape origin-shape touched omit-touched?)) + (generate-update-tokens container dest-shape origin-shape touched omit-touched? nil)) (let [attr-group (get ctk/sync-attrs attr) ;; position-data is a special case because can be affected by @@ -2082,12 +2083,14 @@ (recur (next attrs) roperations' uoperations')) - (cond-> changes - (> (count roperations) 1) - (add-update-attr-changes current-shape container roperations uoperations) - :always - (generate-update-tokens container current-shape previous-shape touched false)))))) + (let [updated-attrs (into #{} (comp (filter #(= :set (:type %))) + (map :attr)) + roperations)] + (cond-> changes + (> (count roperations) 1) + (-> (add-update-attr-changes current-shape container roperations uoperations) + (generate-update-tokens container current-shape previous-shape touched false updated-attrs)))))))) (defn- propagate-attrs "Helper that puts the origin attributes (attrs) into dest but only if