[Compiler Bug]: #31396
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/#N4Igzg9grgTgxgUxALhASwLYAcIwC4AEwBUYCAsghhADQlkBKCAZnaQgMICGANjwEZc4AawIBfAsxgQMBADogYCIXgUBuOQDtMOfEQJ4AFtLx4eCcZOmyFPCABMuYQ+q1aEAD12F7LLlB5CZihNODw0CE0CcgBPAEEsLAAKAEoiLQICOEiwQiVmAgBeegQmZlSNKIysnMIjEzMEewAxCDhSIpLKaiTqzNSigD4+zINjCFNzXqjR2YHCwYJ8gDp2mCVNPAB+ZeY20lSaEdmAVgAGM6OZ2czgY5vzLns0TQBzZEleMiubm7wYLhoHgvd4GGBQBA-X7iKGzFKwggAbT27TAAF0oSlKtV2ABRZjMBBhJLzRbAeoTRotfZgVJiOiIimTJqtVFolJuGZKPCwKIAHmeADclixCsB8mJBgAJBB8CAEADquB49j5AHohYNKmItCAxEA
Repro steps
The compiler assumes that
ref.current
is called during render when inside ofuseMemo()
, even whenuseMemo
is returning a callback that is only called in auseEffect
and never during render. See playground for the code.The most common use case for specifying a callback with
useMemo
instead ofuseCallback
, is when the callback is wrapped in a debouncing technique, likelodash/throttle
:It's as if the compiler isn't differentiating the closure that returns the memoized value (and thus is indeed firing during render), and
useMemo
returning a callback 🤔How often does this bug happen?
Every time
What version of React are you using?
^18.3.1
What version of React Compiler are you using?
19.0.0-beta-6fc168f-20241025
The text was updated successfully, but these errors were encountered: