From 232fdd7d33901c7e84bac23b0869962e3d27de8c Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 24 Nov 2026 17:01:11 +0100 Subject: [PATCH] :bug: Settle layout waits after a text becomes fixed or is resized A text update raised the text reflow signal whenever the text was auto-sized before the update, and the wait then held the text until a WASM resize started. Nothing resizes a text that the update makes fixed, and a commit of WASM modifiers has already laid its texts out, so `waitForLayoutUpdate` timed out after `Text.resize` or a drag resize. - The signal reads the grow type after the update: only an auto-sized text waits for a WASM resize. - `apply-wasm-modifiers` marks its commit with `:text-reflow? false`. AI-assisted-by: claude-opus-5-5 --- .../app/main/data/workspace/modifiers.cljs | 3 ++ .../main/data/workspace/reflow/signals.cljs | 27 +++++++++-------- .../data/workspace_reflow_test.cljs | 29 +++++++++++++++++++ plugins/CHANGELOG.md | 1 + .../src/tests/wait-layout.test.ts | 25 ++++++++++++++++ 5 files changed, 73 insertions(+), 12 deletions(-) diff --git a/frontend/src/app/main/data/workspace/modifiers.cljs b/frontend/src/app/main/data/workspace/modifiers.cljs index 5e9442d98a..03c99bc767 100644 --- a/frontend/src/app/main/data/workspace/modifiers.cljs +++ b/frontend/src/app/main/data/workspace/modifiers.cljs @@ -934,6 +934,9 @@ (assoc :reg-objects? true) (assoc :ignore-tree ignore-tree) (assoc :translation? translation?) + ;; WASM laid the texts out while propagating, so their + ;; geometry needs no later resize. + (assoc :text-reflow? false) ;; Attributes that can change in the transform. This ;; way we don't have to check all the attributes (assoc :attrs transform-attrs)) diff --git a/frontend/src/app/main/data/workspace/reflow/signals.cljs b/frontend/src/app/main/data/workspace/reflow/signals.cljs index fe92de3ea9..7fc03870c3 100644 --- a/frontend/src/app/main/data/workspace/reflow/signals.cljs +++ b/frontend/src/app/main/data/workspace/reflow/signals.cljs @@ -69,15 +69,14 @@ changed))) (defn- async-text-reflow? - "Whether `shape` enters an asynchronous text geometry pipeline. The HTML - renderer measures every changed text; WASM only resizes auto-sized texts. - A grow-type transition is included because `shape` is the value before the - update and may still be fixed." - [state shape changed] + "Whether `shape` enters an asynchronous text geometry pipeline once updated + to `changed-shape`. The HTML renderer measures every changed text; WASM only + resizes texts that are auto-sized after the update, so a text that becomes + fixed starts no work." + [state shape changed-shape] (and (cfh/text-shape? shape) (or (not (features/active-feature? state "render-wasm/v1")) - (not= :fixed (:grow-type shape)) - (contains? changed :grow-type)))) + (not= :fixed (:grow-type (or changed-shape shape)))))) (defn- get-reflow-changes [state objects changed-objects ids {:keys [attrs] :as props}] @@ -110,7 +109,7 @@ (let [edition (dm/get-in state [:workspace-local :edition])] (->> reflow-changes (into [] (comp (filter (fn [[shape changed-shape changed]] - (and (async-text-reflow? state shape changed) + (and (async-text-reflow? state shape changed-shape) (text-reflow-changed? state shape changed-shape changed)))) (map (comp :id first)) @@ -119,23 +118,27 @@ (defn reflow-ids "Ids a shape update has to signal: `:layout-ids` for `:layout/update`, - `:text-ids` for `:text/reflow`. Both are nil when nothing changed. + `:text-ids` for `:text/reflow`. Both are nil when nothing changed. A + `:text-reflow?` false in `props` marks an update whose texts are already laid + out, so it signals no text. Both sets come from one comparison pass, so `update-fn` and the attribute diff only run once per shape." [state page-id objects changed-objects ids props] (let [reflow-changes (get-reflow-changes state objects changed-objects ids props)] {:layout-ids (get-layout-reflow-ids reflow-changes) - :text-ids (get-text-reflow-ids state page-id reflow-changes)})) + :text-ids (when-not (false? (:text-reflow? props)) + (get-text-reflow-ids state page-id reflow-changes))})) (defn text-reflow-candidate? "Whether `props` can start renderer text work, judged from the caller metadata alone. Cheap pre-filter for callers that buffer updates before they have objects to compare." [state props] - (reflow-candidate? (renderer-text-reflow-attr? state) props)) + (and (not (false? (:text-reflow? props))) + (reflow-candidate? (renderer-text-reflow-attr? state) props))) (defn new-text-reflow? "Whether a newly added `shape` enters an asynchronous text geometry pipeline." [state shape] - (async-text-reflow? state shape nil)) + (async-text-reflow? state shape shape)) diff --git a/frontend/test/frontend_tests/data/workspace_reflow_test.cljs b/frontend/test/frontend_tests/data/workspace_reflow_test.cljs index 7d3b29756d..2e4c69982a 100644 --- a/frontend/test/frontend_tests/data/workspace_reflow_test.cljs +++ b/frontend/test/frontend_tests/data/workspace_reflow_test.cljs @@ -12,6 +12,7 @@ (:require [app.common.uuid :as uuid] [app.main.data.workspace.reflow :as wrf] + [app.main.data.workspace.reflow.signals :as wrfs] [app.main.data.workspace.shape-layout :as dwsl] [app.main.data.workspace.shapes :as dwsh] [app.main.data.workspace.texts :as dwtxt] @@ -157,6 +158,34 @@ (wrf/finish! task-b) (done))))))) +(defn- text-reflow-ids + "Texts that the update of a text from `before` to `after` signals for + reflow, with the features in `features` and the update `props`." + ([features before after] + (text-reflow-ids features before after {})) + ([features before after props] + (let [page-id (uuid/next) + state {:features features :current-page-id page-id} + id (:id before)] + (:text-ids (wrfs/reflow-ids state page-id {id before} {id after} [id] props))))) + +(t/deftest wasm-text-reflow-follows-the-updated-grow-type + (let [id (uuid/next) + text {:id id :type :text :grow-type :auto-width :width 10 :content {:text "a"}} + fixed (assoc text :grow-type :fixed :width 300) + wasm #{"render-wasm/v1"}] + (t/is (nil? (text-reflow-ids wasm text fixed)) + "a text that becomes fixed starts no wasm resize") + (t/is (= [id] (text-reflow-ids wasm fixed text)) + "a text that becomes auto-sized is resized") + (t/is (= [id] (text-reflow-ids wasm text (assoc text :content {:text "b"})))) + (t/is (nil? (text-reflow-ids wasm fixed (assoc fixed :content {:text "b"})))) + (t/is (= [id] (text-reflow-ids #{} text fixed)) + "the DOM renderer measures every changed text") + (t/is (nil? (text-reflow-ids wasm text (assoc text :grow-type :auto-height) + {:text-reflow? false})) + "a modifiers commit has already laid the text out"))) + (t/deftest text-bridge-waits-for-each-shape ;; Starting measurement for one id must not release sibling bridge tasks. (t/async done diff --git a/plugins/CHANGELOG.md b/plugins/CHANGELOG.md index 7c4dec7fee..082d778b8d 100644 --- a/plugins/CHANGELOG.md +++ b/plugins/CHANGELOG.md @@ -42,6 +42,7 @@ - **plugins-runtime:** A SES `repairIntrinsics` failure at startup (for example, when a browser extension wraps the native `Temporal` global) no longer leaves the whole app blank. Plugins are skipped for that session, the error is logged, and a telemetry event reports the unavailable runtime; the editor, login and sign-up pages load as usual. Plugins work as before in every other environment. When startup fails, SES has already replaced `Function.prototype.toString` in the host realm before throwing, but no intrinsics are hardened and no sandbox is created. Closes #12924. - **plugins-runtime:** `Variants.removeProperty()` no longer leaves two variants with the same values. When several variants clash, the top one in the layers panel keeps its values and each lower one gets a numbered value (`Big (1)`, or `(1)` when all its remaining values are empty). Closes #12959. - **plugins-runtime:** `Variants.properties` and `Variants.currentValues()` keep the order of the variant properties and values when there are more than eight. They used to come back shuffled, so `removeProperty()` and `renameProperty()` could hit the wrong property when called with an index read from `properties`. Closes #13247. +- **plugins-runtime:** `waitForLayoutUpdate()` settles after a text is resized to a fixed size or its size changes through `resize()`. It used to wait for a text measurement that never came, so the promise always timed out. ## 1.6.0 (2026-11-10) diff --git a/plugins/apps/plugin-api-test-suite/src/tests/wait-layout.test.ts b/plugins/apps/plugin-api-test-suite/src/tests/wait-layout.test.ts index c2b67a4d5b..a2326a8d95 100644 --- a/plugins/apps/plugin-api-test-suite/src/tests/wait-layout.test.ts +++ b/plugins/apps/plugin-api-test-suite/src/tests/wait-layout.test.ts @@ -313,6 +313,31 @@ describe('WaitForLayoutUpdate', () => { expect(t.width).toBeGreaterThan(w0); }); + test('wait settles after resizing an auto-width text', async (ctx) => { + // `resize` makes the text fixed: no text measurement follows, so the + // wait must not hold for one. + const t = autoWidthText(ctx, 'The quick brown fox'); + await t.waitForLayoutUpdate(); + + t.resize(300, 80); + await t.waitForLayoutUpdate(5000); + await ctx.penpot.waitForLayoutUpdate(5000); + expect(t.growType).toBe('fixed'); + expect(Math.round(t.width)).toBe(300); + expect(Math.round(t.height)).toBe(80); + }); + + test('wait settles after resizing a vertical text', async (ctx) => { + const t = autoWidthText(ctx, '春眠不覺曉'); + t.lang = 'zh-Hant-TW'; + t.writingMode = 'vertical-rl'; + await t.waitForLayoutUpdate(); + + t.resize(100, 300); + await t.waitForLayoutUpdate(5000); + expect(Math.round(t.height)).toBe(300); + }); + test('shape-level wait covers the text own resize', async (ctx) => { const t = autoWidthText(ctx, 'The quick brown fox'); await t.waitForLayoutUpdate();