kentcdodds / mdx-bundler

🦤 Give me MDX/TSX strings and I'll give you back a component you can render. Supports imports!
MIT License
1.78k stars 75 forks source link

Externalize all React entrypoints to support React 19 #229

Open eps1lon opened 5 months ago

eps1lon commented 5 months ago

What:

Fixes compatibility with React 19. We're using mdx-bundler in vercel.com, https://nextjs.org/ and various other Vercel surfaces. We're using this patch in production already. Otherwise we couldn't use React 19.

Why:

Bundling the JSX runtime always worked incidentally even though it was never officially supported. Due to changes to the React secret internals, we now enforce not bundling parts of React while externalizing others. Either you bundle everything or none.

How:

Externalize all React entrypoints

Checklist:

eps1lon commented 3 months ago

It's not an optimization but a bug fix. mdx-bundler currently bundles the jsx-runtime which isn't supported (it's like bundling React itself). This worked because all supported versions of React were compatible with the bundled JSX runtime. However, React 19 is not compatible with the bundled JSX runtime.

Publishing a new version with an updated version of React 19 will not fix the issue since that would make mdx-bundler incompatible with React <19. By externalizing the JSX runtime, you're compatible with any React version.

It's not a breaking change if you use this library as documented i.e. use mdx-bundler/client. It is breaking if you inlined mdx-bundler/client since you'd now need to update it.

kentcdodds commented 3 months ago

Hmmm.... Looks like this is failing the tests 🤔

eps1lon commented 3 months ago

I'll take a look later