Repository navigation
[lexical-text][lexical-mark][lexical-link][lexical-playground] Bug Fix: inline node transforms keep the node and its DOM in step - #9060
Merged
Conversation
…x: inline node transforms keep the node and its DOM in step ## Description Ten fixes for one defect class: an inline or custom node and the DOM/HTML it renders drift apart because the code that rewrites the node only re-applies *some* of what built it. A text-entity transform rebuilds a `TextNode` and drops properties the original carried, or misses a match that ends the node; an `updateDOM` returns `false` — promising the reconciler every difference is already in the DOM — while writing to a different element than `createDOM` did, or to none at all; a class or attribute is refreshed on only some of the transitions that should refresh it; an export path loses formats or throws on non-Latin-1 text. Same shape as meta#9049 (nodes overwriting what `super.createDOM` applied), so they are consolidated into one review. - `$replaceWithSimpleText` in `packages/lexical-text/src/registerLexicalTextEntity.ts` carried only `format` onto the replacement node, so an entity reverting to plain text silently lost its `style` and `detail`. - `$textNodeTransform` in the same file re-ran `getMatch` over the *whole* combined text of the node and its sibling and then required `nextMatch.start === 0`. Matches already replaced or skipped are part of that text, so a match that ends the node without starting it — typically the last of several in one node — was never replaced. It now compares against the text still to be processed and against the current match's own `start` (meta#5466). - `MarkNode.updateDOM` (`packages/lexical-mark/src/MarkNode.ts`) enumerated id-count transitions instead of re-applying the `ids.length > 1` rule `createDOM` states, so `1 -> 3` never gained `theme.markOverlap` and `2 -> 0` never lost it. It now derives the overlap state from the same rule. - `handleLinkEdit` (`packages/lexical-link/src/LexicalAutoLinkExtension.ts`) refreshed `rel` and `target` from the new match but never `title`, the third member of `LinkAttributes` that the creation path already applies. It also reported those attribute refreshes through `onChange`, which is documented as receiving `(url, prevUrl)`; attribute refreshes no longer fire it, while creation, removal and real url changes still do. - `TOGGLE_LINK_COMMAND`'s object-payload branch in `packages/lexical-link/src/LexicalLinkExtension.ts` never called `validateUrl`, so a configured policy applied to `dispatchCommand(TOGGLE_LINK_COMMAND, url)` and was skipped for `dispatchCommand(TOGGLE_LINK_COMMAND, {url, target})`. The same gate now covers both shapes. - `MentionNode.exportDOM` (`packages/lexical-playground/src/nodes/MentionNode.ts`) built a bare `<span data-lexical-mention>` from `this.__text`, dropping the node's inline style and text formats from the exported HTML. It now carries the style and wraps the span in the same `<b>/<i>/<s>/<u>` elements `TextNode.exportDOM` uses; the mention stays a `<span>` so the `span[data-lexical-mention]` import rule still matches (meta#6453). - `SpecialTextNode.updateDOM` (`packages/lexical-playground/src/nodes/SpecialTextNode.tsx`) returned `false` but only wrote `dom.textContent` behind a `prevNode.__text.startsWith('[')` guard that cannot hold — the node is built from the regex capture group, with the brackets already stripped — so the chip kept the text it was created with forever. It now writes the text the way `createDOM` does, when it changed. - `EquationNode.exportDOM` (`packages/lexical-playground/src/nodes/EquationNode.tsx`) base64-encoded free-form LaTeX with `btoa`, which throws `InvalidCharacterError` on any code point above U+00FF, so copying or exporting `\text{α}` failed outright; the importer's `atob` had the mirror-image limit. Both sides now go through the UTF-8 bytes with shared `encodeEquation`/`decodeEquation` helpers, the same approach `utils/docSerialization.ts` already uses. Pure ASCII encodes byte for byte, so previously exported HTML still decodes. - `RubyNode.updateDOM` (`packages/lexical-playground/src/plugins/RubyExtension/RubyNode.ts`) handed `super.updateDOM` the wrapper element, while `createDOM` puts the text theme classes and the node's inline style on the *inner* element. The two disagreed about which element carries the formatting, so restyling a ruby annotation did nothing (the inner element's own `color` still won) and underline/strikethrough landed on a wrapper whose only child is an inline-block. It now resolves the inner element and passes it to super, and returns `true` when the inner is missing so the reconciler rebuilds instead. - `$canShowPlaceholder` (`packages/lexical-text/src/canShowPlaceholder.ts`) indexed its innermost loop with the *outer* loop's `i` instead of `s`. `i` is always `0` there, so the scan tested `topBlockChildren[0]` N times and never looked past index 0 — the one thing it exists to do. A paragraph of `[TextNode(""), <inline DecoratorNode>]` reported that the placeholder may be shown, rendering it on top of real content. ## Test plan Seven new unit test files and three extended ones, covering every fix: `registerLexicalTextEntity.test.ts`, `Issue5466Repro.test.ts` and `canShowPlaceholder.test.ts` in `packages/lexical-text`; `LexicalMarkNode.test.ts` in `packages/lexical-mark`; `LexicalAutoLinkExtension.test.ts` and `LinkExtensionValidateUrl.test.ts` in `packages/lexical-link`; and `MentionHTML.test.ts`, `SpecialTextNode.test.ts`, `EquationNodeHTML.test.ts` and `RubyNode.test.ts` in `packages/lexical-playground`. Several cases are deliberate controls that pass before and after — the `createDOM` reference the `updateDOM` cases are held to, the legacy ASCII equation that must still decode, and the string-payload `validateUrl` case that pins the asymmetry with the object payload. ### Before Source fixes reverted, new tests kept: ``` $ npx vitest run --project unit packages/lexical-text packages/lexical-mark packages/lexical-link packages/lexical-playground × replaces a match that ends the node and does not start at offset 0 265ms × replaces the last of several matches in the same node 23ms × replaces every match when the first one starts at offset 0 53ms × exports the font-size applied to a mention (meta#6453) 258ms × exports the text formats applied to a mention (meta#6453) 90ms × updateDOM adds the overlap class when going from 1 to 3 ids 27ms × updateDOM removes the overlap class when going from 2 to 0 ids 22ms × preserves style and detail when reverting an entity to simple text 191ms × re-renders the text when it changes 98ms × renders the text verbatim when it is bracketed 5ms × applies a style change to the element createDOM styled 71ms × applies a class-only text format to the element createDOM classed 4ms × exports an equation with non Latin-1 characters without throwing 53ms × round trips an equation with non Latin-1 characters 4ms × round trips an equation outside the basic multilingual plane 1ms × rejects a URL the validator refuses, for an object payload 64ms × is false when a decorator follows an empty token text node 29ms × is false when a decorator follows an empty segmented text node 4ms × is false when the decorator is several positions along 1ms × editing the link text refreshes the title 28ms × an attribute refresh is not reported as a url change 3ms Test Files 10 failed | 27 passed (37) Tests 21 failed | 895 passed (916) ``` ### After ``` $ npx vitest run --project unit packages/lexical-text packages/lexical-mark packages/lexical-link packages/lexical-playground Test Files 37 passed (37) Tests 916 passed (916) $ npx tsc --noEmit -p . (clean) ``` Supersedes meta#8919, meta#8969, meta#8982, meta#8987, meta#8998, meta#9014, meta#9019, meta#9032, meta#9036, meta#9046, consolidated per the review feedback on meta#9027 and meta#9035.
LeSingh1
requested review from
acywatson,
etrepum,
fantactuka,
ivailop7,
potatowagon and
zurfyx
as code owners
August 10, 2026 04:27
|
@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 was referenced Aug 10, 2026
Closed
Closed
etrepum
approved these changes
Aug 10, 2026
|
The latest updates on your projects. Learn more about Vercel for GitHub. 2 Skipped Deployments
|
Merged
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
Ten fixes for one defect class: an inline or custom node and the DOM/HTML it
renders drift apart because the code that rewrites the node only re-applies
some of what built it. A text-entity transform rebuilds a
TextNodeand dropsproperties the original carried, or misses a match that ends the node; an
updateDOMreturnsfalse— promising the reconciler every difference isalready in the DOM — while writing to a different element than
createDOMdid,or to none at all; a class or attribute is refreshed on only some of the
transitions that should refresh it; an export path loses formats or throws on
non-Latin-1 text. Same shape as #9049 (nodes overwriting what
super.createDOMapplied), so they are consolidated into one review.
$replaceWithSimpleTextinpackages/lexical-text/src/registerLexicalTextEntity.tscarried only
formatonto the replacement node, so an entity reverting toplain text silently lost its
styleanddetail.$textNodeTransformin the same file re-rangetMatchover the wholecombined text of the node and its sibling and then required
nextMatch.start === 0. Matches already replaced or skipped are part of thattext, so a match that ends the node without starting it — typically the last
of several in one node — was never replaced. It now compares against the text
still to be processed and against the current match's own
start(Bug: Inconsistent behaviour fromuseLexicalTextEntitywhen there are several matches within the same node #5466).MarkNode.updateDOM(packages/lexical-mark/src/MarkNode.ts) enumeratedid-count transitions instead of re-applying the
ids.length > 1rulecreateDOMstates, so1 -> 3never gainedtheme.markOverlapand2 -> 0never lost it. It now derives the overlap state from the same rule.
handleLinkEdit(packages/lexical-link/src/LexicalAutoLinkExtension.ts)refreshed
relandtargetfrom the new match but nevertitle, the thirdmember of
LinkAttributesthat the creation path already applies. It alsoreported those attribute refreshes through
onChange, which is documented asreceiving
(url, prevUrl); attribute refreshes no longer fire it, whilecreation, removal and real url changes still do.
TOGGLE_LINK_COMMAND's object-payload branch inpackages/lexical-link/src/LexicalLinkExtension.tsnever calledvalidateUrl, so a configured policy applied todispatchCommand(TOGGLE_LINK_COMMAND, url)and was skipped fordispatchCommand(TOGGLE_LINK_COMMAND, {url, target}). The same gate nowcovers both shapes.
MentionNode.exportDOM(
packages/lexical-playground/src/nodes/MentionNode.ts) built a bare<span data-lexical-mention>fromthis.__text, dropping the node's inlinestyle and text formats from the exported HTML. It now carries the style and
wraps the span in the same
<b>/<i>/<s>/<u>elementsTextNode.exportDOMuses; the mention stays a
<span>so thespan[data-lexical-mention]importrule still matches (Bug: Mentions Format was not applied, the Font size style was not applied in html #6453).
SpecialTextNode.updateDOM(
packages/lexical-playground/src/nodes/SpecialTextNode.tsx) returnedfalsebut only wrote
dom.textContentbehind aprevNode.__text.startsWith('[')guard that cannot hold — the node is built from the regex capture group, with
the brackets already stripped — so the chip kept the text it was created with
forever. It now writes the text the way
createDOMdoes, when it changed.EquationNode.exportDOM(
packages/lexical-playground/src/nodes/EquationNode.tsx) base64-encodedfree-form LaTeX with
btoa, which throwsInvalidCharacterErroron any codepoint above U+00FF, so copying or exporting
\text{α}failed outright; theimporter's
atobhad the mirror-image limit. Both sides now go through theUTF-8 bytes with shared
encodeEquation/decodeEquationhelpers, the sameapproach
utils/docSerialization.tsalready uses. Pure ASCII encodes byte forbyte, so previously exported HTML still decodes.
RubyNode.updateDOM(
packages/lexical-playground/src/plugins/RubyExtension/RubyNode.ts) handedsuper.updateDOMthe wrapper element, whilecreateDOMputs the text themeclasses and the node's inline style on the inner element. The two disagreed
about which element carries the formatting, so restyling a ruby annotation did
nothing (the inner element's own
colorstill won) and underline/strikethroughlanded on a wrapper whose only child is an inline-block. It now resolves the
inner element and passes it to super, and returns
truewhen the inner ismissing so the reconciler rebuilds instead.
$canShowPlaceholder(packages/lexical-text/src/canShowPlaceholder.ts)indexed its innermost loop with the outer loop's
iinstead ofs.iisalways
0there, so the scan testedtopBlockChildren[0]N times and neverlooked past index 0 — the one thing it exists to do. A paragraph of
[TextNode(""), <inline DecoratorNode>]reported that the placeholder may beshown, rendering it on top of real content.
Test plan
Seven new unit test files and three extended ones, covering every fix:
registerLexicalTextEntity.test.ts,Issue5466Repro.test.tsandcanShowPlaceholder.test.tsinpackages/lexical-text;LexicalMarkNode.test.tsinpackages/lexical-mark;LexicalAutoLinkExtension.test.tsandLinkExtensionValidateUrl.test.tsinpackages/lexical-link; andMentionHTML.test.ts,SpecialTextNode.test.ts,EquationNodeHTML.test.tsandRubyNode.test.tsinpackages/lexical-playground. Several cases are deliberate controls that passbefore and after — the
createDOMreference theupdateDOMcases are held to,the legacy ASCII equation that must still decode, and the string-payload
validateUrlcase that pins the asymmetry with the object payload.Before
Source fixes reverted, new tests kept:
After
Supersedes #8919, #8969, #8982, #8987, #8998, #9014, #9019, #9032, #9036, #9046,
consolidated per the review feedback on #9027 and #9035.