-
Notifications
You must be signed in to change notification settings - Fork 49.8k
Open
Description
What kind of issue is this?
- React Compiler core (the JS output is incorrect, or your app works incorrectly after optimization)
- babel-plugin-react-compiler (build issue installing or using the Babel plugin)
- eslint-plugin-react-compiler (build issue installing or using the eslint plugin)
- react-compiler-healthcheck (build issue installing or using the healthcheck script)
Link to repro
Repro steps
Paste the following MDX output into the React compiler playground:
/*@jsxRuntime automatic*/
/*@jsxImportSource react*/
import { useMDXComponents as _provideComponents } from 'user-provided-provider-import-source'
function _createMdxContent(props) {
const _components = {
em: 'em',
p: 'p',
..._provideComponents(),
...props.components
}
return (
<_components.p>
<em>{'emphasis'}</em> <strong>{'Strong'}</strong>
</_components.p>
)
}
export default function MDXContent(props = {}) {
const {wrapper: MDXLayout} = {
..._provideComponents(),
...props.components
};
return MDXLayout ? (
<MDXLayout {...props}>
<_createMdxContent {...props} />
</MDXLayout>
) : (
_createMdxContent(props)
)
}When compiling MDX to JavaScript, the React compiler fails to optimize its output. MDX produces 2 functions: MDXContent and _createMdxContent. The React compiler processes MDXContent, even though there’s not much to optimize. However, it fails to optimize _createMdxContent, which contains all of the MDX content the user wrote. I think it could be a huge win if that component gets optimized. The problem is that React compiler doesn’t optimize components whose name start with an underscore. MDX uses the underscore prefix for private helper variables. I see 3 solutions:
- React compiler handles functions whose name start with an underscore. JSX transforms treat them the same as uppercased variables anyway.
- We handle this in MDX. This isn’t great. We prefer to not incorporate React specific transforms.
- We rename
_createMdxContent. This isn’t great, as the underscore indicates the function is private. Also this may break existing third party plugins. - We add a
'use memo'directive in_createMdxContent. This isn’t great, because it’s specific to React.
- We rename
- Someone creates a custom plugin to implement 2.1 or 2.2. This isn’t great, because this means users need to add this plugin manually.
IMO it would be great if React compiler implements solution 1.
How often does this bug happen?
Every time
What version of React are you using?
19.2.0
What version of React Compiler are you using?
1.0.0