[Compiler Bug]: React Compiler bug: closure is lost in `useEffect` when component is returned from a factory (causes `ReferenceError: <identifier> is not defined`)
Author: budarinCreated Mar 23, 2026Updated Oct 1, 2026
LabelsType: BugStatus: Unconfirmed
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/budarin/react-compiler-bug-repro
Repro steps
- Create a Vite React TS project with React Compiler enabled.
- Use a factory function that returns a component and captures injected dependencies (e.g.
showWelcomeNotification) in a closure. - Inside the returned component, call the injected dependency in a
useEffect. - Run the dev server; a runtime
ReferenceErroroccurs.
How often does this bug happen?
Every time
What version of React are you using?
19.2.4
What version of React Compiler are you using?
1.0.0
Source: react/react