Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/client.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react'
import * as _jsx_runtime from 'react/jsx-runtime'
import * as _jsx_dev_runtime from 'react/jsx-dev-runtime'
import * as ReactDOM from 'react-dom'

/**
Expand All @@ -26,7 +27,13 @@ function getMDXComponent(code, globals) {
*
*/
function getMDXExport(code, globals) {
const scope = {React, ReactDOM, _jsx_runtime, ...globals}
const scope = {
React,
ReactDOM,
_jsx_runtime:
process.env.NODE_ENV === 'production' ? _jsx_runtime : _jsx_dev_runtime,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is likely moot since you ship CJS which bundlers have a hard time tree-shaking. But once it's shipped as ESM, bundlers will be able to DCE react/jsx-dev-runtime in prod

...globals,
}
// eslint-disable-next-line
const fn = new Function(...Object.keys(scope), code)
return fn(...Object.values(scope))
Expand Down
8 changes: 8 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,14 @@ async function bundleMDX({
varName: '_jsx_runtime',
type: 'cjs',
},
'react/jsx-dev-runtime': {
varName: '_jsx_runtime',
type: 'cjs'
},
'react/compiler-runtime': {
varName: '_react_compiler_runtime',
type: 'cjs'
}
Comment on lines +206 to +209
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't necessary for React 19 compat. But if you ever apply the React compiler, you need to externalize its runtime so I just went ahead and did it now to avoid future bugs.

}),
// eslint-disable-next-line new-cap
NodeResolvePlugin({
Expand Down