-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
fix(angular-query): do not run callbacks in injection context #8817
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
fix(angular-query): do not run callbacks in injection context #8817
Conversation
View your CI Pipeline Execution ↗ for commit a0503de.
☁️ Nx Cloud last updated this comment at |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #8817 +/- ##
===========================================
+ Coverage 46.45% 88.36% +41.91%
===========================================
Files 199 16 -183
Lines 7567 275 -7292
Branches 1740 44 -1696
===========================================
- Hits 3515 243 -3272
+ Misses 3672 31 -3641
+ Partials 380 1 -379
🚀 New features to boost your workflow:
|
@arnoud-dv This is not anty-pattern. It is normal angular code, where almost everything in Angular is based on DI. You can even pass injector to https://angular.dev/api/core/CreateEffectOptions 🚨 Rollback this PR it is breaking our codebase. If it were an anti-pattern, then https://angular.dev/api/core/runInInjectionContext would not exist. You can even see how NgRx Signal Store is allowing for that https://ngrx.io/guide/signals/signal-store#reactive-store-methods |
As the callback functions of
injectQuery
andinjectMutation
were run in the injectionContext, usinginject
in these functions was possible. This is an anti-pattern in that it turns dependency injection into service locator. The Angular framework itself does not run callbacks in the injection context. Consider e.g. lifecycle hooks or callback functions on APIs such aseffect
orcomputed
.Running these callbacks in the injection context adds complexity to the adapter, and it wasn't consistent between callbacks, e.g. queryFn did not run in the injection context. Making it consistent by running other callbacks in the injection context too would require adding a lot more complexity.
To prevent the anti-pattern and to be consistent with the Angular framework and remove unnecessary complexity from the adapter the code changes in this PR will ensure callbacks are no longer run in the injection context.
Closes #8714