Skip to content

[lexical-website] Documentation Update: a $createDOM-only override does not affect HTML export - #9224

Closed
potatowagon wants to merge 1 commit into
meta:mainfrom
potatowagon:docs-dom-render-export-split
Closed

potatowagon wants to merge 1 commit into
meta:mainfrom
potatowagon:docs-dom-render-export-split

Conversation

@potatowagon

Copy link
Copy Markdown
Contributor

Description

The quick-start override in serialization/dom-render.md supplies only
$createDOM, and the paragraph after it says the result applies "both inside
the editor and during HTML export". It does not: the render config's
$createDOM has exactly one consumer, the reconciler. HTML export runs the
separate $exportDOM chain, whose default calls the node class's own
createDOM — so the example's data-fluid attribute never reaches exported
HTML.

The tip immediately below already states the rule correctly ("When the
override is render-only or export-only, that's just a matter of which methods
you implement"); this makes the paragraph agree with it.

Test plan

Documentation-only change (markdown is excluded from prettier via
.prettierignore), so the check is that the claim matches the code paths.

Before

$ sed -n '86,89p' packages/lexical-website/docs/serialization/dom-render.md
The override above tags every rendered TextNode with
`data-fluid="true"`. It composes with whatever else
`DOMRenderExtension` is configured to do for `TextNode` — both inside
the editor and during HTML export.

$ grep -rn '\$createDOM' packages/lexical/src/LexicalReconciler.ts
712:    activeEditorDOMRenderConfig.$createDOM(node, activeEditor);

$ grep -rn 'activeEditorDOMRenderConfig.\$createDOM' packages/ --include=*.ts | wc -l
1

The reconciler is the only caller, and the default exportDOM bypasses it:

$ sed -n '1795,1798p' packages/lexical/src/LexicalNode.ts
  exportDOM(editor: LexicalEditor): DOMExportOutput {
    const element = this.createDOM(editor._config, editor);
    return {element};
  }

After

$ sed -n '86,92p' packages/lexical-website/docs/serialization/dom-render.md
The override above tags every rendered TextNode with
`data-fluid="true"` inside the editor. It composes with whatever else
`DOMRenderExtension` is configured to do for `TextNode`. Note that
`$createDOM` is the reconciler's hook only: HTML export goes through
`$exportDOM`, whose default calls the node class's own `createDOM`, so
`data-fluid` does not reach exported HTML unless the override supplies
`$exportDOM` too.

compileDOMRenderConfigOverrides.ts:367-368 compiles $createDOM and
$exportDOM as distinct keys, which is why supplying one does not supply the
other.

…es not affect HTML export

## Description

The quick-start override in `serialization/dom-render.md` supplies only
`$createDOM`, and the paragraph after it says the result applies "both inside
the editor and during HTML export". It does not: the render config's
`$createDOM` has exactly one consumer, the reconciler. HTML export runs the
separate `$exportDOM` chain, whose default calls the node class's own
`createDOM` — so the example's `data-fluid` attribute never reaches exported
HTML.

The tip immediately below already states the rule correctly ("When the
override is render-only or export-only, that's just a matter of which methods
you implement"); this makes the paragraph agree with it.

## Test plan

Documentation-only change (markdown is excluded from prettier via
`.prettierignore`), so the check is that the claim matches the code paths.

### Before

```
$ sed -n '86,89p' packages/lexical-website/docs/serialization/dom-render.md
The override above tags every rendered TextNode with
`data-fluid="true"`. It composes with whatever else
`DOMRenderExtension` is configured to do for `TextNode` — both inside
the editor and during HTML export.

$ grep -rn '\$createDOM' packages/lexical/src/LexicalReconciler.ts
712:    activeEditorDOMRenderConfig.$createDOM(node, activeEditor);

$ grep -rn 'activeEditorDOMRenderConfig.\$createDOM' packages/ --include=*.ts | wc -l
1
```

The reconciler is the only caller, and the default `exportDOM` bypasses it:

```
$ sed -n '1795,1798p' packages/lexical/src/LexicalNode.ts
  exportDOM(editor: LexicalEditor): DOMExportOutput {
    const element = this.createDOM(editor._config, editor);
    return {element};
  }
```

### After

```
$ sed -n '86,92p' packages/lexical-website/docs/serialization/dom-render.md
The override above tags every rendered TextNode with
`data-fluid="true"` inside the editor. It composes with whatever else
`DOMRenderExtension` is configured to do for `TextNode`. Note that
`$createDOM` is the reconciler's hook only: HTML export goes through
`$exportDOM`, whose default calls the node class's own `createDOM`, so
`data-fluid` does not reach exported HTML unless the override supplies
`$exportDOM` too.
```

`compileDOMRenderConfigOverrides.ts:367-368` compiles `$createDOM` and
`$exportDOM` as distinct keys, which is why supplying one does not supply the
other.
@vercel

vercel Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
lexical Ready Ready Preview Sep 24, 2026 4:48pm UTC
lexical-playground Ready Ready Preview Sep 24, 2026 4:48pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 24, 2026
Comment on lines +89 to +92
`$createDOM` is the reconciler's hook only: HTML export goes through
`$exportDOM`, whose default calls the node class's own `createDOM`, so
`data-fluid` does not reach exported HTML unless the override supplies
`$exportDOM` too.

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 seems like something that could be fixed in LexicalNode.exportDOM rather than documented as a quirk

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed — and it's worse than a quirk, because @lexical/html's own type doc already promises the behaviour you're describing: $createDOM "is also the default implementation of $exportDOM for most nodes" (packages/lexical-html/src/types.ts:288-291). So the implementation contradicts its own contract, and this PR as written just documents the contradiction.

I confirmed it with a scratch unit test on a node that does not override exportDOM, so it uses the base implementation:

RENDERED: <div data-fluid="true" dir="auto"><br data-lexical-managed-linebreak="true"></div>
EXPORTED: <div></div>

The mechanism: the compiled config's $exportDOM bottoms out in DEFAULT_EDITOR_DOM_CONFIG.$exportDOM (LexicalEditor.ts:923), which calls node.exportDOM(editor); the base LexicalNode.exportDOM then calls this.createDOM(...) — the class method (LexicalNode.ts:1795-1797). The $createDOM override chain is never consulted, even though the export path holds the same compiled config that has it.

One complication for the fix: 24 node classes override exportDOM themselves (TextNode, ParagraphNode, ListNode, CodeNode, …), and they deliberately emit different HTML than createDOM. So the routing can only apply where the class has not overridden exportDOM — detectable as klass.prototype.exportDOM === LexicalNode.prototype.exportDOM. That check most naturally lives in compileDOMRenderConfigOverrides, where a node with a $createDOM override and no $exportDOM override would get one synthesized from the compiled $createDOM.

Happy to put that up as a separate PR (core behaviour change, doesn't belong in a docs commit) — with a regression test for both the routed case and a TextNode-style class override staying untouched. Two ways to sequence it, your call:

  1. Close this PR, fix the code, and the existing docs text becomes true as-is.
  2. Land this as accurate-for-today, then revert this paragraph in the fix PR.

I'd lean 1 since the current text is only wrong in the direction the fix corrects, but 2 avoids leaving a known-wrong sentence in the docs while the fix is in review.

This branch was successfully deployed

2 active deployments
Preview – lexical — bd780cd9 Deployed Sep 24, 2026 by vercel[bot]
Preview – lexical-playground — bd780cd9 Deployed Sep 24, 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants