[PR #160] [MERGED] fix: register MDX plugin at top level to fix transform ordering #360

Closed
opened 2026-05-06 12:39:24 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/160
Author: @NathanDrake2406
Created: 2/27/2026
Status: Merged
Merged: 3/4/2026
Merged by: @southpolesteve

Base: mainHead: fix/mdx-plugin-ordering


📝 Commits (4)

  • 62c1026 fix: register MDX plugin at top level to fix transform ordering
  • 740617f Merge remote-tracking branch 'origin/main' into fix/mdx-plugin-ordering
  • b2f6833 address review: add config proxy, remove dead resolveId, fix comment separation
  • ea0597e add E2E test for MDX import transform ordering

📊 Changes

5 files changed (+78 additions, -8 deletions)

View changed files

📝 packages/vinext/src/index.ts (+29 -8)
tests/e2e/app-router/mdx.spec.ts (+21 -0)
tests/fixtures/app-basic/app/mdx-test/content.mdx (+6 -0)
tests/fixtures/app-basic/app/mdx-test/page.tsx (+9 -0)
📝 tests/pages-router.test.ts (+13 -0)

📄 Description

Summary

  • Fix auto-injected @mdx-js/rollup running too late in the Vite plugin pipeline, causing MDX files to fail to compile
  • Register a vinext:mdx proxy plugin in the top-level plugin array with enforce: 'pre' instead of returning the MDX plugin from the config() hook
  • Proxy delegates resolveId and transform to the real @mdx-js/rollup instance, which is created during config() and stored in a shared variable
  • Proxy is inert (no-ops) when no MDX files are detected

Fixes #77

Details

Root cause: The MDX plugin was returned from vinext:config's config() hook via viteConfig.plugins. Plugins merged from config() hooks land late in the pipeline — after vite:import-analysis has already tried (and failed) to process .mdx imports.

Fix: Instead of returning the plugin from config(), a vinext:mdx proxy plugin is registered directly in the top-level plugin array returned by vinext(). It has enforce: 'pre', guaranteeing its resolveId and transform hooks run before vite:import-analysis. The proxy handles both function-style and object-style Rollup hooks (i.e. { handler, order } form).

Test plan

  • Build passes (pnpm run build)
  • Lint passes (pnpm run lint — 0 warnings, 0 errors)
  • Typecheck passes (pnpm run typecheck)
  • Full Vitest suite passes (pnpm test — 50 files, 2051 tests passed, 3 skipped)
  • New test verifies vinext:mdx plugin exists with enforce: 'pre' and is inert when no MDX delegate is set
  • E2E: verify MDX page renders in a project with .mdx files in app/

🔄 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/160 **Author:** [@NathanDrake2406](https://github.com/NathanDrake2406) **Created:** 2/27/2026 **Status:** ✅ Merged **Merged:** 3/4/2026 **Merged by:** [@southpolesteve](https://github.com/southpolesteve) **Base:** `main` ← **Head:** `fix/mdx-plugin-ordering` --- ### 📝 Commits (4) - [`62c1026`](https://github.com/cloudflare/vinext/commit/62c1026b891d9456686bc90885eb7bdb5d72e022) fix: register MDX plugin at top level to fix transform ordering - [`740617f`](https://github.com/cloudflare/vinext/commit/740617f4e2aa0587c06acff86e9c6b5804202efb) Merge remote-tracking branch 'origin/main' into fix/mdx-plugin-ordering - [`b2f6833`](https://github.com/cloudflare/vinext/commit/b2f6833dac12da8224e42747748c36edf0494d6f) address review: add config proxy, remove dead resolveId, fix comment separation - [`ea0597e`](https://github.com/cloudflare/vinext/commit/ea0597ea45604525dbf5a648648836169b5bcf2f) add E2E test for MDX import transform ordering ### 📊 Changes **5 files changed** (+78 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/index.ts` (+29 -8) ➕ `tests/e2e/app-router/mdx.spec.ts` (+21 -0) ➕ `tests/fixtures/app-basic/app/mdx-test/content.mdx` (+6 -0) ➕ `tests/fixtures/app-basic/app/mdx-test/page.tsx` (+9 -0) 📝 `tests/pages-router.test.ts` (+13 -0) </details> ### 📄 Description ## Summary - Fix auto-injected `@mdx-js/rollup` running too late in the Vite plugin pipeline, causing MDX files to fail to compile - Register a `vinext:mdx` proxy plugin in the top-level plugin array with `enforce: 'pre'` instead of returning the MDX plugin from the `config()` hook - Proxy delegates `resolveId` and `transform` to the real `@mdx-js/rollup` instance, which is created during `config()` and stored in a shared variable - Proxy is inert (no-ops) when no MDX files are detected Fixes #77 ## Details **Root cause:** The MDX plugin was returned from `vinext:config`'s `config()` hook via `viteConfig.plugins`. Plugins merged from `config()` hooks land late in the pipeline — after `vite:import-analysis` has already tried (and failed) to process `.mdx` imports. **Fix:** Instead of returning the plugin from `config()`, a `vinext:mdx` proxy plugin is registered directly in the top-level plugin array returned by `vinext()`. It has `enforce: 'pre'`, guaranteeing its `resolveId` and `transform` hooks run before `vite:import-analysis`. The proxy handles both function-style and object-style Rollup hooks (i.e. `{ handler, order }` form). ## Test plan - [x] Build passes (`pnpm run build`) - [x] Lint passes (`pnpm run lint` — 0 warnings, 0 errors) - [x] Typecheck passes (`pnpm run typecheck`) - [x] Full Vitest suite passes (`pnpm test` — 50 files, 2051 tests passed, 3 skipped) - [x] New test verifies `vinext:mdx` plugin exists with `enforce: 'pre'` and is inert when no MDX delegate is set - [ ] E2E: verify MDX page renders in a project with `.mdx` files in `app/` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 12:39:24 +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#360
No description provided.