Skip to content

fix(ssg-md): preserve mdxFlowExpression nodes in remarkSplitMdx#3181

Merged
SoonIter merged 4 commits intomainfrom
syt-vibe-kanban/3257-remarksplitmdx-b
Mar 3, 2026
Merged

fix(ssg-md): preserve mdxFlowExpression nodes in remarkSplitMdx#3181
SoonIter merged 4 commits intomainfrom
syt-vibe-kanban/3257-remarksplitmdx-b

Conversation

@SoonIter
Copy link
Copy Markdown
Member

@SoonIter SoonIter commented Mar 2, 2026

Summary

source code

// foo.mdx
# Hello {window.title}

Before

// foo.md
# Hello {window.title}

After

// foo.md
# Hello title

Related Issue

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

AI Summary

What changed:

Top-level mdxFlowExpression and mdxTextExpression nodes (e.g., {window.foo}) are now preserved as-is in the remarkSplitMdx plugin, instead of being incorrectly serialized into string literals.

Why:

When an MDX file contains a top-level expression like {window.foo}, the MDX parser produces an mdxFlowExpression AST node. The remarkSplitMdx plugin's main loop did not have a case for this node type, so it fell through to the "pure markdown" branch which called buildMdxFlowExpressionFragment(). This wrapped the expression in a JSON.stringify literal, turning {window.foo} into {"{window.foo}"} — a plain string instead of an evaluated expression.

How:

Added an early check in the main tree-children loop to pass through mdxFlowExpression and mdxTextExpression nodes unchanged, before the markdown serialization branch. Added a corresponding test case that verifies {window.foo} appears as {window.foo} (evaluated) rather than {"{window.foo}"} (string) in the compiled output.

This PR was written using Vibe Kanban


Top-level mdxFlowExpression nodes (e.g., {window.foo}) were falling
through to the serialization branch, converting them to string literals
instead of preserving them as evaluated expressions.
Copilot AI review requested due to automatic review settings March 2, 2026 13:30
@SoonIter SoonIter changed the title 修复 remarkSplitMdx 中的一个 bug (vibe-kanban) fix(core): preserve mdxFlowExpression nodes in remarkSplitMdx Mar 2, 2026
@SoonIter SoonIter changed the title fix(core): preserve mdxFlowExpression nodes in remarkSplitMdx fix(ssg-md): preserve mdxFlowExpression nodes in remarkSplitMdx Mar 2, 2026
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Mar 2, 2026

Deploying rspress-v2 with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5fe546f
Status: ✅  Deploy successful!
Preview URL: https://944437f6.rspress-v2.pages.dev
Branch Preview URL: https://syt-vibe-kanban-3257-remarks.rspress-v2.pages.dev

View logs

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes an MDX splitting issue in the SSG MD pipeline where standalone MDX expressions like {window.foo} were incorrectly stringified instead of being preserved as executable MDX AST nodes.

Changes:

  • Preserve top-level mdxFlowExpression / mdxTextExpression nodes during remarkSplitMdx processing to avoid converting them into string literals.
  • Add a regression test ensuring {window.foo} compiles into an actual expression output rather than a quoted string.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
packages/core/src/node/ssg-md/remarkSplitMdx.ts Adds a guard to keep MDX expression nodes intact at the root level.
packages/core/src/node/ssg-md/remarkSplitMdx.test.ts Adds a snapshot test to validate the standalone MDX expression case.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 2, 2026

Rsdoctor Bundle Diff Analysis

Found 3 projects in monorepo, 3 projects with changes.

📊 Quick Summary
Project Total Size Change
node 12.0 MB +13.5 KB (0.1%)
node_md 1.5 MB +3.0 KB (0.2%)
web 16.0 MB +10.0 KB (0.1%)
📋 Detailed Reports (Click to expand)

📁 node

Path: website/doc_build/diff-rsdoctor/node/rsdoctor-data.json

📌 Baseline Commit: e64a8783e3 | PR: #3171

Metric Current Baseline Change
📊 Total Size 12.0 MB 12.0 MB +13.5 KB (0.1%)
📄 JavaScript 0 B 0 B 0
🎨 CSS 0 B 0 B 0
🌐 HTML 12.0 MB 12.0 MB +13.5 KB (0.1%)
📁 Other Assets 0 B 0 B 0

📦 Download Diff Report: node Bundle Diff

📁 node_md

Path: website/doc_build/diff-rsdoctor/node_md/rsdoctor-data.json

📌 Baseline Commit: e64a8783e3 | PR: #3171

Metric Current Baseline Change
📊 Total Size 1.5 MB 1.5 MB +3.0 KB (0.2%)
📄 JavaScript 0 B 0 B 0
🎨 CSS 0 B 0 B 0
🌐 HTML 0 B 0 B 0
📁 Other Assets 1.5 MB 1.5 MB +3.0 KB (0.2%)

📦 Download Diff Report: node_md Bundle Diff

📁 web

Path: website/doc_build/diff-rsdoctor/web/rsdoctor-data.json

📌 Baseline Commit: e64a8783e3 | PR: #3171

Metric Current Baseline Change
📊 Total Size 16.0 MB 15.9 MB +10.0 KB (0.1%)
📄 JavaScript 15.7 MB 15.7 MB +10.0 KB (0.1%)
🎨 CSS 120.3 KB 120.3 KB 0
🌐 HTML 0 B 0 B 0
📁 Other Assets 163.6 KB 163.6 KB 0

📦 Download Diff Report: web Bundle Diff

Generated by Rsdoctor GitHub Action

SoonIter added 3 commits March 3, 2026 11:50
Extend expression preservation to inline/nested contexts:
- hasJsxChildren now detects mdxFlowExpression/mdxTextExpression
- processMixedContent preserves expression nodes in headings/paragraphs
- processJsxChildren preserves expression nodes inside JSX elements
Now that remarkSplitMdx preserves mdxFlowExpression/mdxTextExpression
nodes, {reactVersion} and {version} are properly evaluated instead of
being stringified. Update the e2e test to expect resolved version
values and remove the FIXME comment.
@SoonIter SoonIter enabled auto-merge (squash) March 3, 2026 04:13
@SoonIter SoonIter requested a review from Timeless0911 March 3, 2026 05:13
@SoonIter SoonIter merged commit d330716 into main Mar 3, 2026
5 checks passed
@SoonIter SoonIter deleted the syt-vibe-kanban/3257-remarksplitmdx-b branch March 3, 2026 05:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants