Skip to content

[Compiler]: flags mutations of shared mutable refs and skips optimizations #33209

Open
@szhsin

Description

@szhsin

What kind of issue is this?

  • 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-compiler (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/#N4Igzg9grgTgxgUxALhASwLYAcIwC4AEwBcMCAhnggMIQB2VAHngDQFRgIBKCAZmxxr0mhAL4FeMCBgIAdEGXJw88gNyy6GuPTCFaUBghg9etQ8wIBeEoqpmRACgCU6zXW11dBAGIQIVgmcrAD4iDQISHUJtAypjPgDBewRmB31DeNNhFLwXDXCCMjxYOkCCiIAeACMoPDx6coiCemoAGzQ4AGtLYCDLUOBGpoI0XkCYjJMnSNijEwA6OFgyBgIAamsARldhiNFRRuChggBBABMzxoqAehq6+iPSgjy6UVcNFJx8SM9CE6wsAE+gMCtdrgQAMoAC3IZDObAwtXIVVaCAIdHoAFoAKoASQIADdyK0oAhQeCIfU4SNSuRCgl6gRyASIGgzgQ8DA0ABzblGemYlZnIxoOjcggAdyhCFKeGlhOJpJIMLFCDABQ8XgmcRMiU4JgcAAYXgUiiUyk9KukdXxksx5gAFKQEtn8okkhA9bVzPiiR67AgVXz+a7+3ZBvwEUPHCMhsOVa7Wn1Zcx4R3O10wMMvN4aECiIA

Repro steps

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.

How often does this bug happen?

Every time

What version of React are you using?

19.1.0

What version of React Compiler are you using?

19.1.0-rc.1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions