What kind of issue is this?
Link to repro
https://playground.react.dev/#N4Igzg9grgTgxgUxALhHCA7MAXABAFQRwGEIBbAB0wQzwF5cAKYXDKMgIwRlwF8BKXHQB8uYAB0MuXOix4A1ggCe+CAEkMAEwQAPIbihgEAEW4BLAG4JNANQCGAGygJGjQSMnTpAbQCMAGlwAJkCAZgBdADoyOwpXd1E2Bwd+T1x+AG5JNJgEbFgpJIcsjF4SkF4gA
Repro steps
Current version the Compiler started to transform react-native-reanimated API callbacks too much, breaking the code. I compared it with an older version babel-plugin-react-compiler@19.0.0-beta-9ee70a1-20241017 and the problem didn't happen there. It seems to be due to the enableFunctionOutlining feature.
Given the code:
const TestComponent = ({ number }) => {
const keyToIndex = useDerivedValue(() =>
[1, 2, 3].map(() => null)
);
return null;
};
Compiler changes it to
const TestComponent = (t0) => {
useDerivedValue(_temp2);
return null;
};
function _temp() {
return null;
}
function _temp2() {
return [1, 2, 3].map(_temp);
}
Note that _temp and _temp2 are extracted outside. It's ok to extract _temp2, the callback of useDerivedValue, it's handled on our side as a part of the support for the Compiler. It's not ok to extract _temp.
The problem lies in the fact that we can (and we do) deduce that _temp2 must be a worklet, but we cannot in general infer if _temp should be a worklet. This leads to _temp not being workletized and causing a runtime error. We also can't workletize it regardless, in some flows it actually shouldn't be a worklet.
To fix it we need to keep all functions defined in a worklet to stay in this worklet.
How often does this bug happen?
Every time
What version of React are you using?
19
What version of React Compiler are you using?
19.0.0-beta-bafa41b-20250307
What kind of issue is this?
Link to repro
https://playground.react.dev/#N4Igzg9grgTgxgUxALhHCA7MAXABAFQRwGEIBbAB0wQzwF5cAKYXDKMgIwRlwF8BKXHQB8uYAB0MuXOix4A1ggCe+CAEkMAEwQAPIbihgEAEW4BLAG4JNANQCGAGygJGjQSMnTpAbQCMAGlwAJkCAZgBdADoyOwpXd1E2Bwd+T1x+AG5JNJgEbFgpJIcsjF4SkF4gA
Repro steps
Current version the Compiler started to transform
react-native-reanimatedAPI callbacks too much, breaking the code. I compared it with an older versionbabel-plugin-react-compiler@19.0.0-beta-9ee70a1-20241017and the problem didn't happen there. It seems to be due to theenableFunctionOutliningfeature.Given the code:
Compiler changes it to
Note that
_tempand_temp2are extracted outside. It's ok to extract_temp2, the callback ofuseDerivedValue, it's handled on our side as a part of the support for the Compiler. It's not ok to extract_temp.The problem lies in the fact that we can (and we do) deduce that
_temp2must be a worklet, but we cannot in general infer if_tempshould be a worklet. This leads to_tempnot being workletized and causing a runtime error. We also can't workletize it regardless, in some flows it actually shouldn't be a worklet.To fix it we need to keep all functions defined in a worklet to stay in this worklet.
How often does this bug happen?
Every time
What version of React are you using?
19
What version of React Compiler are you using?
19.0.0-beta-bafa41b-20250307