-
Notifications
You must be signed in to change notification settings - Fork 50k
[compiler] Add validator for extraneous effect deps #35282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
josephsavona
left a comment
There was a problem hiding this 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.
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.
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.
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.