Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update mdx integration docs for v3 #8151

Merged
merged 6 commits into from
May 8, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/content/docs/en/guides/integrations-guide/mdx.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ We suggest [using AST Explorer](https://astexplorer.net/) to play with estree ou

### `optimize`

* **Type:** `boolean | { customComponentNames?: string[] }`
* **Type:** `boolean | { ignoreElementNames?: string[] }`

This is an optional configuration setting to optimize the MDX output for faster builds and rendering via an internal rehype plugin. This may be useful if you have many MDX files and notice slow builds. However, this option may generate some unescaped HTML, so make sure your site's interactive parts still work correctly after enabling it.

Expand All @@ -216,11 +216,13 @@ export default defineConfig({
});
```

#### `customComponentNames`
#### `ignoreElementNames`

* **Type:** `string[]`

An optional property of `optimize` to prevent the MDX optimizer from handling any [custom components passed to imported MDX content via the components prop](/en/guides/markdown-content/#custom-components-with-imported-mdx).
Previously known as `customComponentNames` in `@astrojs/mdx` v2.
bluwy marked this conversation as resolved.
Show resolved Hide resolved

An optional property of `optimize` to prevent the MDX optimizer from handling certain element names, like [custom components passed to imported MDX content via the components prop](/en/guides/markdown-content/#custom-components-with-imported-mdx).

You will need to exclude these components from optimization as the optimizer eagerly converts content into a static string, which will break custom components that needs to be dynamically rendered.

Expand All @@ -235,7 +237,7 @@ import Heading from '../Heading.astro';
<Content components={{ ...components, h1: Heading }} />
```

To configure optimization for this using the `customComponentNames` property, specify an array of HTML element names that should be treated as custom components:
To configure optimization for this using the `ignoreElementNames` property, specify an array of HTML element names that should be treated as custom components:

```js title="astro.config.mjs"
import { defineConfig } from 'astro/config';
Expand All @@ -247,8 +249,7 @@ export default defineConfig({
mdx({
optimize: {
// Prevent the optimizer from handling `h1` elements
// These will be treated as custom components
customComponentNames: ['h1'],
ignoreElementNames: ['h1'],
},
}),
],
Expand Down
Loading