Issue involves optimizing Turbopack processing but maintainer disagrees with the assessment.
The issue suggests changing Turbopack's rule for MDX files from `as: '*.tsx'` to `as: '*.js'` to avoid redundant processing, but the maintainer disputes the claimed performance impact. The fix is simple but its necessity and effectiveness are unclear.
https://codesandbox.io/p/devbox/staging-monad-ns775c
@next/mdx and Turbopack enabled (default in canary).app/heavy/page.mdx that uses rehype-katex with several math equations.next dev.The slow path is triggered by as: '*.tsx' in the Turbopack rule inside
packages/next-mdx/index.js, which routes already-compiled JavaScript through
Turbopack's TypeScript/JSX pipeline a second time.
Current:
The Turbopack loader rule for .mdx files sets as: '*.tsx', which tells
Turbopack to re-process the loader output through its full TypeScript/JSX
pipeline (type-stripping → JSX transform → source-map merge).
@mdx-js/mdx already compiles MDX to plain JavaScript using the automatic JSX
runtime (_jsx()/_jsxs() calls). The output contains no JSX syntax and no
TypeScript, so the extra pipeline is pure overhead.
For large outputs (e.g. rehype-katex on a math-heavy page: ~1.9 MB), the
redundant source-map merging alone adds ~50 s of compilation time.
Expected:
The rule should use as: '*.js' so Turbopack treats the loader output as
plain JavaScript and skips the unnecessary TypeScript/JSX pipeline.
The fix is a one-line change:
- as: '*.tsx',
+ as: '*.js',
Operating System:
Platform: linux
Arch: x64
Version: #1 SMP PREEMPT_DYNAMIC Sun Aug 6 20:05:33 UTC 2023
Available memory (MB): 4102
Available CPU cores: 2
Binaries:
Node: 20.12.1
npm: 10.5.0
Yarn: 1.22.19
pnpm: 8.15.6
Relevant Packages:
next: 16.2.0-canary.85 // Latest available version is detected (16.2.0-canary.85).
eslint-config-next: N/A
react: 19.2.4
react-dom: 19.2.4
typescript: 5.9.3
Markdown (MDX)
Claim this issue to let others know you're working on it. You'll earn 15 points when you complete it!