# Fumadocs (Framework Mode, Astro): MDX Remote
URL: /docs/astro/integrations/content/mdx-remote
Source: https://raw.githubusercontent.com/fuma-nama/fumadocs/refs/heads/main/apps/docs/content/docs/(framework)/[framework]/integrations/content/mdx-remote.mdx

Compiled Markdown/MDX content on demand.

## Introduction [#introduction]

Fumadocs offers the **MDX Remote** package, a helper to integrate Markdown/MDX content sources with Fumadocs.
Think of it as `next-mdx-remote` with built-in plugins for Fumadocs.

<Callout type="warn">
Do not pass untrusted MDX to the compiler, it runs as JavaScript in your app. Compile untrusted content as Markdown instead, it can't run JavaScript or raw HTML:

```ts
import { createCompiler } from '@fumadocs/mdx-remote';

const compiler = createCompiler({
  format: 'md',
  // skip reading files and fetching URLs for image sizes
  remarkImageOptions: false,
});
```
</Callout>

## Setup [#setup]

```package-install
@fumadocs/mdx-remote
```

Its main feature is the MDX compiler, which compiles MDX content to JSX nodes.
It doesn't use a bundler, so there are some limitations:

- Images have to be optimized at runtime.
- No imports and exports in MDX files.

### Usage [#usage]

Create a compiler:

```ts title="lib/compiler.ts"
import { createCompiler } from '@fumadocs/mdx-remote';

export const compiler = createCompiler({
  // options
});
```

Compile the content of your pages, `@/lib/source` stands for your content source.

`compileFile()` compiles it to JavaScript in the page, and `executeMdxSync()` runs it in a React island:

```astro tab="src/pages/docs/[...slug].astro"
---
import type { GetStaticPaths, InferGetStaticPropsType } from 'astro';
import Layout from '@/layouts/Layout.astro';
import { Docs } from '@/components/docs';
import { compiler } from '@/lib/compiler';
import { getPage, source } from '@/lib/source';

export const prerender = true;

export const getStaticPaths = (() => {
  return source.getPages().map((page) => ({
    params: { slug: decodeURI(page.slugs.join('/')) || undefined },
    props: { page },
  }));
}) satisfies GetStaticPaths;

type Props = InferGetStaticPropsType<typeof getStaticPaths>;

const { page } = Astro.props;
const pageTree = await source.serializePageTree(source.getPageTree());
// compile to JavaScript, it runs in the island
const compiled = String(await compiler.compileFile(getPage(page.slugs).content));
---

<Layout title={page.data.title}>
  <Docs
    client:load
    pathname={Astro.url.pathname}
    params={Astro.params}
    tree={pageTree}
    compiled={compiled}
  />
</Layout>
```

```tsx tab="src/components/docs.tsx"
import { useMemo } from 'react';
import { executeMdxSync } from '@fumadocs/mdx-remote/client';
import { type SerializedPageTree, useFumadocsLoader } from 'fumadocs-core/source/client';
import { DocsLayout } from 'fumadocs-ui/layouts/docs';
import { DocsBody, DocsPage } from 'fumadocs-ui/layouts/docs/page';
import { Provider, type ProviderProps } from '@/components/provider';
import { getMDXComponents } from '@/components/mdx';

export interface DocsProps extends ProviderProps {
  tree: SerializedPageTree;
  compiled: string;
}

export function Docs({ tree, compiled, ...props }: DocsProps) {
  const data = useFumadocsLoader({ tree });
  const { default: MdxContent, toc } = useMemo(() => executeMdxSync(compiled), [compiled]);

  return (
    <Provider {...props}>
      <DocsLayout tree={data.tree}>
        <DocsPage toc={toc}>
          <DocsBody>
            <MdxContent components={getMDXComponents()} />
          </DocsBody>
        </DocsPage>
      </DocsLayout>
    </Provider>
  );
}
```

> The `frontmatter` property returned by `compile()` is not validated. Validate it with a library like `zod`.

### Images [#images]

On serverless platforms like Vercel, the original `public` folder (including static assets like images) will be removed after production build.
The MDX compiler might no longer be able to access local images in `public`.

When referencing images, make sure to use a URL.