-
Notifications
You must be signed in to change notification settings - Fork 50.6k
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-hooks (build issue installing or using the eslint plugin)
- react-compiler-healthcheck (build issue installing or using the healthcheck script)
Link to repro
https://github.com/tryasko/test-react-compiler
Repro steps
Description
React Compiler compiles a component when 'use memo' is placed inside the function body, but does NOT compile the same component when 'use memo' is placed at the module level.
According to the documentation, module-level directives should apply to all functions in the file:
https://react.dev/reference/react-compiler/directives
"Place directives at the top of a file to affect all functions in that module."
However, in my setup, only function-level directives trigger compilation, while module-level directives are ignored.
Steps to reproduce
- Clone the repository: https://github.com/tryasko/test-react-compiler
- Install dependencies:
npm i - Run the compiler:
npm start - Inspect the generated files in the
outputdirectory.
Compilation result
| Component file | Directive level | Compilation | Expected result |
|---|---|---|---|
| component-a.jsx | no directive | Not compiled | ✅ Expected |
| component-b.jsx | function-level | Compiled | ✅ Expected |
| component-c.jsx | module-level | Not compiled | ❌ Not expected |
Expected behavior
React Compiler should compile components when 'use memo' is placed at the module level, the same way it does when the directive is placed at the function level.
Specifically, the output for component-c.jsx should include React Compiler transformations, such as:
import { c as _c } from "react/compiler-runtime";How often does this bug happen?
Every time
What version of React are you using?
19
What version of React Compiler are you using?
1.0.0