Skip to content

[Compiler Bug]: React Compiler silently skips custom hooks whose only hook call is use() #35960

@carlbergman

Description

@carlbergman

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-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/#N4Igzg9grgTgxgUxALhASwLYAcIwC4AEwBcMCAhnggMIQB2VAHngDQFRgJsc31OEBfAgDMYEDAQDkZcnDySA3AB06KuPTCEAsgE9aDBMwIBeEjKr7+BADxECAN3IAbKAmQFNMNHQDmBIQB8BAAUdFBOTgCEAJTKqnSGOPgiUHRyaPTsnLqWhngA6mh4ABYAqpzB0UQqBCQahMSOLgj+JlkIwTl8ebE1BGR4sHR2Ta7+cQIqKom4hMKp6Zk8XQbMhSXlvKt4ldXDdXSaI85jQqY8ucydet3MvfsDQ8fN4yoCICwg6nTCaD4o6GwswIeB0WBaxAACi4fN4APJYPAZQ6tUTiKQAI3IGIQTgAtFgYd48TI5Hj1Ng0E4EDAAPQAEzQmkUUzowWAfVptIpWCplGRWgg9LcBCUIGcTjFbw8-LAvwQYAI0KgsLoCKRGliH3AxQgAHcAJIGGB0ZxgFDCM0IARAA

Repro steps

  1. Create a context MyContext and a custom hook useMyContext that only calls use(MyContext)
  2. Compile in the default infer compilation mode.
  3. Observe that useMyContext is silently skipped by the compiler, no memoization is applied.
  4. Change use(MyContext) to useContext(MyContext), the compiler now recognizes the function as containing a hook call and compiles it correctly.

How often does this bug happen?

Every time

What version of React are you using?

19.2.4

What version of React Compiler are you using?

babel-plugin-react-compiler 1.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: UnconfirmedA potential issue that we haven't yet confirmed as a bugType: Bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions