Skip to content

[Compiler Bug]:Compiler doesn't memoize if const is between hooks #35355

@pritjasani08

Description

@pritjasani08

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/#N4lgzg9grgTgxgUxALhAejQAgLIILYQCWAXggCaYBGAnpgEolCGc

Repro steps

  1. Open the React Compiler Playground link: https://playground.react.dev/#N4lgzg9grgTgxgUxALhAejQAgLIILYQCWAXggCaYBGAnpgEolCGc
  2. Observe the code that has a const declaration between React hooks
  3. Check the compiled output - you'll see that memoization is not working correctly
  4. The compiler should memoize values even when const is between hooks, but it currently doesn't

How often does this bug happen?

Every time

What version of React are you using?

Latest (React 19 or main branch)

What version of React Compiler are you using?

Latest babel-plugin-react-compiler from main branch

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