-
Notifications
You must be signed in to change notification settings - Fork 49.1k
Closed
Labels
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
Bug Description
Context providers update state correctly, but consumers receive stale values when using React Compiler. Works without the compiler.
Repro: Click "Open Dialog" button
Expected: Dialog shows "Modal open!"
Actual: Dialog stays "Modal is closed" despite provider logging isOpen: true
Root Cause
The React Compiler incorrectly optimizes hooks called through namespace exports with .use()
property names:
Broken: Modal.use()
→ Entire hook result cached, never re-evaluated
// Compiled output - WRONG
const ModalDialog = () => {
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = Modal.use(); // Only called once
$[0] = t0;
} else {
t0 = $[0]; // Uses stale cached value
}
const { close, isOpen } = t0;
Working: Modal.useModal()
→ Individual values tracked correctly
// Compiled output - CORRECT
const ModalDialog = () => {
const { close, isOpen } = Modal.useModal();
if ($[0] !== close || $[1] !== isOpen) { // Proper dependency tracking
$[0] = close;
$[1] = isOpen;
}
Workaround
Use any property name other than .use()
in namespace exports.
How often does this bug happen?
Every time
What version of React are you using?
19.1.0
What version of React Compiler are you using?
19.1.0-rc.2