Skip to content

Conversation

@josephsavona
Copy link
Member

@josephsavona josephsavona commented 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.

Feel free to commandeer and edit :-)

@meta-cla meta-cla bot added the CLA Signed label Dec 4, 2025
@github-actions github-actions bot added the React Core Team Opened by a member of the React Core Team label 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 Author

Spot checking the test failures they look mostly legit, lots of cases where our test fixtures have non-exhaustive deps.

) {
// NOTE: this relies on reactivity inference running first
validateExhaustiveDependencies(hir).unwrap();
validateExhaustiveDependencies(hir, env).unwrap();
Copy link
Member Author

Choose a reason for hiding this comment

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

The hir has access to its environment, so you don’t need to pass it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed React Core Team Opened by a member of the React Core Team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants