mdx-editor / mdx-editor/editor

[BUG] Heading type incorrectly transfers to the latter fragment when splitting a heading containing a line break

Open
#925 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
3.7k
Forks
307
Avg merge
14h 22m
Merged PRs (30d)
5

Description

  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • I have read the documentation and cannot find an answer.

Describe the bug

When a Heading node contains a LineBreakNode (inserted via Shift+Enter) and the user presses Enter to split the block, the heading type incorrectly transfers to the latter fragment. The original text loses its heading formatting and becomes a plain paragraph.

To Reproduce

  1. Create a Heading (e.g., select "Heading 1" from the Block Type dropdown)
  2. Type some text (e.g., first)
  3. Press Shift+Enter to insert a line break inside the heading
  4. Type more text (e.g., second)
  5. Press Enter to split into a new block

Expected behavior

# first       ← heading type stays with the original text
second        ← new paragraph

Actual behavior

first         ← heading type is lost (downgraded to paragraph)
# second      ← heading type incorrectly transferred here

Screenshots

Before Enter (Shift+Enter line break inside H1):

Image

After Enter (heading transferred to wrong fragment):
Image

Desktop

  • OS: macOS
  • Browser: Chrome
  • MDXEditor version: 3.52.4

Additional context

We discovered this while building a form-integrated MDXEditor setup (MDXEditor + react-hook-form) where we needed to ensure the markdown round-trip (markdown → editor → markdown) produces consistent results.

Our use case involves saving editor content as markdown to a database and reloading it later. Since the markdown ↔ WYSIWYG round-trip is inherently lossy (CommonMark collapses multiple blank lines, etc.), we normalize content at save time using the same mdast-util-from-markdown / mdast-util-to-markdown pipeline that MDXEditor uses internally — to keep the saved value and editor display in sync.

While testing all block types (h1–h3, paragraph, blockquote, lists) for Enter vs Shift+Enter behavior to verify visual consistency between the editor and rendered output, we noticed this heading split issue. It breaks the assumption that block-level formatting stays with the original content when a block is split.

This also means that a heading containing a Shift+Enter, when saved and reloaded through the mdast round-trip, can produce a different structure than what the user originally authored — compounding the round-trip normalization problem.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue in MDXEditor 3.52.4 using an H1, Shift+Enter, more text, and Enter, then inspect the heading-splitting behavior. Done means the original fragment remains a heading, the latter fragment becomes a paragraph, and the behavior is consistent with the expected markdown round-trip.

Written by the indexing model from the issue text.

Assessment

Tech stack
markdown, react, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.