Skip to content

Bug: LexicalNode.getTopLevelElement invariant does not allow DecoratorNode children of root nodes #6319

Closed
@decademoon

Description

@decademoon

Lexical version: 0.16.0

Steps To Reproduce

In the playground, start with an empty editor and then insert a horizontal rule.

root
  ├ (49) paragraph 
  ├ (50) horizontalrule 
  └ (51) paragraph

So then it seems DecoratorNode can be a top level element (as expected), however the invariant in getTopLevelElement disallows this:

getTopLevelElement(): ElementNode | null {
let node: ElementNode | this | null = this;
while (node !== null) {
const parent: ElementNode | null = node.getParent();
if ($isRootOrShadowRoot(parent)) {
invariant(
$isElementNode(node),
'Children of root nodes must be elements',
);
return node;
}
node = parent;
}
return null;
}

In the past it seems this was allowed (#2741), did this change on purpose?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions