🐛 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.
This commit is contained in:
Andrey Antukh 2026-04-13 17:50:55 +00:00 committed by Eva Marco
parent b802859a53
commit 362f64ff9b
3 changed files with 14 additions and 9 deletions

View File

@ -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

View File

@ -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)))))

View File

@ -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))