[Compiler Bug]: Compiler incorrectly removes memoization of an expensive operation in useMemo #29892
Open
1 of 4 tasks
Labels
Component: Optimizing Compiler
Status: Unconfirmed
A potential issue that we haven't yet confirmed as a bug
Type: Bug
What kind of issue is this?
Link to repro
https://playground.react.dev/#N4Igzg9grgTgxgUxALhAMygOzgFwJYSYAEUYCAsgJ4ASEEA1gBQCGAlEcADrFFyFg4iaOkQC8JMuQQBbCI0btRAPg7ci63v0GRpCHAAs8mAOZiiCAB4AHBJjB4AbghasA3Go0w9sYsyIBqIh09QxN3HgBfABoiAG1mAF1WDy8cHyE6cIiQCKA
Repro steps
The compiler seems to incorrectly erase memoization of possibly expensive operations using
useMemo
in some cases.Compare the compiler output of the two similar examples, in the first all memoization will be replaced, in the 2nd it will be correctly added in
I believe this is a byproduct of how memoization is dependent on the
return
value.Another side effect of that decision (although already a rule break) is that someone incorrectly using
useMemo
instead ofuseEffect
would likely force that effect to run every render (regardless of their deps array that would normally prevent it)How often does this bug happen?
Every time
What version of React are you using?
v17.0.2
The text was updated successfully, but these errors were encountered: