Skip to content

Conversation

@jackpope
Copy link
Contributor

@jackpope jackpope commented Dec 3, 2025

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.

@meta-cla meta-cla bot added the CLA Signed label Dec 3, 2025
@jackpope jackpope requested review from jorge-cab and mofeiZ December 3, 2025 22:38
Copy link
Member

@josephsavona josephsavona left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm on vacation but couldn't help but notice this one :-)

The logic to collect dependencies here significantly duplicates the logic I added recently in ValidateExhaustiveDependencies, but is also missing key pieces of that logic such as handling optionals. That means we're going to get a lot of incorrect results. Let's reuse the existing logic, and generalize if necessary. For example, we can likely consolidate the ManualMemoDependency and the InferredDependency type in that pass, and then reuse a significant percentage of the logic from the dependency extractor.

josephsavona added a commit that referenced this pull request Dec 4, 2025
Alternative approach to #35282 for validating effect deps in the compiler that builds on the machinery in ValidateExhaustiveDependencies. Key changes to that pass:

* Refactor to track the dependencies of array expressions as temporaries so we can look them up later if they appear as effect deps.
* Instead of not storing temporaries for LoadLocals of locally created variables, we store the temporary but also propagate the local-ness through. This allows us to record deps at the top level, necessary for effect deps. Previously the pass was only ever concerned with tracking deps within function expressions.
* Refactor the bulk of the dependency-checking logic from `onFinishMemoize()` into a standalone helper to use it for the new `onEffect()` helper as well.

A few important remaining todos:
* Add a new ErrorCategory for effect deps, use it for errors on effects
* Put the effect dep validation behind a feature flag
* Adjust the error reason for effect errors

Testing it locally on fixtures this looks ballpark right but i didn't do an exhaustive test.
@josephsavona
Copy link
Member

josephsavona commented Dec 4, 2025

@jackpope I put up an alternate take in ##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 added a commit that referenced this pull request Dec 4, 2025
Alternative approach to #35282 for validating effect deps in the compiler that builds on the machinery in ValidateExhaustiveDependencies. Key changes to that pass:

* Refactor to track the dependencies of array expressions as temporaries so we can look them up later if they appear as effect deps.
* Instead of not storing temporaries for LoadLocals of locally created variables, we store the temporary but also propagate the local-ness through. This allows us to record deps at the top level, necessary for effect deps. Previously the pass was only ever concerned with tracking deps within function expressions.
* Refactor the bulk of the dependency-checking logic from `onFinishMemoize()` into a standalone helper to use it for the new `onEffect()` helper as well.

A few important remaining todos:
* Add a new ErrorCategory for effect deps, use it for errors on effects
* Put the effect dep validation behind a feature flag
* Adjust the error reason for effect errors

Testing it locally on fixtures this looks ballpark right but i didn't do an exhaustive test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants