lexical icon indicating copy to clipboard operation
lexical copied to clipboard

Docs: Clarify createDOM() comment about "nested elements" constraint

Open bbertold opened this issue 11 months ago • 2 comments

Description

The JSDoc comment on LexicalNode.createDOM() currently states:

"This method must return exactly one HTMLElement. Nested elements are not supported."

To me, this wording is somewhat confusing, as it could be interpreted to mean that nested DOM structures are entirely disallowed. However, based on examples such as TextNode.createDOM() (around lines 487–508), nested DOM elements do appear to be used legitimately:

if (outerTag !== null) {
  innerDOM = document.createElement(innerTag);
  dom.appendChild(innerDOM);
}
return dom;

There also seem to be existing tests that cover this behavior.

Impact

It appears that the “nested elements are not supported” note is intended to discourage returning multiple root nodes, rather than prohibit having a single root element that contains child elements.

bbertold avatar Dec 21 '25 09:12 bbertold

The jsdoc accurately describes the supported public API. There are a few cases where lexical bends these rules internally (TextNode and TableNode for example), but it’s not currently supported for other code to do this. In some cases it would happen to work, in others it wouldn’t.

etrepum avatar Dec 21 '25 14:12 etrepum

Okay understood, I am going to make a feature request for now!

bbertold avatar Dec 21 '25 18:12 bbertold