Skip to content

Prevent JSX kind mismatches from crashing the editor - #963

Merged
petyosi merged 1 commit into
mainfrom
petyosi/jsx-kind-mismatch-policy
Aug 27, 2026
Merged

petyosi merged 1 commit into
mainfrom
petyosi/jsx-kind-mismatch-policy

Conversation

@petyosi

@petyosi petyosi commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Why

Valid one-line MDX can parse a component as inline content even when its descriptor declares a flow component. The generic JSX editor previously used the descriptor to create a block nested editor, which placed phrasing nodes directly under a Lexical root and crashed the editor.

Fixes #962.

What changes

The JSX plugin now uses the parsed MDAST node type as the default content model, so valid source imports and edits without a Lexical invariant failure.

Consumers can set kindMismatchPolicy to normalize when descriptors should be authoritative for lossless conversions, or error when every mismatch should be rejected through onError. Reconciliation runs before Lexical construction, follows import-visitor ownership, and also applies to direct MDAST tree imports.

The change includes documentation and regression coverage for nested edits, both mismatch directions, wildcard descriptors, built-in HTML ownership, direct imports, and unsupported normalization shapes.

Limits

Normalization does not split surrounding paragraphs or flatten multiple or non-paragraph blocks. Those cases produce a recoverable error because conversion could change or discard content.

@petyosi petyosi mentioned this pull request Aug 27, 2026
@petyosi
petyosi force-pushed the petyosi/jsx-kind-mismatch-policy branch from 63d68ce to a5f5763 Compare August 27, 2026 10:13
@petyosi
petyosi merged commit 300dfd5 into main Aug 27, 2026
4 checks passed
@petyosi
petyosi deleted the petyosi/jsx-kind-mismatch-policy branch August 27, 2026 10:43
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 4.2.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]

1 participant