Repository navigation
Conversation
…typed with
## Description
`KeywordNode.createDOM` replaces the class name that `TextNode.createDOM` just set instead of adding to it:
```ts
createDOM(config: EditorConfig): HTMLElement {
const dom = super.createDOM(config);
dom.style.cursor = 'default';
dom.className = 'keyword'; // <- discards everything super applied
return dom;
}
```
`TextNode.createDOM` renders the node's text formats through `$createTextInnerDOM`, which applies `config.theme.text.*` to the element. Every format the playground theme implements as a class — underline, strikethrough, highlight, subscript, superscript, code, uppercase/lowercase/capitalize — is written onto that element and then thrown away by the assignment.
The formats really are there to render: `registerLexicalTextEntity`, which is what promotes a `TextNode` into a `KeywordNode`, explicitly carries the format over.
```ts
replacementNode.setFormat(nodeToReplace.getFormat());
```
So turning on underline and typing `congrats` gives a node whose state, toolbar and `exportDOM` all say underlined, rendered without an underline. It is not permanently broken, which is what makes it confusing: `TextNode.updateDOM` re-runs `setTextThemeClassNames` on a *format change*, so toggling the format off and back on paints it correctly, and it stays correct until something re-runs `createDOM` — pasting the keyword elsewhere, an undo/redo across it, reloading a saved document, or receiving it over collab — at which point the styling disappears again. The same document renders differently depending on how it was arrived at.
Fixed by using `addClassNamesToElement`, which is what the sibling `SpecialTextNode` in the same directory already does for the same reason. The outer `.keyword` class is unchanged, so the CSS still matches; formats are simply no longer dropped.
## Test plan
New unit test `packages/lexical-playground/__tests__/unit/KeywordNode.test.ts` renders a formatted keyword with a theme and reads the class list off the rendered element.
### Before
```
❯ packages/lexical-playground/__tests__/unit/KeywordNode.test.ts (2 tests | 2 failed)
× keeps the theme class of the text format it was created with
AssertionError: expected [ 'keyword' ] to deeply equal [ 'keyword', 'theme-underline' ]
- Expected
+ Received
Array [
"keyword",
- "theme-underline",
]
× keeps the theme class across a re-render of the keyword
AssertionError: expected [ 'keyword' ] to deeply equal [ 'keyword', 'theme-bold' ]
Test Files 1 failed (1)
Tests 2 failed (2)
```
### After
```
Test Files 1 passed (1)
Tests 2 passed (2)
```
Package suite is unchanged:
```
$ npx vitest run packages/lexical-playground
Test Files 18 passed (18)
Tests 273 passed (273)
```
LeSingh1
requested review from
acywatson,
etrepum,
fantactuka,
ivailop7,
potatowagon and
zurfyx
as code owners
August 9, 2026 05:13
|
@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.
Description
KeywordNode.createDOMreplaces the class name thatTextNode.createDOMjust set instead of adding to it:TextNode.createDOMrenders the node's text formats through$createTextInnerDOM, which appliesconfig.theme.text.*to the element. Every format the playground theme implements as a class — underline, strikethrough, highlight, subscript, superscript, code, uppercase/lowercase/capitalize — is written onto that element and then thrown away by the assignment.The formats really are there to render:
registerLexicalTextEntity, which is what promotes aTextNodeinto aKeywordNode, explicitly carries the format over.So turning on underline and typing
congratsgives a node whose state, toolbar andexportDOMall say underlined, rendered without an underline. It is not permanently broken, which is what makes it confusing:TextNode.updateDOMre-runssetTextThemeClassNameson a format change, so toggling the format off and back on paints it correctly, and it stays correct until something re-runscreateDOM— pasting the keyword elsewhere, an undo/redo across it, reloading a saved document, or receiving it over collab — at which point the styling disappears again. The same document renders differently depending on how it was arrived at.Fixed by using
addClassNamesToElement, which is what the siblingSpecialTextNodein the same directory already does for the same reason. The outer.keywordclass is unchanged, so the CSS still matches; formats are simply no longer dropped.Test plan
New unit test
packages/lexical-playground/__tests__/unit/KeywordNode.test.tsrenders a formatted keyword with a theme and reads the class list off the rendered element.Before
After
Package suite is unchanged: