Repository navigation
Conversation
… text changes
## Description
`SpecialTextNode` builds its element from the node's text and returns `false` from `updateDOM`, but never re-syncs that text:
```ts
createDOM(config: EditorConfig): HTMLElement {
const dom = $getDocument().createElement('span');
addClassNamesToElement(dom, config.theme.specialText);
dom.textContent = this.getTextContent();
return dom;
}
updateDOM(prevNode: this, dom: HTMLElement, config: EditorConfig): boolean {
if (prevNode.__text.startsWith('[') && prevNode.__text.endsWith(']')) {
const strippedText = this.__text.substring(1, this.__text.length - 1); // Strip brackets again
dom.textContent = strippedText; // Update the text content
}
addClassNamesToElement(dom, config.theme.specialText);
return false;
}
```
`false` means "I have already applied every difference between `prevNode` and `this`", so the reconciler leaves the element alone. The only write to `dom.textContent` is behind a guard that cannot hold: the node is created by `SpecialTextExtension` from the *capture group*, not the whole match —
```ts
const BRACKETED_TEXT_REGEX = /\[([^[\]]+)\]/;
...
const specialTextNode = $createSpecialTextNode(matchedText); // match[1], brackets already gone
```
— and the group excludes brackets, so `prevNode.__text` never starts with `[`. The branch is dead and the element keeps whatever text it was created with, forever.
`SpecialTextNode` does not override `canInsertTextBefore`, so typing at the start of a chip merges the character into the node. Type `[foo]` to get a `foo` chip, put the caret at its start and type `x` (the node's text becomes `xfoo`), then undo: the editor state goes back to `foo`, the chip still reads `xfoo`, and the undo looks like it did nothing. Any programmatic `setTextContent`, and any collab edit, desync the same way.
The guard is also wrong on its own terms. In the one case it *can* fire — the user typing brackets back around a chip, which the transform skips because a `SpecialTextNode` is not `isSimpleText()` — it writes `this.__text` minus its first and last character, while `createDOM` writes the whole string. The two methods disagree about who strips brackets, and `createDOM` is the one that matches how the node is actually constructed.
Fixed by dropping the dead guard and writing the text the same way `createDOM` does, only when it changed. `$setTextContent`, the helper `TextNode.updateDOM` uses, is module-private, and assigning `textContent` is exactly what this node's own `createDOM` already does. Still returns `false`; no API or serialization change.
## Test plan
New unit test `packages/lexical-playground/__tests__/unit/SpecialTextNode.test.ts`. The second case pins the bracket contradiction: a chip whose text is `[bar]` must render `[bar]`, which is what `createDOM` produces.
### Before
```
❯ packages/lexical-playground/__tests__/unit/SpecialTextNode.test.ts (2 tests | 2 failed)
× re-renders the text when it changes
AssertionError: expected 'foo' to be 'bar' // Object.is equality
× renders the text verbatim when it is bracketed
AssertionError: expected 'bar' to be '[bar]' // Object.is equality
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:20
|
@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
SpecialTextNodebuilds its element from the node's text and returnsfalsefromupdateDOM, but never re-syncs that text:falsemeans "I have already applied every difference betweenprevNodeandthis", so the reconciler leaves the element alone. The only write todom.textContentis behind a guard that cannot hold: the node is created bySpecialTextExtensionfrom the capture group, not the whole match —— and the group excludes brackets, so
prevNode.__textnever starts with[. The branch is dead and the element keeps whatever text it was created with, forever.SpecialTextNodedoes not overridecanInsertTextBefore, so typing at the start of a chip merges the character into the node. Type[foo]to get afoochip, put the caret at its start and typex(the node's text becomesxfoo), then undo: the editor state goes back tofoo, the chip still readsxfoo, and the undo looks like it did nothing. Any programmaticsetTextContent, and any collab edit, desync the same way.The guard is also wrong on its own terms. In the one case it can fire — the user typing brackets back around a chip, which the transform skips because a
SpecialTextNodeis notisSimpleText()— it writesthis.__textminus its first and last character, whilecreateDOMwrites the whole string. The two methods disagree about who strips brackets, andcreateDOMis the one that matches how the node is actually constructed.Fixed by dropping the dead guard and writing the text the same way
createDOMdoes, only when it changed.$setTextContent, the helperTextNode.updateDOMuses, is module-private, and assigningtextContentis exactly what this node's owncreateDOMalready does. Still returnsfalse; no API or serialization change.Test plan
New unit test
packages/lexical-playground/__tests__/unit/SpecialTextNode.test.ts. The second case pins the bracket contradiction: a chip whose text is[bar]must render[bar], which is whatcreateDOMproduces.Before
After
Package suite is unchanged: