You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Compiler]: flags mutations of shared mutable refs and skips optimizations #33209
Sometimes you need a shared, mutable value that isn’t tied to the UI but is used across multiple components. In these cases, you don’t want React to trigger re-renders when the value changes. To handle this, you can store the value in a ref and pass it down through context.
However, when a child component mutates this value (for example, inside an event handler), the compiler currently produces an error and causes optimizations to be skipped. I feel this is too restricted for what is otherwise a legitimate React pattern.
Thanks for posting. This is occurring because we are currently very conservative about what we assume is a ref. I think the correct thing is to treat identifiers which look like refs as if they were refs (ref or -Ref suffix). We have a compiler flag for this that we should turn on.
#34005 enables the flag to treat ref-like identifiers as refs by default. As long as your variable is named ref or ends in Ref (myRef etc), the compiler will treat it as a ref. Thanks again for posting!
Activity
josephsavona commentedon Jun 23, 2025
Thanks for posting. This is occurring because we are currently very conservative about what we assume is a ref. I think the correct thing is to treat identifiers which look like refs as if they were refs (
refor-Refsuffix). We have a compiler flag for this that we should turn on.josephsavona commentedon Jul 29, 2025
#34005 enables the flag to treat ref-like identifiers as refs by default. As long as your variable is named ref or ends in Ref (myRef etc), the compiler will treat it as a ref. Thanks again for posting!