react icon indicating copy to clipboard operation
react copied to clipboard

[compiler] Add validator for extraneous effect deps

Open jackpope opened this issue 3 months ago • 1 comments

This PR adds a new validator behind the validateExtraneousEffectDependencies config option, default false. This is an experimental error log to flag the over-inclusion of values in the effect dep array that are not used by the effect.

This is implemented as a React Compiler Validator for now rather than as part of the eslint rule so that we can roll it out more carefully without affecting the existing rule and suppressions.

We've always had some amount of trouble with this, with people "watching" unrelated values instead of moving the logic into the event that affected those values. But increasingly with useEffectEvent we're seeing values captured by the Effect Event included here without additional use. We expect them instead to be passed as arguments to the Effect Event.

Additionally, there's some general effect usage by LLMs that will add extraneous deps. This allows us to flag that result for correction while we work on better context to prevent it from happening altogether.

jackpope avatar Dec 03 '25 22:12 jackpope

@jackpope I put up an alternate take in #https://github.com/facebook/react/pull/35285 - I had actually started hacking on this before going on vacation but got stuck, took another look today and figured it out quickly.

josephsavona avatar Dec 04 '25 08:12 josephsavona

Closing in favor of #35285

jackpope avatar Dec 05 '25 15:12 jackpope