react / react/react

[Compiler Bug]: `Invariant: [InferMutationAliasingEffects] Expected value kind to be initialized` on passing reference to current function to other function

Open
#37,058 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Status: Unconfirmed Type: Bug
Dominant language
JavaScript
Stars
251k
Forks
51.4k
Avg merge
2d 4h
Merged PRs (30d)
53

Description

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/#N4Igzg9grgTgxgUxALhAgHgBwjALgAgDMoA7OXASwhPwFkBPAYQgFtsSETcAKASn2AAdGvhgJcsGgB4AEggA28iAHUc8gCb5qjeRTgBrALzA++QwD4Bw-DaIQI3YmUrV8AIwCGMU0JG38FIT43LQeuAAWAHQwHiTqrKaWkQCs-L7+-p4AXnwA3NYZAL74CmAIVn4ZAI5Q6NyeMLz5lTaFBa1NBYXFAPTmwm0kIAA0IHDUhBQA5igg6fg9PeNsFPJhVCS0EOoIyPiCIB6KBwMj4OEQAO4AklwIMCRHYCiETwiFQA

Repro steps

1: give react compiler this code

export function MyComponent() {
  return <HelloWorld onClick={() => {
    foo(function bar() {
      if (Math.random() > .5) {
        baz();
      } else {
        qux(bar);
      }
    });
  }} />
}

2: notice the following error

Found 1 error:

Invariant: [InferMutationAliasingEffects] Expected value kind to be initialized

<unknown> bar$5.

   5 |         baz();
   6 |       } else {
>  7 |         qux(bar);
     |             ^^^ this is uninitialized
   8 |       }
   9 |     });
  10 |   }} />
How often does this bug happen?

Every time

What version of React are you using?

the version in playground.react.dev

What version of React Compiler are you using?

the version in playground.react.dev

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked React Compiler playground and reproduce the error using the JavaScript snippet. Trace the [InferMutationAliasingEffects] failure at the qux(bar) reference, then verify that the same repro no longer reports an uninitialized value or invariant failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
compilers, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.