Skip to content

[Compiler Bug]: "This dependency may be mutated later" error is inconsistent #34924

@cauthmann

Description

@cauthmann

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/#N4Igzg9grgTgxgUxALhAgHgBwjALgAgDMoA7OXASwhPwGEIBbbEhE3ACgEp9gAdG-LxBQwCfCQj4GCBhCEBufAHol+AMqUANpvwIYMHGH758camAIBDfAF4plgNYIA+hABGAKwTku8-sdNzAggHAEZbfEsAOnQ-ATMSC119HHC7SwB+GLiTBKS9AxgAJgjrDMiY-GR8AAYcwMSCApwAZgjCCAh2aPROerymlJgAFnbO7r6AgfwQkvSs9HwAalrFFXwAdxwHSwNSABMiHHxMGAoGCkoANzFcAE9MBCMSKaCpGQgKAC8EQ7sRBAAWQ+7C4tgAfDwAiYYAhcLAaM0YOEVkiSqihm0MYVRisQiiZg4ivUAL4AGnwAG0kaEKWi6ZiGTiKfiWUSALqTATrfAAPX5ApMAsFfOFvKFYoCPIAKgALChgfD7BCPEjKsh3eyatxiWT7CiECi-fCaSy4PT+bmqADiMEsbF+FNhlnIgSYFE0ei14ggBAcEg2kTc0AIuFlYkwsEudyiUtUACEoKHw7CAOSKyyaSA+zaWTW4STm7T4S6xgSegiLOyR2HOYhkSjUboU6Syb6-LkBWHwmA0AA8+qu4OA6BJfaUg-BcRJlvr5CoNBrLjnjZIzak3D4VqVECePoIeoNmusxwY-BJIDJIAShoA5igQOdsHh8PdHjx8AAFTRQW8UEgAPKYKuiokkQBgMPgqZuJYOqaAAtJgP5-iQ8HOuQ8FmO6nowBOCq4KmcT8OwW4mCoWGYB6ZoLoCEDKtUQiZpoQjnvgYDUWAhp7t+v7-kBIF9Je4CyhAGwAJIOr2mZgCghDSQgJJAA

Repro steps

The code in the playground link follows the Rules of React, but the react compiler emits a very defensive error.

The obvious bug is that ok1 doesn't trigger the error even though it could get mutated just like the others.

But this is also a false positive; the code is fine. It's not pretty, but it is correct. There's no obvious way to fix this and no documented escape hatch.

It was also way too time consuming to debug and reduce to a testcase. Maybe I'm spoiled by the rust compiler, but I'd like to see a better error message:

error1 references a value contained in a declared in line xxx, which may be mutated later by a call to pure_function in line xxx.

How often does this bug happen?

Every time

What version of React are you using?

19.2

What version of React Compiler are you using?

latest on the playground

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