[PR #668] [MERGED] fix: skip MDX files during RSC scan-build to prevent parse errors #756

Closed
opened 2026-05-06 13:09:58 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/668
Author: @Divkix
Created: 3/23/2026
Status: Merged
Merged: 3/29/2026
Merged by: @james-elicx

Base: mainHead: fix/issue-659-mdx-scan-strip-parses-mdx


📝 Commits (9)

  • e38d65b fix: skip MDX files during RSC scan-build to prevent parse errors (issue #659)
  • af6f644 fix(mdx): return stub module for undetected MDX files during scan-build
  • f873091 fix(mdx): lazily compile globbed mdx imports
  • a0a2b05 fix review issues
  • 722a144 fix: use absolute path for root tsconfig alias to fix import.meta.glob resolution
  • f5f2bdb refactor: address review feedback on MDX lazy initialization
  • 3ed5fe8 refactor: address review feedback on MDX handling
  • 49a368f docs: clarify mdx delegate fallback comment
  • 8a90748 chore: trigger ci

📊 Changes

4 files changed (+309 additions, -134 deletions)

View changed files

📝 packages/vinext/src/index.ts (+87 -39)
📝 tests/pages-router.test.ts (+56 -6)
📝 tests/tsconfig-path-alias-build.test.ts (+161 -84)
📝 tests/tsconfig-paths-vite8.test.ts (+5 -5)

📄 Description

Summary

  • Adds on-demand @mdx-js/rollup initialization when MDX files are encountered during transform but weren't pre-detected by hasMdxFiles()
  • Fixes toViteAliasReplacement() to return absolute path instead of "/" when alias target equals project root (companion fix)
  • Prevents rsc:scan-strip parse errors on MDX files with YAML frontmatter and JSX
  • Adds regression test for issue #659

Root cause

When import.meta.glob loads MDX files outside app/ or pages/ directories in an RSC build, rsc:scan-strip (from @vitejs/plugin-rsc) runs on all files including MDX. It uses es-module-lexer.parse() which fails on MDX frontmatter (---) and JSX syntax. The lazy on-demand initialization ensures MDX is compiled before rsc:scan-strip sees it.

Companion fix: tsconfig alias root resolution

Fixed toViteAliasReplacement() to return the normalized absolute path when an alias target resolves to the project root (e.g., @/* -> ./*). Previously it returned "/" which Vite could misinterpret as filesystem root on Linux. This affects all tsconfig alias resolution.

Testing

  • pnpm test tests/tsconfig-path-alias-build.test.ts - 2 tests pass
  • pnpm test tests/pages-router.test.ts - MDX-related tests pass
  • pnpm test tests/tsconfig-paths-vite8.test.ts - 7 tests pass

Regression test verified: fails on main without the fix, passes with the fix.

Closes #659


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/cloudflare/vinext/pull/668 **Author:** [@Divkix](https://github.com/Divkix) **Created:** 3/23/2026 **Status:** ✅ Merged **Merged:** 3/29/2026 **Merged by:** [@james-elicx](https://github.com/james-elicx) **Base:** `main` ← **Head:** `fix/issue-659-mdx-scan-strip-parses-mdx` --- ### 📝 Commits (9) - [`e38d65b`](https://github.com/cloudflare/vinext/commit/e38d65b057cc0960d85513a1d06aecae96747a04) fix: skip MDX files during RSC scan-build to prevent parse errors (issue #659) - [`af6f644`](https://github.com/cloudflare/vinext/commit/af6f644aaa21e8ba67bcf91093ca6ad33703c834) fix(mdx): return stub module for undetected MDX files during scan-build - [`f873091`](https://github.com/cloudflare/vinext/commit/f873091f23440bf891afd7503484a2c3261c73c5) fix(mdx): lazily compile globbed mdx imports - [`a0a2b05`](https://github.com/cloudflare/vinext/commit/a0a2b05b633b02250271113a006272a474b18171) fix review issues - [`722a144`](https://github.com/cloudflare/vinext/commit/722a14447c26a34496bbfac43ad36e5c4ede152f) fix: use absolute path for root tsconfig alias to fix import.meta.glob resolution - [`f5f2bdb`](https://github.com/cloudflare/vinext/commit/f5f2bdbb8ea8aa8facb8e1af6440755f5027effa) refactor: address review feedback on MDX lazy initialization - [`3ed5fe8`](https://github.com/cloudflare/vinext/commit/3ed5fe893438b2301d35dd171fdeb5c91572a6cd) refactor: address review feedback on MDX handling - [`49a368f`](https://github.com/cloudflare/vinext/commit/49a368f13c2c5743634a7ba9c0ce4c94a28e2cf8) docs: clarify mdx delegate fallback comment - [`8a90748`](https://github.com/cloudflare/vinext/commit/8a907484454c25f76277ccbb1134f6230920da43) chore: trigger ci ### 📊 Changes **4 files changed** (+309 additions, -134 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/index.ts` (+87 -39) 📝 `tests/pages-router.test.ts` (+56 -6) 📝 `tests/tsconfig-path-alias-build.test.ts` (+161 -84) 📝 `tests/tsconfig-paths-vite8.test.ts` (+5 -5) </details> ### 📄 Description ## Summary - Adds on-demand @mdx-js/rollup initialization when MDX files are encountered during transform but weren't pre-detected by hasMdxFiles() - Fixes toViteAliasReplacement() to return absolute path instead of "/" when alias target equals project root (companion fix) - Prevents rsc:scan-strip parse errors on MDX files with YAML frontmatter and JSX - Adds regression test for issue #659 ## Root cause When import.meta.glob loads MDX files outside app/ or pages/ directories in an RSC build, rsc:scan-strip (from @vitejs/plugin-rsc) runs on all files including MDX. It uses es-module-lexer.parse() which fails on MDX frontmatter (---) and JSX syntax. The lazy on-demand initialization ensures MDX is compiled before rsc:scan-strip sees it. ## Companion fix: tsconfig alias root resolution Fixed toViteAliasReplacement() to return the normalized absolute path when an alias target resolves to the project root (e.g., @/* -> ./*). Previously it returned "/" which Vite could misinterpret as filesystem root on Linux. This affects all tsconfig alias resolution. ## Testing - pnpm test tests/tsconfig-path-alias-build.test.ts - 2 tests pass - pnpm test tests/pages-router.test.ts - MDX-related tests pass - pnpm test tests/tsconfig-paths-vite8.test.ts - 7 tests pass Regression test verified: fails on main without the fix, passes with the fix. Closes #659 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 13:09:58 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#756
No description provided.