Repository navigation
[lexical-playground] Bug Fix: Prevent crash importing <details> with loose body content - #8442
Merged
Merged
Conversation
…loose body content The playground's <details> importer ($convertDetailsElement) returned a bare CollapsibleContainerNode. Because that node is a shadow root, lexical-html's traversal could leave loose text or non-summary elements as direct children, producing a malformed tree that crashed downstream rendering with "Only element or decorator nodes can be inserted in to the root node". Add an `after` callback that reshapes the imported children into the canonical [CollapsibleTitleNode, CollapsibleContentNode] structure. Loose inline siblings inside the content are wrapped in a ParagraphNode since CollapsibleContentNode is also a shadow root. Round-trip imports of lexical-exported markup produce the same tree. Closes meta#8407.
markselby9
requested review from
acywatson,
etrepum,
fantactuka,
ivailop7,
potatowagon,
takuyakanbr and
zurfyx
as code owners
May 1, 2026 12:16
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Address review feedback on meta#8442: - Test 1: assert exact child count (toBe(2) instead of >= 2). - Test 4 (no <summary>): assert the post-transform shape — the empty CollapsibleTitleNode created for missing summary is removed by CollapsibleTitleNode's $transform, leaving only the CollapsibleContentNode under the container.
etrepum
reviewed
May 1, 2026
Comment on lines
+52
to
+55
| expect(container).toBeDefined(); | ||
| const children = ( | ||
| container as CollapsibleContainerNode | ||
| ).getChildren(); |
Collaborator
There was a problem hiding this comment.
Suggested change
| expect(container).toBeDefined(); | |
| const children = ( | |
| container as CollapsibleContainerNode | |
| ).getChildren(); | |
| assert(container != null, 'CollapsibleContainerNode must be a child of RootNode'); | |
| const children = container.getChildren(); |
Comment on lines
+57
to
+58
| expect($isCollapsibleTitleNode(children[0])).toBe(true); | ||
| expect($isCollapsibleContentNode(children[1])).toBe(true); |
Collaborator
There was a problem hiding this comment.
Suggested change
| expect($isCollapsibleTitleNode(children[0])).toBe(true); | |
| expect($isCollapsibleContentNode(children[1])).toBe(true); | |
| assert($isCollapsibleTitleNode(children[0]), 'First child must be CollapsibleTitleNode'); | |
| assert($isCollapsibleContentNode(children[1]), 'Second child must be CollapsibleContentNode'); |
| const root = $getRoot(); | ||
| const container = root | ||
| .getChildren() | ||
| .find($isCollapsibleContainerNode) as CollapsibleContainerNode; |
Collaborator
There was a problem hiding this comment.
Suggested change
| .find($isCollapsibleContainerNode) as CollapsibleContainerNode; | |
| .find($isCollapsibleContainerNode)!; |
| const root = $getRoot(); | ||
| const container = root | ||
| .getChildren() | ||
| .find($isCollapsibleContainerNode) as CollapsibleContainerNode; |
Collaborator
There was a problem hiding this comment.
Suggested change
| .find($isCollapsibleContainerNode) as CollapsibleContainerNode; | |
| .find($isCollapsibleContainerNode)!; |
Comment on lines
+67
to
+68
| // Lexical-exported markup wraps the body in a CollapsibleContentNode; | ||
| // unwrap so we can rebuild a single canonical content node. |
Collaborator
There was a problem hiding this comment.
We should just re-use this when present, rather than creating more nodes to garbage collect
- Reuse the existing CollapsibleContentNode from lexical-exported round-trip markup instead of creating a new one and discarding the imported node. - Replace `as Type` test casts with vitest `assert(...)` and non-null assertions for cleaner narrowing.
etrepum
approved these changes
May 1, 2026
Merged
This branch was successfully deployed
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
Closes #8407.
The playground's
<details>importer ($convertDetailsElement) returned a bareCollapsibleContainerNode. Because that node is a shadow root, lexical-html's traversal could leave loose text or non-summary elements as direct children, producing a malformed tree that crashed downstream rendering withOnly element or decorator nodes can be inserted in to the root node.The fix adds an
aftercallback that reshapes the imported children into the canonical[CollapsibleTitleNode, CollapsibleContentNode]structure. Loose inline siblings inside the content are wrapped in aParagraphNodesinceCollapsibleContentNodeis also a shadow root. Round-trip imports of lexical-exported markup produce the same tree.Scope is strictly the playground's
CollapsibleExtension, per the maintainer's triage on the issue.Test plan
packages/lexical-playground/__tests__/unit/CollapsibleContainerNode.test.tscovers: loose text body,openattribute preservation, summary-after-content ordering, no-summary input, multi-paragraph body, round-trip shape.pnpm run prettier/pnpm run tsc/pnpm run lintall clean.Before
Pasting the issue's HTML and switching back to wysiwyg crashed the editor with
Only element or decorator nodes can be inserted in to the root node.After
Imports as a working Details widget with the canonical structure:
```
root
└ collapsible-container
├ collapsible-title
│ └ text "Details"
└ collapsible-content
└ paragraph
└ text "Something small enough to escape casual notice."
```
No console errors; expanding the disclosure shows the body content.