Repository navigation
[lexical-website] Documentation Update: a $createDOM-only override does not affect HTML export - #9224
potatowagon wants to merge 1 commit into
Conversation
…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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| `$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. |
There was a problem hiding this comment.
This seems like something that could be fixed in LexicalNode.exportDOM rather than documented as a quirk
There was a problem hiding this comment.
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:
- Close this PR, fix the code, and the existing docs text becomes true as-is.
- 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.
Description
The quick-start override in
serialization/dom-render.mdsupplies only$createDOM, and the paragraph after it says the result applies "both insidethe editor and during HTML export". It does not: the render config's
$createDOMhas exactly one consumer, the reconciler. HTML export runs theseparate
$exportDOMchain, whose default calls the node class's owncreateDOM— so the example'sdata-fluidattribute never reaches exportedHTML.
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
The reconciler is the only caller, and the default
exportDOMbypasses it:After
compileDOMRenderConfigOverrides.ts:367-368compiles$createDOMand$exportDOMas distinct keys, which is why supplying one does not supply theother.