Repository navigation
[lexical-playground] Bug Fix: custom nodes keep the theme classes createDOM applied - #9049
Conversation
…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.
|
@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. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
left a comment
There was a problem hiding this comment.
Implementation looks fine, but the tests should be cleaned up
| @@ -0,0 +1,81 @@ | |||
| /** | |||
There was a problem hiding this comment.
This test should use buildEditorFromExtensions, not the old initializeUnitTest
| @@ -0,0 +1,76 @@ | |||
| /** | |||
There was a problem hiding this comment.
This test should use buildEditorFromExtensions, not the old initializeUnitTest
| theme: {text: {underline: 'theme-underline'}}, | ||
| }); | ||
|
|
||
| function makeEditor(): [LexicalEditor & Disposable, HTMLElement] { |
There was a problem hiding this comment.
No need for this, can just return LexicalEditorWithDispose and use editor.getRootElement in the caller
7003362 to
cfd6c42
Compare
|
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 |
Description
KeywordNode,EmojiNodeandMentionNodeeach callsuper.createDOM(config),which applies the configured theme's text-format classes, and then overwrite
classNameon the element they were given. The format classes are lost, so textthat is bold, italic or underlined inside one of these nodes renders unstyled
while the editor state still says it is formatted.
KeywordNode.createDOMassignsdom.className = 'keyword'.MentionNode.createDOMassignsdom.className = 'mention'.EmojiNode.createDOMoverwrites the inner element's classes, and itsupdateDOMalso discardssuper.updateDOM'struereturn, so a formatchange on an emoji never triggers a re-render.
Each now adds its own class rather than replacing what
superapplied, andEmojiNode.updateDOMpropagatessuper's return value.Test plan
One unit test per node, each asserting the theme format class survives
createDOM, plus a case covering theupdateDOMreturn forEmojiNode.Before
After
Supersedes #9008, #9009 and #9035, consolidated per the review feedback on
#9027 and #9035.