-
Notifications
You must be signed in to change notification settings - Fork 50.2k
Open
Labels
Status: UnconfirmedA potential issue that we haven't yet confirmed as a bugA potential issue that we haven't yet confirmed as a bugType: Bug
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
Repro steps
- Open the React Compiler Playground with this code: LINK
- The code defines a factory function createBindings() that returns React components. Inside the factory:
- InnerComponent is defined as a simple functional component
- OuterComponent uses InnerComponent inside a .map() callback - Observe the compiled output - the .map() callback is extracted to a module-scope function _temp:
function _temp(item) {
console.log("InnerComponent:", typeof InnerComponent);
return <InnerComponent key={item} value={item} />;
}- _temp references InnerComponent, but InnerComponent is defined inside createBindings() - not at module scope.
The closure is broken. - At runtime, InnerComponent is undefined inside _temp, causing: Error: InnerComponent is not defined
Expected behavior:
The compiler should either:
- Keep the callback inline to preserve the closure
- Hoist captured variables along with the extracted function
- Skip compilation for callbacks that close over locally-scoped values
Workaround:
Adding 'use no memo' to OuterComponent prevents the callback extraction and preserves the closure.
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
Krish-vadsak45
Metadata
Metadata
Assignees
Labels
Status: UnconfirmedA potential issue that we haven't yet confirmed as a bugA potential issue that we haven't yet confirmed as a bugType: Bug