You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 7, 2021. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 7, 2021. It is now read-only.
HMR - Services bootstrapped multiple times, but never torn down #708
Cross-platform modules:
✔ Component nativescript has 5.0.0 version and is up to date.
✔ Component tns-core-modules has 5.0.2 version and is up to date.
✔ Component tns-android has 5.0.0 version and is up to date.
✔ Component tns-ios has 5.0.0 version and is up to date.
Android Runtime: 5.0.0
iOS Runtime: 5.0.0
Plugin(s): None
Node.js: 10.12.0
Please, attach your package.json and webpack.config.js as these configurations are usually critical for investigating issues with webpack.
These are default out of the box configs from using tns create
Describe the bug
When HMR tears down the Angular platform on changes, it correctly calls ngOnDestroy for all components etc, however it does not for services, meaning your app can end up in a weirdly initialized state with multiple "singletons" running side by side.
To Reproduce tns create - create a new angular project with say, the tabbed view.
Insert a constructor in app/core/data.service.ts: constructor() { console.log("DataService constructor"); } tns run android --hmr - the app starts, "DataService constructor" is written in console as expected.
Change some text in home.component.html that will cause a refresh. "DataService constructor" gets output again.
A lifecycle hook that is called when a directive, pipe, or service is destroyed.
You can imagine the trouble you can get in when you start including Rx Observable subscriptions in the constructor of a service, and even more when services start bootstrapping plugins.
So ngOnDestroy should also get called for services.
@larssn hey - not sure if this is still relevant for you: I just experienced something similar.
However, once I implemented the OnDestroy interface in my @Injectable service, I see that ngOnDestroy gets called when the app gets bootstrapped againg by HMR.
I'm using {N} 5.3 with nativescript-dev-webpack 0.22.0
Activity
NickIliev commentedon Nov 13, 2018
Issue moved to NativeScript/nativescript-angular #1605 via ZenHub
lambourn commentedon May 15, 2019
@larssn hey - not sure if this is still relevant for you: I just experienced something similar.
However, once I implemented the
OnDestroyinterface in my@Injectableservice, I see thatngOnDestroygets called when the app gets bootstrapped againg by HMR.I'm using {N} 5.3 with nativescript-dev-webpack 0.22.0