-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
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
feat: upgrade to MDX v2 #8288
feat: upgrade to MDX v2 #8288
Conversation
site builds but no content :s
✅ [V2]
To edit notification comments on pull requests, go to your Netlify site settings. |
⚡️ Lighthouse report for the deploy preview of this PR
|
Size Change: +148 B (0%) Total Size: 1.01 MB
ℹ️ View Unchanged
|
Note the docs says:
https://mdxjs.com/docs/what-is-mdx/ Problem - Heading anchor syntax
|
# Conflicts: # packages/docusaurus-theme-mermaid/package.json # yarn.lock
Struggling to upgrade your site to MDX v2? Here's a discussion to ask for support: #9053 |
Just linking in a related issue here: #9081 (comment) I'd love to see a guide on how to migrate remark / rehype plugins to Docusaurus v3 / MDX v2
It sounds like the docs may exist - but not yet be visible! |
Motivation
Docusaurus v3 will upgrade MDX to v2
It is much better to work with than v1 for many reasons explained here: https://mdxjs.com/blog/v2/
MDX v2 also exposes a better infrastructure for Docusaurus to build new useful features, and optimize performances.
Fix #4029
Also makes it possible to support a CommonMark mode (opt-in), requested in #3018, but by default we still use MDX (even on
.md
files, see also #9097)Need support to upgrade to MDX v2? See MDX v2 Upgrade Support
Other notable changes:
::myDirective
if you want.Breaking changes
Breaking changes coming from MDX v2 itself, notably:
<pre>
or<code>
will render as isBreaking changes coming from Docusaurus public APIs:
.md
and.mdx
can be handled differently if you opt-in for CommonMark ({/* truncate */}
for.mdx
files (➡️ compat option provided)docs.admonitions.tag
option is removed, we can now only use:::
(markdown directive syntax)docs.admonitions.extendDefaults
option is nowtrue
by default (merge default+user-provided admonition keywords instead of replacing them)mdx-code-block
workaround for Crowdin is implemented in a very different way. It still works in most cases but we recommend to not use this anymore and put complex React components outside of MDX files.Notable private API changes:
options.markdownConfig
to be provided (see also docs: document siteConfig.markdown + better mdx-loader retrocompat #8419)Compatibility options
Site config
We have a few options to keep Docusaurus v3 more retro-compatible with v2 features, that are for now turned on by default.
The goal is to give you the opportunity to progressively adopt a stricter MDX syntax.
This is important to aim for MDX compatibility, so that other tools understand your files: GitHub, VSCode, Prettier, ESLint, Crowdin... You will have to progressively turn these flags off to do so.
MDX vs CommonMark
By default, Docusaurus v3 will still compile all files as MDX (like Docusaurus v2 did), but it is possible to opt-in for CommonMark parser (does not allow usage of JSX).
You can do so:
siteConfig.markdown.format: 'detect'
(will use CommonMark for.md
files and MDX for.mdx
files)format: 'md'
Note: some Docusaurus features currently don't work yet in CommonMark, make sure to test this issue before adopting this new mode: #9092
Follow-up
Things to handle later, after this PR is merged:
{/* headingId */}
) ❌.md
and.mdx
format? ✅ feat(mdx): add siteConfig.markdown.format to configure the default content parser (MDX / CommonMark) #9097format
setting? ✅ feat(mdx): add siteConfig.markdown.format to configure the default content parser (MDX / CommonMark) #9097.mdx
? 🤷♂️components={{theme}}
and use<theme.Tabs/>
? ➡️ Make most features work in CommonMark mode: head, live code blocks, tabs... #9092Tests
We have many unit tests to ensure the behavior is similar to what it used to be.
We also started using visual regressions tests, comparing visually each page from our sitemap to detect potential regressions. The setup is quite hacky (using an external repo for now) but you can take a look here:
Some review links:
Other Relevant links: