-
-
Notifications
You must be signed in to change notification settings - Fork 241
HMR: app.module bootstrapped multiple times #1954
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
Comments
Bump. I am having a similar issue. My app gets bootstrapped according to the number of times Hot Module Replacement has run. So running it the first time, it is bootstrapped once. Then, if I make a change to the app, the app will then get bootstrapped twice. Make another change, the app will get bootstrapped 3 times. Using NS angular, 5.3.1. Any ideas for fixing this? |
This issue is still present in the latest release, has there been any news regarding this issue ? |
This behavior is intended with HMR. This also happens on the web: https://stackblitz.com/edit/angular-hotreload-lifecycle?file=src/app/app.component.ts Things to note:
Check the console.log and see the AppModule construct happens many times (uncheck clear console on reload if you want the full log, as hot reloads count as a "reload"). When running with I'd also like to add that multiple constructs is intended on normal usage too. When you exit the app via back button, the rest of the application is still running (timers, native stuff, etc), but angular is destroyed (there is no frontend to show anymore) so ensure you're clearing up your subscriptions and timers on |
I'm not sure if my app has a problem with HMR, but I can't figure out since many weeks why my app is working as I described it here: https://stackoverflow.com/questions/61253807/possible-memory-leak-in-nativescript-app-if-user-reopens-his-app-multiple-times @edusperoni, do you think, it can be related to this topic about HMR? The problem is that when I'm moving my app to the background of my mobile device and then open that app again (for example a few times). Then, when I logout the user subscription emits as many times as I moved the app to the background and back before. So if I move app to the background and open that app 5 times, then if I logout my user, then this.authenticationService.user$ emits 5 console.logs. I use async and try to use ngOnDestroy everywhere, but without success :/ |
The same problem faced. 😭 The HMR causes all the components and services(singleton provide in root) initialize twice. |
Environment
Provide version numbers for the following components (information can be retrieved by running
tns info
in your project folder or by inspecting thepackage.json
of the project):Describe the bug
When using HMR, our Angular-based application gets bootstrapped multipled times. More precisely: the app.module gets bootrapped multiple times in a single HMR run. Looks like a recursion while processing the modules.
I try to reproduce the issue but having diffculties to get to the root cause.
The only thing I can see is that this behaviour starts as soon as code in a @Injectable which is provided by the main app.module is changed or if the @Injectable is in the dependency chain of affected modules.
The multiple bootstrapping does not happen if code in a UI/view is changed, e.g. a regular @component.
Example #1 - code change in @component. Works as expected. Resulting log:
Example #2 - code change in @Injectable. Resulting log:
Following HMR updates/reloads cause even more bootstraps.
What could be the reason for this? Or is this even expected behaviour?
The text was updated successfully, but these errors were encountered: