Replies: 2 comments 2 replies
-
I plan to work on an upgrade to https://github.com/johnnyreilly/rehype-cloudinary-docusaurus - this is a reminder I need to do it |
Beta Was this translation helpful? Give feedback.
2 replies
-
I've been testing out the Docusaurus 3 beta which migrates to MDX 2. I have a couple of rehype plugins that improve core webvitals and serve images with cloudinary. This post walks through the migration for each plugin: https://johnnyreilly.com/docusaurus-3-how-to-migrate-rehype-plugins |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Docusaurus v3 is around the corner, coming with MDX v3.
Please use this discussion to ask questions about the creation of Remark or Rehype plugins using MDX v3, or the upgrade of existing plugins to support MDX v3.
Note:
Other useful support links
Before asking for support
To ask for support, please:
It's not scalable to provide done-for-you support for all Docusaurus users looking to upgrade. Any support request not respecting those constraints will possibly be ignored.
If you want help, you need to invest your own time so that helping you is easy.
Alternatively, you can look for a paid Docusaurus Service Provider to help you.
Useful notes for plugin authors
MDX v3 is a major MDX upgrade coming with breaking changes that impact your existing plugins.
It is probable that you will need to rewrite those plugins to support MDX v3.
It is outside the scope of Docusaurus to reach you everything about how to write Remark/Rehype plugins for MDX v1 vs MDX v3. If you successfully learned how to create a MDX v1 plugin, you will have to re-learn again and follow the same process to create a MDX v3 plugin.
We recommend using the MDX Playground extensively to understand how the new MDX AST works. By comparing the AST of your input, and the AST of your desired output, you can find out which AST transformations your plugins should perform.
ESM-Only support
MDX v3 and all newer versions of Unified/Remark/Rehype packages all use ESM only, and dropped support for CommonJS.
This has implications, and you will eventually need to use dynamic ESM imports in your plugin code, and/or your Docusaurus config (using CommonJS) to import those ESM modules.
An example:
If you write unit tests for your plugins, you must know that Jest does not support ESM. You can either use a tool that supports ESM, or vendor the dependencies you use as CJS.
Vendoring many small packages to get Jest to work is super annoying to do but it works, and is it what Docusaurus does:
New AST nodes
This new MDX version is much cleaner and stricter in how it represents JSX and ESM nodes in its AST.
For example, let's compare the AST o MDX v1/v3 for the same MDX file:
MDX v1 MDAST will look like:
MDX v3 MDAST will look like:
The first thing you should notice is that:
The new node types are documented on the mdast-util-mdx-jsx and mdast-util-mdxjs-esm repositories:
Plugin migration examples
Please tell us if you find good community examples, and we'll mention them here to help other plugin authors.
Beta Was this translation helpful? Give feedback.
All reactions