Skip to content

mdx

Use when working with MDX — custom component mapping, remark/rehype plugins, framework-specific setup (@astrojs/mdx, @next/mdx), and MDX in content collections. Also use for MDX-related configuration and plugin troubleshooting.

ModelSource
sonnetpack: frontend
Full Reference

┏━ 🔧 mdx ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ MDX — Markdown for the component era ┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

MDX (v3.x) combines Markdown with JSX. Write content in Markdown, embed React/JSX components, use JS expressions, and import/export via ESM.

ItemValue
Core package@mdx-js/mdx v3.1.1
PipelineMDX → mdast (remark) → hast (rehype) → esast (recma) → JS
JSX supportReact, Preact, Vue, Solid (via jsxImportSource)
Docshttps://mdxjs.com/docs/
I want to…File
Set up MDX with Next.js or Astroreference/setup.md
Map HTML elements to custom componentsreference/components.md
Add remark/rehype/recma pluginsreference/plugins.md
Patterns for content collections, frontmatter, layoutsreference/patterns.md

Usage: Read the reference file matching your current task. Load only what you need — don’t ingest all 4 files for a single question.

ConceptWhat it means
components propMap HTML elements (h1, a, code) to custom JSX
remarkPluginsTransform Markdown AST before HTML conversion
rehypePluginsTransform HTML AST after Markdown conversion
recmaPluginsTransform JavaScript AST at the output stage
evaluate()Compile + run MDX at runtime — only for trusted content
outputFormat: 'function-body'Use with run() for streaming/edge scenarios
useMDXComponentsContext-based component provider (React, Next.js)
GotchaFix
Frontmatter not parsed by @next/mdxAdd remark-frontmatter + remark-mdx-frontmatter
Plugins fail with TurbopackPass plugin names as strings, not imports
evaluate() with untrusted inputNever — use a sandboxed render approach instead
format: 'detect' in ProcessorOptionsBanned — only allowed in CompileOptions
Missing mdx-components.tsx in Next.js App RouterRequired — App Router will not work without it