Skip to content

[Compiler Bug]: React Compiler conditionally memoize a function depending on the order of statements before it #35569

@refparo

Description

@refparo

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/#N4Igzg9grgTgxgUxALhAgHgBwjALgAgDMoA7OXASwhPyjAQDEFc4ALBGAZVxwQAp6uSiQDmYfAF58wAL4BKaQB0a+ONTAFgRZmw4AafADpjhHey7NhY-DMn5BVsAG5ly-KvUEEJAG4UY1AC23rhMLOZ2dIxmHHxyLiRu+DDMsDTEZHym4fraORZCFKJgBt5+ASTBJKExMPHKMiB6IGokhBQiKCAUgdh4+LgAnpgI0vgACgA2UCJFAPKYlOo2RAGB+ADkAEYAhlsIkwC0mNOzJIcpO+SHar0UkxwA9AAmFBobCcp8wEmPj7eYe47JYkACyEGeCGQ+EUIB2k0msIa9mBb3aCHEUxm80WVBIYHiTXArAgAHcAJLVDgkeFgFCEWkIGRAA

Repro steps

  1. See the playground link, where the func call at line 6 isn't memoized.
  2. Swap line 2 and line 4, and see that func call becomes memoized now.

Why does the different order of statements before the func call affect whether the func call is memoized? I'm expecting the func call to be memoized in both cases.

How often does this bug happen?

Every time

What version of React are you using?

Both 19.2.3, and whatever the playground is using

What version of React Compiler are you using?

Both babel-plugin-react-compiler@1.0.0, and whatever the playground is using

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