From 362f64ff9bd18899cd8be5697aa1fb1d5912beb8 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 13 Apr 2026 17:50:55 +0000 Subject: [PATCH] :bug: Strip nil values at text-style merge boundaries Add d/without-nils at every point where default-font or editor styles are merged before being stored or used to build content: - v2-update-text-editor-styles and v3-update-text-editor-styles now strip nils from merged styles before writing to workspace state. - initialize-editor-state strips nils from the attrs passed to Draft.js. - v2-default-text-content strips nils from default-font before building the initial text tree for new shapes. These are defensive guards so that any residual nil in default-font (e.g. from sessions predating the save-font fix) cannot reach shape content or editor state. --- frontend/src/app/main/data/workspace/texts.cljs | 12 +++++++----- frontend/src/app/main/data/workspace/texts_v3.cljs | 8 +++++--- frontend/src/app/util/text/content.cljs | 3 ++- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/frontend/src/app/main/data/workspace/texts.cljs b/frontend/src/app/main/data/workspace/texts.cljs index 7397405eac..eae231fe72 100644 --- a/frontend/src/app/main/data/workspace/texts.cljs +++ b/frontend/src/app/main/data/workspace/texts.cljs @@ -183,8 +183,9 @@ ptk/UpdateEvent (update [_ state] (let [text-state (some->> content ted/import-content) - attrs (merge (txt/get-default-text-attrs) - (get-in state [:workspace-global :default-font])) + attrs (d/without-nils + (merge (txt/get-default-text-attrs) + (get-in state [:workspace-global :default-font]))) editor (cond-> (ted/create-editor-state text-state decorator) (and (nil? content) (some? attrs)) (ted/update-editor-current-block-data attrs))] @@ -945,9 +946,10 @@ ;; `stylechange` can fire on every `selectionchange` while typing. ;; Avoid swapping the global store when the computed styles are unchanged, ;; otherwise we can end up in store->rerender->selectionchange loops. - (let [merged-styles (merge (txt/get-default-text-attrs) - (get-in state [:workspace-global :default-font]) - new-styles) + (let [merged-styles (d/without-nils + (merge (txt/get-default-text-attrs) + (get-in state [:workspace-global :default-font]) + new-styles)) prev (get-in state [:workspace-v2-editor-state id])] (if (= merged-styles prev) state diff --git a/frontend/src/app/main/data/workspace/texts_v3.cljs b/frontend/src/app/main/data/workspace/texts_v3.cljs index 4f0834d7d2..01a36aa729 100644 --- a/frontend/src/app/main/data/workspace/texts_v3.cljs +++ b/frontend/src/app/main/data/workspace/texts_v3.cljs @@ -6,6 +6,7 @@ (ns app.main.data.workspace.texts-v3 (:require + [app.common.data :as d] [app.common.types.text :as txt] [potok.v2.core :as ptk])) @@ -14,7 +15,8 @@ (ptk/reify ::v3-update-text-editor-styles ptk/UpdateEvent (update [_ state] - (let [merged-styles (merge (txt/get-default-text-attrs) - (get-in state [:workspace-global :default-font]) - new-styles)] + (let [merged-styles (d/without-nils + (merge (txt/get-default-text-attrs) + (get-in state [:workspace-global :default-font]) + new-styles))] (update-in state [:workspace-wasm-editor-styles id] (fnil merge {}) merged-styles))))) diff --git a/frontend/src/app/util/text/content.cljs b/frontend/src/app/util/text/content.cljs index 492aa4477b..71245b8121 100644 --- a/frontend/src/app/util/text/content.cljs +++ b/frontend/src/app/util/text/content.cljs @@ -6,6 +6,7 @@ (ns app.util.text.content (:require + [app.common.data :as d] [app.common.types.text :as txt] [app.main.refs :as refs] [app.util.text.content.from-dom :as fd] @@ -26,7 +27,7 @@ current default typography. Used by the V2 editor/WASM path when a shape is created with no content yet." [] - (let [default-font (deref refs/default-font) + (let [default-font (d/without-nils (deref refs/default-font)) text-defaults (merge (txt/get-default-text-attrs) default-font) default-span (merge {:text ""} (select-keys text-defaults txt/text-node-attrs))