From c5c60e466b2363c2283d52b9f0000814773757b0 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Thu, 19 Nov 2026 10:13:59 +0100 Subject: [PATCH] :bug: Measure a text in the element its renderer mounted In the SVG renderer, a text inside a component kept drawing its old font weight after a font weight token changed: the Design panel showed the new weight, the canvas the old one, also after a reload. A changed text is measured in a hidden HTML element, looked up in the document by `#html-text-node-`. While a layout reflows, the text modifiers renderer mounts an element with the same id for the same text, ahead of the changes renderer's one. The measurement found that transient element; when a font variant had to load first, it was gone by the time the measurement ran, so the position data came out empty and was dropped, and nothing measured the text again. Texts in boards with layout, as component mains usually are, take that path; others did not. `calc-position-data` now measures the element the renderer passes, never one looked up by id. Found by the components Qase run (PENPOT-2562). Checked in the browser: cycling the font weight token of a main and its copy through weights not loaded yet (300, 700, 200, 900, 600 italic, 300) redraws both with each new weight; before, the first use of each weight kept the old one. AI-assisted-by: claude-opus-5-5 --- .../workspace/shapes/text/viewport_texts_html.cljs | 4 ++-- frontend/src/app/util/text_svg_position.cljs | 14 ++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/shapes/text/viewport_texts_html.cljs b/frontend/src/app/main/ui/workspace/shapes/text/viewport_texts_html.cljs index 04b150e62d..f0e53f4834 100644 --- a/frontend/src/app/main/ui/workspace/shapes/text/viewport_texts_html.cljs +++ b/frontend/src/app/main/ui/workspace/shapes/text/viewport_texts_html.cljs @@ -121,7 +121,7 @@ "Measure the text and commit its position-data and auto-grow size as `text-heal` decides for `phase`. Resolves to the next heal phase, if any." [{:keys [id] :as shape} node phase] - (->> (tsp/calc-position-data id) + (->> (tsp/calc-position-data node) (p/fmap (fn [position-data] (let [;; A page-open check never writes a size laid out ;; with a fallback font @@ -151,7 +151,7 @@ (defn- update-text-modifier [{:keys [grow-type id] :as shape} node] - (->> (tsp/calc-position-data id) + (->> (tsp/calc-position-data node) (p/fmap (fn [position-data] (let [props {:position-data position-data}] (if (contains? #{:auto-height :auto-width} grow-type) diff --git a/frontend/src/app/util/text_svg_position.cljs b/frontend/src/app/util/text_svg_position.cljs index 05ad576f1a..62620e99ab 100644 --- a/frontend/src/app/util/text_svg_position.cljs +++ b/frontend/src/app/util/text_svg_position.cljs @@ -82,9 +82,8 @@ (seq (.-childNodes parent-node))))) (defn- calc-text-node-positions - [shape-id] - (let [text-nodes (-> (dom/query (dm/fmt "#html-text-node-%" shape-id)) - (dom/query-all ".text-node"))] + [root-node] + (let [text-nodes (dom/query-all root-node ".text-node")] (->> (p/all (map resolve-font text-nodes)) (p/fmap (fn [fonts] (cond-> (into [] (mapcat process-text-node) text-nodes) @@ -97,7 +96,10 @@ (true? (::font-failed (meta position-data)))) (defn calc-position-data - [shape-id] + "Measure the position data of the text rendered in `root-node`, the + `.text-node-html` element of a text shape. Several renderers can hold an + element for the same shape at once, so it is never looked up by id." + [root-node] (letfn [(get-prop [styles prop] (let [value (.getPropertyValue styles prop)] (when (and (some? value) (not= value "")) @@ -120,8 +122,8 @@ txt/default-text-fills) :text text})))] - (when (some? shape-id) - (->> (calc-text-node-positions shape-id) + (when (some? root-node) + (->> (calc-text-node-positions root-node) (p/fmap (fn [text-data] (with-meta (mapv transform-data text-data) (meta text-data))))))))