Skip to content

[lexical-playground] Bug Fix: custom nodes keep the theme classes createDOM applied - #9049

Merged
etrepum merged 6 commits into
meta:mainfrom
LeSingh1:consolidate/playground-theme-classes
Aug 29, 2026
Merged

etrepum merged 6 commits into
meta:mainfrom
LeSingh1:consolidate/playground-theme-classes

Conversation

@LeSingh1

Copy link
Copy Markdown
Contributor

Description

KeywordNode, EmojiNode and MentionNode each call super.createDOM(config),
which applies the configured theme's text-format classes, and then overwrite
className on the element they were given. The format classes are lost, so text
that is bold, italic or underlined inside one of these nodes renders unstyled
while the editor state still says it is formatted.

  • KeywordNode.createDOM assigns dom.className = 'keyword'.
  • MentionNode.createDOM assigns dom.className = 'mention'.
  • EmojiNode.createDOM overwrites the inner element's classes, and its
    updateDOM also discards super.updateDOM's true return, so a format
    change on an emoji never triggers a re-render.

Each now adds its own class rather than replacing what super applied, and
EmojiNode.updateDOM propagates super's return value.

Test plan

One unit test per node, each asserting the theme format class survives
createDOM, plus a case covering the updateDOM return for EmojiNode.

Before

$ npx vitest run packages/lexical-playground/__tests__/unit/KeywordNode.test.ts \
    packages/lexical-playground/__tests__/unit/EmojiNode.test.ts \
    packages/lexical-playground/__tests__/unit/MentionNodeTheme.test.ts
 × a keyword keeps the text format classes
 × an emoji keeps the text format classes
 × updateDOM reports that the emoji needs re-rendering
 × a mention keeps the text format classes

After

 Test Files  3 passed (3)
      Tests  6 passed (6)

$ npx tsc --noEmit -p .
(clean)

Supersedes #9008, #9009 and #9035, consolidated per the review feedback on
#9027 and #9035.

…ateDOM applied

## Description

`KeywordNode`, `EmojiNode` and `MentionNode` each call `super.createDOM(config)`,
which applies the configured theme's text-format classes, and then overwrite
`className` on the element they were given. The format classes are lost, so text
that is bold, italic or underlined inside one of these nodes renders unstyled
while the editor state still says it is formatted.

- `KeywordNode.createDOM` assigns `dom.className = 'keyword'`.
- `MentionNode.createDOM` assigns `dom.className = 'mention'`.
- `EmojiNode.createDOM` overwrites the inner element's classes, and its
  `updateDOM` also discards `super.updateDOM`'s `true` return, so a format
  change on an emoji never triggers a re-render.

Each now adds its own class rather than replacing what `super` applied, and
`EmojiNode.updateDOM` propagates `super`'s return value.

## Test plan

One unit test per node, each asserting the theme format class survives
`createDOM`, plus a case covering the `updateDOM` return for `EmojiNode`.

### Before

```
$ npx vitest run packages/lexical-playground/__tests__/unit/KeywordNode.test.ts \
    packages/lexical-playground/__tests__/unit/EmojiNode.test.ts \
    packages/lexical-playground/__tests__/unit/MentionNodeTheme.test.ts
 × a keyword keeps the text format classes
 × an emoji keeps the text format classes
 × updateDOM reports that the emoji needs re-rendering
 × a mention keeps the text format classes
```

### After

```
 Test Files  3 passed (3)
      Tests  6 passed (6)

$ npx tsc --noEmit -p .
(clean)
```

Supersedes meta#9008, meta#9009 and meta#9035, consolidated per the review feedback on
meta#9027 and meta#9035.
@vercel

vercel Bot commented Aug 10, 2026

Copy link
Copy Markdown

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

@vercel

vercel Bot commented Aug 16, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview Aug 28, 2026 8:41pm
lexical-playground Ready Ready Preview Aug 28, 2026 8:41pm

Request Review

@etrepum etrepum left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementation looks fine, but the tests should be cleaned up

@@ -0,0 +1,81 @@
/**

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test should use buildEditorFromExtensions, not the old initializeUnitTest

@@ -0,0 +1,76 @@
/**

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test should use buildEditorFromExtensions, not the old initializeUnitTest

theme: {text: {underline: 'theme-underline'}},
});

function makeEditor(): [LexicalEditor & Disposable, HTMLElement] {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this, can just return LexicalEditorWithDispose and use editor.getRootElement in the caller

@etrepum

etrepum commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

A lint rule changed since this PR was opened so you'll need to apply pnpm run lint:fix to this (and probably your other PRs) in order to pass integrity checks

@etrepum
etrepum added this pull request to the merge queue Aug 29, 2026
Merged via the queue into meta:main with commit cef3704 Aug 29, 2026
44 checks passed
@etrepum etrepum mentioned this pull request Aug 31, 2026

This branch was successfully deployed

2 active deployments
Preview – lexical — a4e2ba91 Deployed Aug 28, 2026 by vercel[bot]
Preview – lexical-playground — a4e2ba91 Deployed Aug 28, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. extended-tests Run extended e2e tests on a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants