-
Notifications
You must be signed in to change notification settings - Fork 50k
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
If you want to reassign props (not modify), and use them in a callback function, React Compiler will skip compiling the component. For example:
export default function Component({ foo, bar }) {
if (!foo && !bar) {
foo = "foo";
}
return (
<div>
{Array.from({ length: 3 }, (_, i) => <div key={i}>{foo}</div>)}
</div>
);
}I got this error:
Todo: Support destructuring of context variables
You can also replace the if statement if (!foo && !bar) { foo = "foo"; } with the content itself foo = "foo";, that will also trigger the issue, however it is meaningless.
The modified prop must in a callback, directly use it will work fine. For example, <div>{foo}</div> works fine, and <div>{(() => foo)()}</div> raise an issue.
I think the code above should be automatically converted into the code below which can work properly. Although I can also use the code below directly, it will only cause more trouble.
export default function Component({ foo: _foo, bar }) {
let foo = _foo;
if (!foo && !bar) {
foo = "foo";
}
return (
<div>
{Array.from({ length: 3 }, (_, i) => <div key={i}>{foo}</div>)}
</div>
);
}How often does this bug happen?
Every time
What version of React are you using?
19.2.1
What version of React Compiler are you using?
1.0.0
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