×

注意!页面内容来自https://www.mdxjs.cn/blog/v3/,本站不储存任何内容,为了更好的阅读体验进行在线解析,若有广告出现,请及时反馈。若您觉得侵犯了您的利益,请通知我们进行删除,然后访问 原网页

Skip to navigation
2-3 minutes read
By Titus Wormer

Note: Info on how to migrate is available in our Version 3 migration guide.

MDX 3

Version 3 already! This major version contains a couple small changes. For most folksupdating Node. and plugins is all that’s needed!

Contents

Breaking changes

The main breaking change is that Node. 16 is now the minimum supported version.

Across the ecosystem there were several small internal breaking changes. Everything’s released already. You can update all plugins now. If you ran into problems beforeit should work now.

We also removed some infrequently used deprecated APIs. You’re likely fine but gloss over the v3 migration guide if you get errors.

Important to note when you use your lesser-known but powerful evaluaterunor outputFormat: 'function-body' APIsplease pass the baseUrl option. That makes sure import.meta.urlimportand export work. You’ll get a runtime error when those features are used otherwise.

Improvements to the MDX format

There’s also a few small improvements to the MDX formatsome of which technically breaking.

Adjacent block JSX and expressions in MDX

We now accept block expressions right next to block JSX tags:

<>{`

  h1 {
    color: blue;
  }

`}</>

Previouslythere was a syntax errorand you had to add a newline between the angle brackets and the braces.

Await in MDX

We now accept await syntax:

MDX
{await Promise.resolve(42)}

Most frameworks don’t support promises. Whether this works depends on that.

Previouslythere was a runtime error that await was used in a context where it wasn’t allowed.

ES2024 in MDX

You can now use modern JavaScript syntax in MDX. Acornused internallyis now instructed to use ES2024.

Miscellaneous

I refactored all the docs. Updating every use example where needed. I also wrote a guide on how to inject components from anywhere: § Injecting components.

The site is a lot faster. There’s a nice improved playground too: try it out! ». We also have proper syntax highlighting herethanks to wooorm/markdown-tm-language and wooorm/starry-night.

The generated JS code is a little cleaner (the JSX pragma comment is removed and objects are sorted where needed)it also uses spreads instead of Object.assignthere’s a 'use strict' added when neededand the MDXContent is exported immediately.

Thanks

We’d like to say thanks to all our contributors and our happy users. Special thanks to 北雁云依 (@BeiyanYunyi)Christian Murphy (@ChristianMurphy)JokcyLou (@Jokcy)Maël Nison (@arcanis)Andreas Deininger (@deining)Remco Haszing (@remcohaszing)Sébastien Lorber (@slorber)Víctor Fernández (@victor23k)Titus Wormer (@wooorm)and anyone we may have forgotten.