Nextra processes MDX files at the webpack/Turbopack build level for local content, but sometimes you need to compile and render MDX that is fetched at request time — from a CMS, a GitHub repository, or a database. TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/shuding/nextra/llms.txt
Use this file to discover all available pages before exploring further.
compileMdx() function and MDXRemote component together provide a server-side compilation pipeline and a client-ready renderer for exactly this use case.
compileMdx()
Compiles a raw MDX string into serialised JavaScript that can be evaluated at runtime. The function runs the full Nextra remark/rehype/recma pipeline (GFM, syntax highlighting, front-matter extraction, smart quotes, etc.) and returns the resulting module code as a string.compileMdx always produces output in function-body format so that the
compiled string can be evaluated safely inside MDXRemote without requiring a
full module bundler at runtime.Parameters
The raw MDX (or Markdown) source string to compile.
Optional compilation settings. All fields are optional and mirror the
corresponding options available in
NextraConfig.Return value
compileMdx returns a Promise<string> — the serialised JavaScript module
body that MDXRemote evaluates to produce a React component.
MDXRemote
A React component that evaluates the string produced bycompileMdx() and renders the resulting MDX content. It accepts custom component overrides and scope variables, making it easy to inject your own design-system components or dynamic data into remotely-fetched content.
Props
The serialised JavaScript string returned by
compileMdx(). MDXRemote
evaluates this string using Nextra’s evaluate helper and renders the default
export as a React element.An object mapping MDX element names to React components. These are merged with
the components registered in your
mdx-components.js file, so local overrides
take precedence.An object whose keys become variables available inside the MDX expression
scope. Useful for passing server-fetched data into the MDX content without
embedding it directly in the source string.
Full Remote Content Example
The following pattern fetches MDX from a remote URL, compiles it on the server, and renders it inside a Next.js App Router page. No build-time pre-processing is required.app/remote/page.tsx
With scope variables and custom options
Relationship to Local MDX Processing
For MDX files inside your
content/ or app/ directory, Nextra compiles
them automatically at build time via the webpack/Turbopack loader — you do not
need compileMdx(). Use this API only when the MDX source is not available on
disk at build time.| Scenario | Approach |
|---|---|
MDX files in content/ or app/ | Automatic — no action needed |
| MDX fetched from a CMS at request time | compileMdx() + MDXRemote |
| MDX from a GitHub repository | compileMdx() + MDXRemote |
| User-generated MDX content | compileMdx() + MDXRemote (sanitise first) |