[Compiler Bug]: Memoization depends on how the order of the lines of code
What kind of issue is this?
- [x] 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://playground.react.dev/#N4Igzg9grgTgxgUxALhAgHgBwjALgAgDMoA7OXASwhPyjAQDEIIAKCgE2XzFxgpIDmASnzAAOjXxxqPfACMAhjHwBeWvQBCSlkIDcE-FJkEAbgoA2UBKqKk4LRTD0SDRkrOD52C3AvwBfGzoELQAvFghMShk2diFnSWl3Aj81GAQwKHNcFm9fABp8M0sEBNdXdNxYGgV9En8QfJAkwgoBFBAKAFtsPHxcAE9Ma08ABUsBfgB5KKp3AKIYCC78AHJFOQRzAFpMCf5t9IVybekeinMEGAB6dgoeVbqJFnFJa+uzzAufOYBZCHYCC4YhAFnMIIkgTAPzArQy+HGUEmJBm0Xceka4AAFhAAO4ASRIuCuJAsYBQvCs-iAA
Repro steps
The output of the linked code skips memoization of func(bar) and result(data, value), but if line 3 (const value = func(bar);) is moved down below the useBaz call, the memoization happens as expected.
I would expect this code to be memoized regardless of the order of the lines.
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
I was going to report the same bug. I came up with these examples while investigating
take particular notice of the shouldBeMemoized variable in the generated code.