Skip to content
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): remove signalMethod instance watcher on destroy #4648

Merged

Conversation

rainerhahnekamp
Copy link
Contributor

Each signalMethod instance uses a watcher assigned to it. The watcher is destroyed when the signalMethod itself gets destroyed. However, watchers were removed prematurely due to onDestroy behavior in effect. • onDestroy doesn’t run when an effect is destroyed but after each execution. • This caused watchers to be removed after the first execution unexpectedly.

Problematic Code: watchers.splice(watchers.indexOf(watcher), 1);

The removal mistakenly affected other watchers, keeping instances running, even after the signalMethod was destroyed.

Co-authored-by: @davdev82

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[x] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

effects are not destroyed.

Closes #4644

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Each `signalMethod` instance uses a watcher assigned to it. The watcher is
destroyed when the `signalMethod` itself gets destroyed. However, watchers were
removed prematurely due to `onDestroy` behavior in `effect`.
• `onDestroy` doesn’t run when an effect is destroyed but after each execution.
• This caused watchers to be removed after the first execution unexpectedly.

Problematic Code: `watchers.splice(watchers.indexOf(watcher), 1);`

The removal mistakenly affected other watchers, keeping instances running,
even after the signalMethod was destroyed.

Co-authored-by: @davdev82
Copy link

netlify bot commented Jan 2, 2025

Deploy Preview for ngrx-io canceled.

Built without sensitive environment variables

Name Link
🔨 Latest commit 78b9f9b
🔍 Latest deploy log https://app.netlify.com/sites/ngrx-io/deploys/677cf20db7f14c0008200e67

@markostanimirovic markostanimirovic changed the title fix(signals): fix issue with onDestroy removing watchers prematurely fix(signals): remove signalMethod instance watcher on destroy Jan 8, 2025
@markostanimirovic markostanimirovic merged commit 7f42065 into ngrx:main Jan 8, 2025
11 checks passed
@rainerhahnekamp
Copy link
Contributor Author

For the record. The not-working destroy is now officially a bug: angular/angular#59410

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

signalMethod cleans up watcher after first effect run
4 participants