next-mdx-remote

Load, compile, and hydrate MDX content from any remote source—CMS, database, or API—inside Next.js apps, without a build-time file import.

Library
npm
v6.0.0
3,073stars
Mozilla Public License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
51/100Fair
Development Activity8
Maintenance44
Community52
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
70/100Good
Architecture75
Code Quality80
Innovation70
Learning Curve55

next-mdx-remote is a small utility library that lets Next.js applications render MDX content that doesn’t live as a local file at build time. A serialize() function runs server-side (inside getStaticProps, getServerSideProps, or a Server Component) to compile a raw MDX string—pulled from a CMS, database, or any remote source—into a portable, JSON-safe compiledSource payload plus parsed frontmatter and scope. That payload is then handed to the client-side <MDXRemote /> component (or, for the React Server Components path, the single-call compileMDX()/MDXRemote async function), which evaluates the compiled source at runtime and renders it through @mdx-js/react’s MDXProvider, with consumer-supplied components available inside the MDX.

The library also adds guardrails aimed at the specific risk of compiling MDX from untrusted or remote sources: import/export statements are stripped by default, and JavaScript expressions ({variable}, {func()}) are blocked unless explicitly allowed, with a best-effort filter for dangerous globals like eval and process when they are. As of early 2026 the project has been archived by its maintainers and is no longer actively supported, so it should be evaluated as a stable, no-further-development dependency rather than an actively maintained one.

What You Get

  • A serialize() function that compiles a raw MDX string—pulled from anywhere—into a portable compiledSource object usable inside getStaticProps/getServerSideProps.
  • A <MDXRemote /> client component that hydrates compiled MDX with your own React components mapped in via a components prop.
  • A dedicated next-mdx-remote/rsc entry point exposing compileMDX() and an async MDXRemote for React Server Components, collapsing compile+render into a single call.
  • Optional frontmatter parsing (parseFrontmatter: true), a scope object for passing template variables into MDX, and a lazy hydration mode that defers client-side hydration via requestIdleCallback.
  • Built-in safety controls (blockJS, blockDangerousJS) for compiling MDX from sources you don’t fully trust.

Common Use Cases

  • Rendering blog posts or docs stored in a headless CMS or database instead of as local MDX files.
  • Building a marketing site where non-technical editors write MDX content that’s fetched at request/build time from an external API.
  • Server Components apps that want to compile and render remote MDX in one async call via compileMDX.
  • Multi-tenant or user-generated-content platforms that need to safely compile MDX-like text without exposing arbitrary JS execution.

Under The Hood

Architecture The package exposes three entry points via package.json exports: the root (src/index.tsx) for client-side hydration, next-mdx-remote/rsc (src/rsc.tsx) for React Server Components, and next-mdx-remote/serialize (src/serialize.ts) for the server-side compile step—a clean split between compiling MDX and rendering it. serialize() calls @mdx-js/mdx’s compile() with a chain of remark plugins assembled in getCompileOptions() (stripping imports/exports, blocking JS expressions or dangerous globals), producing a self-contained function-body compiledSource string plus frontmatter and scope. On the client, MDXRemote evaluates that string via Reflect.construct(Function, ...), closing over React, the MDX runtime, and consumer-supplied components/scope, then renders through MDXProvider; the RSC path’s compileMDX does the same construct-and-eval trick synchronously inside an async server function, skipping the serialize-to-props round trip entirely. This eval bridge is the one abstraction the whole library depends on—change how @mdx-js/mdx’s output format shapes compiledSource and every consumer breaks.

Tech Stack TypeScript compiled via tsc to flat index.js/serialize.js/rsc.js entry files (no bundler), built on @mdx-js/mdx and @mdx-js/react ^3 for MDX compilation and context, vfile/vfile-matter for the compiled-file model and frontmatter parsing, unist-util-visit/unist-util-remove for the custom remark plugins, and @babel/code-frame for formatted compiler error output. The only peer dependency is react >=16. Tooling includes Changesets for versioning and canary/stable release workflows in GitHub Actions, Vitest for tests, tsc --noEmit for type-checking, and Prettier with a husky pre-commit hook; the test harness spins up a real Next.js app plus Puppeteer for browser-level integration tests.

Code Quality Tests live in __tests__/ (integration, RSC, and serialize suites plus a fixtures Next.js app) run via Vitest, with a pretest step that builds and npm-packs the library first so tests exercise the actual published output rather than raw source—a stronger-than-typical setup. Type safety is thorough: a fully generic public API (MDXRemoteSerializeResult<TScope, TFrontmatter>), a dedicated test:types script, and hand-authored .d.ts files alongside generated ones. Error handling is explicit and user-facing—createFormattedMDXError parses the MDX compiler’s error message for line/column info and re-throws a formatted error with a code frame instead of letting a raw compiler exception surface. Naming is consistent across the three entry points, Prettier plus a pre-commit hook enforce formatting, and CI runs the test suite on every PR; the one gap is no linter configured beyond Prettier.

API Design The public surface is small and its names mirror each other across entry points (serialize / MDXRemote / compileMDX), so getting started requires little boilerplate—import serialize, call it server-side, pass the result to <MDXRemote />. The two-step server/client split (compile, then separately render) does ask consumers to understand and thread scope/components between two call sites, which is the main source of friction; the newer RSC compileMDX collapses this into a single async call and is meaningfully more ergonomic. Documentation lives entirely in an extensive README with collapsible sections covering common patterns (frontmatter, scope, MDXProvider, lazy hydration)—thorough, but there’s no separate API reference or docs site.

Used by 12 apps in this directory

Rust
53%
Other

Cap

Team Chat · Video Conferencing

21,859

Open source Loom alternative with GPU-accelerated recording, instant share links, AI summaries, and full self-hosting via Docker Compose.

View details
89
Repo Health
81
Technical
64
Dependency
Built with
Rust53%
TypeScript43%
Updated yesterday
TypeScript
84%
Apache 2.0

Continue

Developer Tools · AI Development · AI Code Assistants

35,808

Open-source coding agent for VS Code, JetBrains, and CLI with support for 30+ LLM providers.

View details
81
Repo Health
88
Technical
62
Dependency
Built with
TypeScript84%
Updated yesterday
TypeScript
75%
Apache 2.0

Fern

Developer Tools

3,772

Fern turns a single OpenAPI, AsyncAPI, or Protobuf definition into type-safe SDKs for nine languages and a hosted API documentation site, all from one CLI and one source of truth.

View details
90
Repo Health
86
Technical
66
Dependency
Built with
TypeScript75%
Updated yesterday
TypeScript
91%
Apache 2.0

Helicone

Monitoring · AI Development · Analytics

6,133

An open-source AI gateway and LLM observability platform that routes requests to 100+ models while logging cost, latency, and full traces for every call.

View details
69
Repo Health
81
Technical
65
Dependency
Built with
TypeScript91%
Updated 1 weeks ago
TypeScript
71%
Other

highlight.io

Developer Tools · Analytics · Monitoring

9,372

Open-source full-stack monitoring that unifies session replay, error tracking, logging, and distributed tracing so you can stop context-switching between tools.

View details
69
Repo Health
78
Technical
65
Dependency
Built with
TypeScript71%
Go16%
Updated 2 weeks ago
TypeScript
65%
Apache 2.0

Laminar

AI Development · Monitoring

3,230

Open-source observability platform purpose-built for AI agents — trace, evaluate, debug, and monitor at scale with SQL access and real-time replay.

View details
85
Repo Health
76
Technical
69
Dependency
Built with
TypeScript65%
Rust33%
Updated yesterday
TypeScript
99%
Other

LobeHub

AI Assistants · Productivity · Automation

82,273

Your Chief Agent Operator — build, schedule, and collaborate with an entire AI team in one self-hostable workspace.

View details
92
Repo Health
81
Technical
69
Dependency
Built with
TypeScript99%
Updated today
TypeScript
86%
MIT

medusa

Ecommerce

36,163

The most flexible open-source commerce platform — build B2C, B2B, and marketplace applications with modular, composable commerce primitives.

View details
93
Repo Health
87
Technical
63
Dependency
Built with
TypeScript86%
JavaScript14%
Updated 2 days ago
TypeScript
96%
AGPL 3.0

Midday

Invoicing Finance · Productivity

14,958

All-in-one AI-powered business operations platform for freelancers and solo entrepreneurs to manage invoicing, time tracking, banking, and financial intelligence.

View details
55
Repo Health
78
Technical
70
Dependency
Built with
TypeScript96%
Updated 2 months ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search