Skip to content

Commit

Permalink
MDX integration v3 (#10935)
Browse files Browse the repository at this point in the history
* fix(mdx): convert remark-images-to-component plugin to a rehype plugin (#10697)

* Remove fs read for MDX transform (#10866)

* Tag MDX component for faster checks when rendering (#10864)

* Use unified plugin only for MDX transform (#10869)

* Only traverse children and handle mdxJsxTextElement when optimizing (#10885)

* Rename to `optimize.ignoreComponentNames` in MDX (#10884)

* Allow remark/rehype plugins added after mdx to work (#10877)

* Improve MDX optimize with sibling nodes (#10887)

* Improve types in rehype-optimize-static.ts

* Rename `ignoreComponentNames` to `ignoreElementNames`

I think this better reflects what it's actually doing

* Simplify plain MDX nodes in optimize option (#10934)

* Format code

* Minimize diff changes

* Update .changeset/slimy-cobras-end.md

Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>

---------

Co-authored-by: Armand Philippot <59021693+ArmandPhilippot@users.noreply.github.com>
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
  • Loading branch information
3 people committed May 8, 2024
1 parent 685fc22 commit ddd8e49
Show file tree
Hide file tree
Showing 34 changed files with 1,081 additions and 281 deletions.
5 changes: 5 additions & 0 deletions .changeset/blue-geese-visit.md
@@ -0,0 +1,5 @@
---
"@astrojs/mdx": patch
---

Simplifies plain MDX components as hast element nodes to further improve HTML string inlining for the `optimize` option
5 changes: 5 additions & 0 deletions .changeset/chilly-items-help.md
@@ -0,0 +1,5 @@
---
"astro": patch
---

Improves the error message when failed to render MDX components
5 changes: 5 additions & 0 deletions .changeset/fresh-masks-agree.md
@@ -0,0 +1,5 @@
---
"@astrojs/mdx": major
---

Refactors the MDX transformation to rely only on the unified pipeline. Babel and esbuild transformations are removed, which should result in faster build times. The refactor requires using Astro v4.8.0 but no other changes are necessary.
5 changes: 5 additions & 0 deletions .changeset/friendly-plants-leave.md
@@ -0,0 +1,5 @@
---
"astro": minor
---

Exports `astro/jsx/rehype.js` with utilities to generate an Astro metadata object
5 changes: 5 additions & 0 deletions .changeset/large-glasses-jam.md
@@ -0,0 +1,5 @@
---
"@astrojs/mdx": patch
---

Allows Vite plugins to transform `.mdx` files before the MDX plugin transforms it
7 changes: 7 additions & 0 deletions .changeset/slimy-cobras-end.md
@@ -0,0 +1,7 @@
---
"@astrojs/mdx": major
---

Allows integrations after the MDX integration to update `markdown.remarkPlugins` and `markdown.rehypePlugins`, and have the plugins work in MDX too.

If your integration relies on Astro's previous behavior that prevents integrations from adding remark/rehype plugins for MDX, you will now need to configure `@astrojs/mdx` with `extendMarkdownConfig: false` and explicitly specify any `remarkPlugins` and `rehypePlugins` options instead.
5 changes: 5 additions & 0 deletions .changeset/small-oranges-report.md
@@ -0,0 +1,5 @@
---
"@astrojs/mdx": major
---

Renames the `optimize.customComponentNames` option to `optimize.ignoreElementNames` to better reflect its usecase. Its behaviour is not changed and should continue to work as before.
5 changes: 5 additions & 0 deletions .changeset/smart-rats-mate.md
@@ -0,0 +1,5 @@
---
"@astrojs/mdx": patch
---

Updates the `optimize` option to group static sibling nodes as a `<Fragment />`. This reduces the number of AST nodes and simplifies runtime rendering of MDX pages.
5 changes: 5 additions & 0 deletions .changeset/sweet-goats-own.md
@@ -0,0 +1,5 @@
---
"@astrojs/mdx": major
---

Replaces the internal `remark-images-to-component` plugin with `rehype-images-to-component` to let users use additional rehype plugins for images
5 changes: 5 additions & 0 deletions .changeset/tame-avocados-relax.md
@@ -0,0 +1,5 @@
---
"@astrojs/mdx": patch
---

Tags the MDX component export for quicker component checks while rendering
5 changes: 5 additions & 0 deletions .changeset/violet-snails-call.md
@@ -0,0 +1,5 @@
---
"@astrojs/mdx": patch
---

Fixes `export const components` keys detection for the `optimize` option
5 changes: 5 additions & 0 deletions .changeset/young-chicken-exercise.md
@@ -0,0 +1,5 @@
---
"@astrojs/mdx": patch
---

Improves `optimize` handling for MDX components with attributes and inline MDX components
2 changes: 2 additions & 0 deletions packages/astro/package.json
Expand Up @@ -209,6 +209,8 @@
"astro-scripts": "workspace:*",
"cheerio": "1.0.0-rc.12",
"eol": "^0.9.1",
"mdast-util-mdx": "^3.0.0",
"mdast-util-mdx-jsx": "^3.1.2",
"memfs": "^4.9.1",
"node-mocks-http": "^1.14.1",
"parse-srcset": "^1.0.2",
Expand Down
3 changes: 3 additions & 0 deletions packages/astro/src/jsx/babel.ts
Expand Up @@ -134,6 +134,9 @@ function addClientOnlyMetadata(
}
}

/**
* @deprecated This plugin is no longer used. Remove in Astro 5.0
*/
export default function astroJSX(): PluginObj {
return {
visitor: {
Expand Down

0 comments on commit ddd8e49

Please sign in to comment.