[compiler] Add validator for extraneous effect deps#35282
Closed
jackpope wants to merge 1 commit intofacebook:mainfrom
Closed
[compiler] Add validator for extraneous effect deps#35282jackpope wants to merge 1 commit intofacebook:mainfrom
jackpope wants to merge 1 commit intofacebook:mainfrom
Conversation
josephsavona
reviewed
Dec 4, 2025
Member
josephsavona
left a comment
There was a problem hiding this comment.
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.
3 tasks
Member
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.
Contributor
Author
|
Closing in favor of #35285 |
jackpope
added a commit
that referenced
this pull request
Dec 8, 2025
#35285) 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. * 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 --------- Co-authored-by: Jack Pope <jackpope1@gmail.com>
github-actions bot
pushed a commit
that referenced
this pull request
Dec 8, 2025
#35285) 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. * 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 --------- Co-authored-by: Jack Pope <jackpope1@gmail.com> DiffTrain build for [ec9cc00](ec9cc00)
github-actions bot
pushed a commit
that referenced
this pull request
Dec 8, 2025
#35285) 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. * 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 --------- Co-authored-by: Jack Pope <jackpope1@gmail.com> DiffTrain build for [ec9cc00](ec9cc00)
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds a new validator behind the
validateExtraneousEffectDependenciesconfig option, defaultfalse. 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
useEffectEventwe'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.