fix(core): wrap root-level inline nodes in default block element during HTML deserialization (#5061) - #5075
Closed
Samarth1306w wants to merge 1 commit into
Conversation
…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
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
🦋 Changeset detectedLatest commit: 8a5556c The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
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.
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(ordeserializeHtml) parses HTML fragments consisting solely of inline content (e.g.'hello world'or'<span>text</span>'),normalizeDescendantsToDocumentFragmentreturned the fragment containing bareTextnodes 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 unhandledTypeErrorcrash.Fix Description
packages/core/src/lib/plugins/html/utils/deserializeHtml.ts: AfternormalizeDescendantsToDocumentFragmentprocesses the fragment, check if all root nodes are inline. If so, wrap them in a default paragraph block element ({ type: defaultType, children: normalized }).packages/core/src/lib/plugins/html/utils/deserializeHtmlNode.spec.tsx: Added unit test coverage verifying inline-only HTML fragments deserialize into a paragraph block..changeset/fix-html-deserialization-unwrapped-root-nodes.md: Added patch changeset for@platejs/core.Verification
deserializeHtmlreturns valid block elements at the document root level, preserving Plate's block-root document structure.@platejs/core.