-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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(signals): use Injector
of rxMethod
instance caller if available
#4529
fix(signals): use Injector
of rxMethod
instance caller if available
#4529
Conversation
✅ Deploy Preview for ngrx-io canceled.
|
c207a69
to
7286585
Compare
Ensure that an instance of `rxMethod` uses the `Injector` of the caller where the instance was invoked, rather than the injector of the node where `rxMethod` was created. This change addresses a potential memory leak where a `SignalStore` method, generated by `rxMethod` and provided at the root level, continues to track a signal via its `effect` using the `RootInjector`. In cases where the component calling the method is destroyed, the `Signal` remains tracked, leading to unintended behavior and memory retention. With this commit, `rxMethod` now prioritizes the injector of the instance caller, falling back to the creator's injector only if no injection context exists. Additionally, a custom injector can be provided by the caller and will take precedence when specified. For `Observable`, since it has a different completion mechanism, the instance caller is still responsible for handling unsubscription or completion.
7286585
to
720ec77
Compare
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.
Left a few suggestions. It will be useful to add a concise section on this topic to the RxJS Integration page.
Co-authored-by: Marko Stanimirović <[email protected]>
…ub.com/rainerhahnekamp/ngrx into fix/signals/rx-method-unclosed-effects
@markostanimirovic, I've incorporated all your suggestions and fixed the issues with the source subscription. As a result, the current version of If you are OK with the implementation, I'd do a last push and add the addition for the docs. |
Co-authored-by: Tim Deschryver <[email protected]>
Injector
of rxMethod
instance callerInjector
of rxMethod
instance caller if available
9c9913a
to
bb79531
Compare
bb79531
to
b3fcf82
Compare
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've added the same behavior for observables - unsubscribe from an instance subscription when an injector is destroyed.
Ensure that an instance of
rxMethod
uses theInjector
of the caller where the instance was invoked, rather than the injector of the node whererxMethod
was created.This change addresses a potential memory leak where a
SignalStore
method, generated byrxMethod
and provided at the root level, continues to track a signal via itseffect
using theRootInjector
. In cases where the component calling the method is destroyed, theSignal
remains tracked, leading to unintended behavior and memory retention.With this commit,
rxMethod
now prioritizes the injector of the instance caller, falling back to the creator's injector only if no injection context exists. Additionally, a custom injector can be provided by the caller and will take precedence when specified.For
Observable
, since it has a different completion mechanism, the instance caller is still responsible for handling unsubscription or completion.PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Closes #4528
What is the new behavior?
Does this PR introduce a breaking change?