René's URL Explorer Experiment


Title: Erratic behavior with DestroyRef, not all callbacks are always being called upon component destruction. · Issue #50221 · angular/angular · GitHub

Open Graph Title: Erratic behavior with DestroyRef, not all callbacks are always being called upon component destruction. · Issue #50221 · angular/angular

X Title: Erratic behavior with DestroyRef, not all callbacks are always being called upon component destruction. · Issue #50221 · angular/angular

Description: Which @angular/* package(s) are the source of the bug? core Is this a regression? Yes Description We have migrated our code base to use the new takeUntilDestroyed pipe along with DestroyRef. Unfortunately, we have noticed very erratic be...

Open Graph Description: Which @angular/* package(s) are the source of the bug? core Is this a regression? Yes Description We have migrated our code base to use the new takeUntilDestroyed pipe along with DestroyRef. Unfort...

X Description: Which @angular/* package(s) are the source of the bug? core Is this a regression? Yes Description We have migrated our code base to use the new takeUntilDestroyed pipe along with DestroyRef. Unfort...

Opengraph URL: https://github.com/angular/angular/issues/50221

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Erratic behavior with DestroyRef, not all callbacks are always being called upon component destruction.","articleBody":"### Which @angular/* package(s) are the source of the bug?\r\n\r\ncore\r\n\r\n### Is this a regression?\r\n\r\nYes\r\n\r\n### Description\r\n\r\nWe have migrated our code base to use the new takeUntilDestroyed pipe along with DestroyRef.\r\n\r\nUnfortunately, we have noticed very erratic behavior that with these, going so far as to not actually unsubscribe from some Observables at all after components are destroyed (I am still working on trying to provide a minimal reproduction for some cases).\r\n\r\nI have been able to replicate some bugs consistently with the reproduction below.\r\nhttps://stackblitz.com/edit/at-ng-14-router-aoffwi?file=src%2Fapp%2Fhello.component.ts\r\n\r\n# Reproduction\r\nThis small App contains\r\nA Service with a BehaviorSubject (bhSubject) that increments an integer and a Subject (subject) that \"increments\" strings.\r\nThose two actions are performed from AppComponent, which is always visible with the buttons.\r\nA third button \"Toggle Child\" will show and hide the HelloComponent, which contains the actual bug.\r\n\r\nHelloComponent registers a onDestroy callback in each of the following cases:\r\n1) In the callback given to subscribe() on bhSubject.\r\n2) In a method called from the same callback given to subscribe on bhSubject.\r\n3) In the callback given to subscribe() on subject.\r\n4) In a setTimeout of 0.\r\n5) In ngZone.runOutsideAngular()\r\n6) Directly in ngOnit()\r\n\r\nNote that a lot of the stuff is going on in the console.\r\n\r\n## Case 1:\r\n\r\n- Toggle Child\r\n- Toggle Child again\r\n\r\n### Expected onDestroy callbacks to have been called:\r\n- 1, 2, 4, 5?, 6\r\n\r\n### Actual callbacks called\r\n- 2, 4, 6\r\n\r\n## Case 2:\r\n\r\n- Toggle Child\r\n- Int++\r\n- Toggle Child\r\n\r\n### Expected onDestroy callbacks to have been called:\r\n- 1, 1, 2, 2, 4, 5?, 6\r\n\r\n### Actual callbacks called\r\n- 1, 2, 2, 4, 6\r\n\r\n## Case 3:\r\n\r\n- Toggle Child\r\n- Letter++\r\n- Toggle Child\r\n\r\n### Expected onDestroy callbacks to have been called:\r\n- 1, 2, 3, 4, 5?, 6\r\n\r\n### Actual callbacks called\r\n- 2, 3, 4, 6\r\n\r\n\r\nFollowing this, it seems like the first callback from a BehaviorSubject doesn't allow to use DestroyRef.\r\n\r\nNow you might be wondering why I added runOutsideAngular() in this, it's normal it's not working there. Well, if we comment the subscription to the normal subject (line 40 to 50 in hello.component.ts) and do case 1 again, it somehow does work with runOutsideAngular(). https://stackblitz.com/edit/at-ng-14-router-d9iur8?file=src%2Fapp%2Fhello.component.ts\r\n\r\n```ts\r\n    /*this.someService.subject\r\n      .pipe(takeUntilDestroyed(this.destroyRef))\r\n      .subscribe((value) => {\r\n        console.log(value);\r\n\r\n        this.destroyRef.onDestroy(() => {\r\n          console.log('Subject ' + value + ' destroyRef');\r\n        });\r\n\r\n        this.letterValue = value;\r\n      });*/\r\n```\r\n\r\n## Case 4 (Same as Case 1, but with a subscription that is commented out):\r\n\r\n- Toggle Child\r\n- Toggle Child again\r\n\r\n### Expected onDestroy callbacks to have been called:\r\n- 1, 2, 4, 5?, 6\r\n\r\n### Actual callbacks called\r\n- 2, 4, 5, 6\r\n\r\n\r\n\r\n\r\nThis all seems very inconsistent. As stated before, we ran into bugs where takeUntilDestroyed() didn't work at all when used on observables within ngOnit directly (with destroyRef supplied, of course) and it wouldn't unsubscribe from all observables. Sadly I've not been able to reproduce this in a simple example yet, but this makes this new feature quite unusable. I'll keep you updated if I manage to craft a minimal reproduction for that bug as well.\r\n\r\n### Please provide a link to a minimal reproduction of the bug\r\n\r\nhttps://stackblitz.com/edit/at-ng-14-router-aoffwi?file=src%2Fapp%2Fhello.component.ts\r\n\r\n### Please provide the exception or error you saw\r\n\r\n_No response_\r\n\r\n### Please provide the environment you discovered this bug in (run `ng version`)\r\n\r\n```true\r\nAngular CLI: 16.0.0\r\nNode: 16.18.0\r\nPackage Manager: npm 9.6.4\r\nOS: win32 x64\r\n\r\nAngular: 16.0.0\r\n... animations, cdk, cli, common, compiler, compiler-cli, core\r\n... forms, localize, material, platform-browser\r\n... platform-browser-dynamic, router\r\n\r\nPackage                         Version\r\n---------------------------------------------------------\r\n@angular-devkit/architect       0.1600.0\r\n@angular-devkit/build-angular   16.0.0\r\n@angular-devkit/core            16.0.0\r\n@angular-devkit/schematics      16.0.0\r\n@schematics/angular             16.0.0\r\nrxjs                            7.8.1\r\ntypescript                      5.0.4\r\n```\r\n\r\n\r\n### Anything else?\r\n\r\n_No response_","author":{"url":"https://github.com/wartab","@type":"Person","name":"wartab"},"datePublished":"2023-05-09T16:38:21Z","url":"https://github.com/angular/angular/issues/50221"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:8db6bf86-c846-dc55-317d-255df79f9ffa
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idD35E:1C94F:CE7C6C:1076DBB:6B013FCE
html-safe-nonced0d25691b198ba46a6600b35376f7de18c57f54907671e7a12b168460013fadd
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMzVFOjFDOTRGOkNFN0M2QzoxMDc2REJCOjZCMDEzRkNFIiwidmlzaXRvcl9pZCI6IjgzMzUzMzQ1NzYwNzUzOTA5MjYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmacee97a6e2322304d13d0b5b6c097dc08bd88111c6d8cc66bc3de659f4b7f34b13
hovercard-subject-tagissue:1702376856
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular/50221/issue_layout
twitter:imagehttps://opengraph.githubassets.com/c7f1229bbda94fa745b1e32f1151c9e1ca39b1640e4deaa70bc86e1260a16904/angular/angular/issues/50221
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/c7f1229bbda94fa745b1e32f1151c9e1ca39b1640e4deaa70bc86e1260a16904/angular/angular/issues/50221
og:image:altWhich @angular/* package(s) are the source of the bug? core Is this a regression? Yes Description We have migrated our code base to use the new takeUntilDestroyed pipe along with DestroyRef. Unfort...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamewartab
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
turbo-cache-controlno-preview
go-importgithub.com/angular/angular git https://github.com/angular/angular.git
octolytics-dimension-user_id139426
octolytics-dimension-user_loginangular
octolytics-dimension-repository_id24195339
octolytics-dimension-repository_nwoangular/angular
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id24195339
octolytics-dimension-repository_network_root_nwoangular/angular
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/angular/angular/issues/50221#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fangular%2Fangular%2Fissues%2F50221
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fangular%2Fangular%2Fissues%2F50221
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=angular%2Fangular
Reloadhttps://github.com/angular/angular/issues/50221
Reloadhttps://github.com/angular/angular/issues/50221
Reloadhttps://github.com/angular/angular/issues/50221
angularhttps://github.com/angular
angularhttps://github.com/angular/angular
Codehttps://github.com/angular/angular
Issues836 (836)https://github.com/angular/angular/issues
Pull requests141 (141)https://github.com/angular/angular/pulls
Discussionshttps://github.com/angular/angular/discussions
Actionshttps://github.com/angular/angular/actions
Projectshttps://github.com/angular/angular/projects
Security and quality40 (40)https://github.com/angular/angular/security
Insightshttps://github.com/angular/angular/insights
https://github.com/angular/angular
New issuehttps://github.com/login?return_to=https://github.com/angular/angular/issues/50221
New issuehttps://github.com/login?return_to=https://github.com/angular/angular/issues/50221
Erratic behavior with DestroyRef, not all callbacks are always being called upon component destruction.https://github.com/angular/angular/issues/50221#top
area: coreIssues related to the framework runtimehttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22area%3A%20core%22
bughttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22bug%22
core: lifecycle hookshttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22core%3A%20lifecycle%20hooks%22
needsTriagehttps://github.com/angular/angular/milestone/83
https://github.com/wartab
wartabhttps://github.com/wartab
on May 9, 2023https://github.com/angular/angular/issues/50221#issue-1702376856
https://stackblitz.com/edit/at-ng-14-router-aoffwi?file=src%2Fapp%2Fhello.component.tshttps://stackblitz.com/edit/at-ng-14-router-aoffwi?file=src%2Fapp%2Fhello.component.ts
https://stackblitz.com/edit/at-ng-14-router-d9iur8?file=src%2Fapp%2Fhello.component.tshttps://stackblitz.com/edit/at-ng-14-router-d9iur8?file=src%2Fapp%2Fhello.component.ts
https://stackblitz.com/edit/at-ng-14-router-aoffwi?file=src%2Fapp%2Fhello.component.tshttps://stackblitz.com/edit/at-ng-14-router-aoffwi?file=src%2Fapp%2Fhello.component.ts
alxhubhttps://github.com/alxhub
area: coreIssues related to the framework runtimehttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22area%3A%20core%22
core: lifecycle hookshttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22core%3A%20lifecycle%20hooks%22
bughttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22bug%22
on May 9, 2023https://github.com/angular/angular/issues/50221#event-9205504257
ngbothttps://github.com/apps/ngbot
needsTriagehttps://github.com/angular/angular/milestone/83
on May 9, 2023https://github.com/angular/angular/issues/50221#event-9205504355
https://github.com/garrettld
garrettldhttps://github.com/garrettld
on May 10, 2023https://github.com/angular/angular/issues/50221#issuecomment-1542309444
angular/packages/core/src/render3/node_manipulation.tshttps://github.com/angular/angular/blob/cc286be7af31c7f999d6c469d3fd8f9becb28ce7/packages/core/src/render3/node_manipulation.ts#L468-L476
cc286behttps://github.com/angular/angular/commit/cc286be7af31c7f999d6c469d3fd8f9becb28ce7
angular/packages/core/src/render3/util/view_utils.tshttps://github.com/angular/angular/blob/cc286be7af31c7f999d6c469d3fd8f9becb28ce7/packages/core/src/render3/util/view_utils.ts#L230-L237
cc286behttps://github.com/angular/angular/commit/cc286be7af31c7f999d6c469d3fd8f9becb28ce7
https://github.com/pkozlowski-opensource
pkozlowski-opensourcehttps://github.com/pkozlowski-opensource
on May 10, 2023https://github.com/angular/angular/issues/50221#issuecomment-1542310768
@wartabhttps://github.com/wartab
https://stackblitz.com/edit/angular-wffadt?file=src%2Fmain.tshttps://stackblitz.com/edit/angular-wffadt?file=src%2Fmain.ts
https://github.com/pkozlowski-opensource
pkozlowski-opensourcehttps://github.com/pkozlowski-opensource
on May 10, 2023https://github.com/angular/angular/issues/50221#issuecomment-1542317315
@garrettldhttps://github.com/garrettld
https://github.com/pkozlowski-opensource
pkozlowski-opensourcehttps://github.com/pkozlowski-opensource
on May 10, 2023https://github.com/angular/angular/issues/50221#issuecomment-1542336748
https://github.com/wartab
wartabhttps://github.com/wartab
on May 10, 2023https://github.com/angular/angular/issues/50221#issuecomment-1542461431
AndrewKushnirhttps://github.com/AndrewKushnir
on May 11, 2023https://github.com/angular/angular/issues/50221#event-9224947464
fix(core): allow onDestroy unregistration while destroying (#50237)https://github.com/angular/angular/commit/cc41758b595da46a3fd14a58b3832c77b251b940
#50237https://github.com/angular/angular/pull/50237
https://docs.github.com/articles/closing-issues-via-commit-messages
cc41758https://github.com/angular/angular/commit/cc41758b595da46a3fd14a58b3832c77b251b940
AndrewKushnirhttps://github.com/AndrewKushnir
completedhttps://github.com/angular/angular/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
03f1e24https://github.com/angular/angular/commit/03f1e240b368c4c87fd8412605bf0eff9adc153d
on May 11, 2023https://github.com/angular/angular/issues/50221#event-9224947772
https://github.com/dcby
dcbyhttps://github.com/dcby
on May 17, 2023https://github.com/angular/angular/issues/50221#issuecomment-1551414949
https://github.com/garrettld
garrettldhttps://github.com/garrettld
on May 17, 2023https://github.com/angular/angular/issues/50221#issuecomment-1551433199
@dcbyhttps://github.com/dcby
jessicajaniukhttps://github.com/jessicajaniuk
on May 19, 2023https://github.com/angular/angular/issues/50221#event-9291022461
docs: added clarity in lifecycle event docs (#50145)https://github.com/angular/angular/commit/d963ecdf5057e68701f44dd9dabe0f45f9f9e5b7
#50145https://github.com/angular/angular/pull/50145
https://docs.github.com/articles/closing-issues-via-commit-messages
d963ecdhttps://github.com/angular/angular/commit/d963ecdf5057e68701f44dd9dabe0f45f9f9e5b7
docs: added clarity in lifecycle event docs (#50145)https://github.com/angular/angular/commit/2f1796f8f6299d78de7e286e5b836d8402bb7661
#50145https://github.com/angular/angular/pull/50145
https://docs.github.com/articles/closing-issues-via-commit-messages
2f1796fhttps://github.com/angular/angular/commit/2f1796f8f6299d78de7e286e5b836d8402bb7661
https://github.com/apps/angular-automatic-lock-bot
angular-automatic-lock-bothttps://github.com/apps/angular-automatic-lock-bot
on Jun 17, 2023https://github.com/angular/angular/issues/50221#issuecomment-1595503861
automatic conversation locking policyhttps://github.com/angular/angular/blob/8f24bc9443b3872fe095d9f7f77b308a361a13b4/docs/GITHUB_PROCESS.md#conversation-locking
angular-automatic-lock-bothttps://github.com/apps/angular-automatic-lock-bot
on Jun 17, 2023https://github.com/angular/angular/issues/50221#event-9557020062
Sign up for freehttps://github.com/signup?return_to=https://github.com/angular/angular/issues/50221
Sign in to commenthttps://github.com/login?return_to=https://github.com/angular/angular/issues/50221
area: coreIssues related to the framework runtimehttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22area%3A%20core%22
bughttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22bug%22
core: lifecycle hookshttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22core%3A%20lifecycle%20hooks%22
needsTriageNo due datehttps://github.com/angular/angular/milestone/83
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.