[lexical] Bug Fix: don't leave empty class/style attributes in the editor DOM - #8977
Closed
LeSingh1 wants to merge 1 commit into
Closed
[lexical] Bug Fix: don't leave empty class/style attributes in the editor DOM#8977LeSingh1 wants to merge 1 commit into
LeSingh1 wants to merge 1 commit into
Conversation
…itor DOM `classList.remove()` and `style.setProperty(prop, '')` keep the attribute in place with an empty value, so clearing the last theme class or the last inline declaration rendered `<span class="">` / `<p style="">`. Remove the attribute once it is empty in the three reconcile paths that can drop the final token: element format (text-align), element indent (padding-inline-start and the indent theme class), and TextNode format/style. The e2e expectations in ClearFormatting, Indentation and KeyboardShortcuts recorded the leftover `style=""` and are updated. DraggableBlock is left alone: its `style=""` comes from LexicalDraggableBlockPlugin writing to the DOM directly, not from the reconciler.
LeSingh1
requested review from
acywatson,
etrepum,
fantactuka,
ivailop7,
potatowagon and
zurfyx
as code owners
August 8, 2026 03:11
|
@LeSingh1 is attempting to deploy a commit to the Meta Open Source Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
classList.remove()andstyle.setProperty(prop, '')keep the attribute in place with an empty value, so clearing the last theme class or the last inline declaration renders<span class="">/<p style="">.Repro:
p.setFormat('center')thenp.setFormat('')gives<p style="">; togglingselection.formatText('underline')twice with atheme.text.underlineclass gives<span class="">.Adds an internal
removeEmptyDOMAttribute(dom, 'class' | 'style'), which drops the attribute whengetAttributereturns'', and calls it from the three reconcile paths that can drop the final token: element format (text-align), element indent (padding-inline-startplus the indent theme class), andTextNode.updateDOM(theme classes and__style). It is not exported fromindex.ts, so there is no public API or flow change.Four unit tests, all failing on
mainwith the exactstyle=""/class=""output.Three e2e files had recorded the leftover attribute and are updated —
ClearFormatting(5),Indentation(6),KeyboardShortcuts(1). Their purpose is unchanged; only the stale attribute is gone, and I confirmed in Chromium beforehand that the received HTML differed from the expectation by exactlystyle="".DraggableBlock.spec.mjskeeps its fourstyle=""assertions on purpose: that one comes fromLexicalDraggableBlockPluginwritingelement.style.transformdirectly and restoring it, not from the reconciler. Same cosmetic class, plugin-owned DOM, worth its own fix.Noting @acywatson's "we could probably change this, but I'm not sure it's a bug" from the thread — happy to close this if the answer is still that it isn't worth the churn.
Fixes #5307