Skip to content

fix(markdown): preserve table cells during MDX fallback#5007

Open
kiranmagic7 wants to merge 1 commit into
udecode:mainfrom
kiranmagic7:fix/markdown-table-incomplete-mdx-5006
Open

fix(markdown): preserve table cells during MDX fallback#5007
kiranmagic7 wants to merge 1 commit into
udecode:mainfrom
kiranmagic7:fix/markdown-table-incomplete-mdx-5006

Conversation

@kiranmagic7

@kiranmagic7 kiranmagic7 commented Jun 12, 2026

Copy link
Copy Markdown
Contributor
  • Auto release

Summary

Fixes #5006.

When MDX parsing fails on plain less-than text inside a GFM table cell, the safe Markdown fallback now keeps the table structure valid instead of appending fallback inline text directly under the table node. If the incomplete MDX tail belongs to a table, the fallback replaces the partial table with the non-MDX parsed table while preserving completed blocks before it.

Testing

  • ./node_modules/.bin/bun test packages/markdown/src/lib/table.spec.ts packages/markdown/src/lib/deserializer/utils/markdownToSlateNodesSafely.spec.tsx -> 7 passed
  • PATH="$PWD/node_modules/.bin:$PATH" pnpm --filter @platejs/markdown lint -> passed
  • pnpm turbo build --filter=./packages/markdown -> 11 tasks passed
  • ./node_modules/.bin/biome check packages/markdown/src/lib/deserializer/utils/markdownToSlateNodesSafely.ts packages/markdown/src/lib/table.spec.ts .changeset/green-plants-fix.md -> passed
  • git diff --check -> passed

Notes

  • Full ./node_modules/.bin/bun test packages/markdown/src/lib reached 210 passing tests, then stopped on an existing local module-resolution issue for @platejs/list-classic/react in standardList.spec.tsx.
  • pnpm turbo typecheck --filter=./packages/markdown also fails in this checkout on existing unresolved local workspace/test imports such as @platejs/basic-nodes, @platejs/test-utils, and @platejs/table, not on this change.
  • Local codex review --base origin/main was not run because codex is not installed in this environment.

AI-assisted: yes. I understand the change and verified the focused regression locally.

@kiranmagic7 kiranmagic7 requested a review from a team June 12, 2026 09:30
@codesandbox

codesandbox Bot commented Jun 12, 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 Jun 12, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: bb2dbcf

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

This PR includes changesets to release 1 package
Name Type
@platejs/markdown 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:M This PR changes 30-99 lines, ignoring generated files. patch Bugfix & documentation PR plugin:markdown Markdown deserializer plugin:table Tables labels Jun 12, 2026
@kiranmagic7 kiranmagic7 force-pushed the fix/markdown-table-incomplete-mdx-5006 branch from cb9ae4c to bb2dbcf Compare June 12, 2026 12:37
@zbeyens

zbeyens commented Jun 12, 2026

Copy link
Copy Markdown
Member

@codex

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bb2dbcfbe3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +113 to +114
if (fallbackTable) {
return [...completeNodes.slice(0, -1), fallbackTable];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve blocks after the fallback table

When the < that triggers MDX fallback is inside a table cell but the markdown continues after that table, withoutMdxNodes contains the repaired table plus the following blocks, while this return keeps only fallbackTable. For input shaped like a GFM table row containing a<b followed by \n\nAfter, the trailing paragraph is silently dropped; splice the fallback table together with the subsequent fallback nodes instead of returning only the table.

Useful? React with 👍 / 👎.

Comment on lines +38 to +40
lastChild.text += inlineNodes
.map((inlineNode) => inlineNode.text)
.join('');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid merging fallback text into marked leaves

When the complete prefix ends in a formatted text leaf, e.g. **bold**<u>, this branch appends the literal fallback text into that same leaf and preserves its marks, so <u> becomes bold text. The previous behavior appended the fallback inline nodes separately, which kept the incomplete MDX literal from inheriting formatting that only applied to the preceding markdown span.

Useful? React with 👍 / 👎.

Comment on lines +109 to +111
const fallbackTable = withoutMdxNodes
.filter((node) => ElementApi.isElement(node) && node.type === tableType)
.at(-1);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Match the fallback table to the split point

If the cell containing the plain less-than text is followed later by another GFM table, this picks the last table from the full non-MDX parse rather than the table that was partial in completeNodes. In that case the broken table is replaced with the later table and the original repaired table is lost; the fallback needs to identify the table corresponding to the split position, not just .at(-1) across the whole document.

Useful? React with 👍 / 👎.

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

Labels

patch Bugfix & documentation PR plugin:markdown Markdown deserializer plugin:table Tables size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Markdown table crashes when a table cell contains plain text with an unescaped <x character while remarkMdx is enabled.

2 participants