fix(ssg-md): preserve mdxFlowExpression nodes in remarkSplitMdx#3181
fix(ssg-md): preserve mdxFlowExpression nodes in remarkSplitMdx#3181
Conversation
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.
Deploying rspress-v2 with
|
| 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 |
There was a problem hiding this comment.
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/mdxTextExpressionnodes duringremarkSplitMdxprocessing 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.
Rsdoctor Bundle Diff AnalysisFound 3 projects in monorepo, 3 projects with changes. 📊 Quick Summary
📋 Detailed Reports (Click to expand)📁 nodePath:
📦 Download Diff Report: node Bundle Diff 📁 node_mdPath:
📦 Download Diff Report: node_md Bundle Diff 📁 webPath:
📦 Download Diff Report: web Bundle Diff Generated by Rsdoctor GitHub Action |
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.
Summary
source code
// foo.mdx # Hello {window.title}Before
// foo.md # Hello {window.title}After
// foo.md # Hello titleRelated Issue
Checklist
AI Summary
What changed:
Top-level
mdxFlowExpressionandmdxTextExpressionnodes (e.g.,{window.foo}) are now preserved as-is in theremarkSplitMdxplugin, 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 anmdxFlowExpressionAST node. TheremarkSplitMdxplugin's main loop did not have a case for this node type, so it fell through to the "pure markdown" branch which calledbuildMdxFlowExpressionFragment(). This wrapped the expression in aJSON.stringifyliteral, 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
mdxFlowExpressionandmdxTextExpressionnodes 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