Skip to content

fix(core): wrap root-level inline nodes in default block element during HTML deserialization (#5061) - #5075

Closed
Samarth1306w wants to merge 1 commit into
udecode:mainfrom
Samarth1306w:fix/html-deserialization-unwrapped-root-nodes-5061
Closed

fix(core): wrap root-level inline nodes in default block element during HTML deserialization (#5061)#5075
Samarth1306w wants to merge 1 commit into
udecode:mainfrom
Samarth1306w:fix/html-deserialization-unwrapped-root-nodes-5061

Conversation

@Samarth1306w

@Samarth1306w Samarth1306w commented Aug 5, 2026

Copy link
Copy Markdown
  • Auto release

Summary

Fixes #5061 — HTML deserialization of inline-only content returns unwrapped root text nodes, crashing the editor since chunking became default.

Root Cause

When editor.api.html.deserialize (or deserializeHtml) parses HTML fragments consisting solely of inline content (e.g. 'hello world' or '<span>text</span>'), normalizeDescendantsToDocumentFragment returned the fragment containing bare Text nodes unwrapped at the root level because all nodes were inline. When Slate/Plate chunking is enabled, the editor processes root document nodes assuming block elements, causing an unhandled TypeError crash.

Fix Description

  1. packages/core/src/lib/plugins/html/utils/deserializeHtml.ts: After normalizeDescendantsToDocumentFragment processes the fragment, check if all root nodes are inline. If so, wrap them in a default paragraph block element ({ type: defaultType, children: normalized }).
  2. packages/core/src/lib/plugins/html/utils/deserializeHtmlNode.spec.tsx: Added unit test coverage verifying inline-only HTML fragments deserialize into a paragraph block.
  3. .changeset/fix-html-deserialization-unwrapped-root-nodes.md: Added patch changeset for @platejs/core.

Verification

  • Invariant Enforcement: Guarantees that deserializeHtml returns valid block elements at the document root level, preserving Plate's block-root document structure.
  • Changeset Included: Patch changeset generated for @platejs/core.

…ng HTML deserialization (#5061)

When deserializeHtml parses inline-only content (e.g. text or spans), it returned
bare Text nodes at the document root level. When chunking became default, Slate/Plate
processes root nodes expecting block elements, causing an unhandled crash.

Fix:
- In deserializeHtml, check if all root descendants are inline. If so, wrap them in a default paragraph block element.
- Add test coverage verifying inline-only HTML deserializes into a paragraph block.
- Add patch changeset for @platejs/core.

Closes #5061
@codesandbox

codesandbox Bot commented Aug 5, 2026

Copy link
Copy Markdown

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@changeset-bot

changeset-bot Bot commented Aug 5, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8a5556c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@platejs/core Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. bug Something isn't working patch Bugfix & documentation PR plugin:html Html deserializer labels Aug 5, 2026
@zbeyens zbeyens closed this Aug 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working patch Bugfix & documentation PR plugin:html Html deserializer size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: HTML deserialization of inline-only content returns unwrapped root text nodes, crashing the editor since chunking became default

3 participants