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

bug: ion-router-outlet triggers ngOnDestroy outside the Angular zone #22571

Closed
kawazoe opened this issue Nov 25, 2020 · 7 comments
Closed

bug: ion-router-outlet triggers ngOnDestroy outside the Angular zone #22571

kawazoe opened this issue Nov 25, 2020 · 7 comments
Labels
package: angular @ionic/angular package

Comments

@kawazoe
Copy link

kawazoe commented Nov 25, 2020

Bug Report

Ionic version:

[ ] 4.x
[x] 5.x

Current behavior:

In an ionic angular application using the ion-router-outlet, navigating away from a page in a way that would trigger the ngOnDestroy lifecycle method on the page component will cause the method to be called outside of the angular zone.

This causes issues when using ngOnDestroy to unsubscribe from observables which have finalize clauses that require change detection. For instance, dispatching an NgRx action in a finalize clause will cause an error in such scenario unless it is wrapped with ngZone.run().

Expected behavior:

The standard angular behavior is to run all lifecycle methods inside the angular zone. Swapping the ion-router-outlet for a angular router-outlet fixes this issue.

Steps to reproduce:

Related code:

See this repository for a repro project: https://github.com/imadh/ionic-router-outside-angular-zone

Simply navigate between the "hello" and "bye" pages multiple times to trigger the ngOnDestroy call. A console log will indicate if the method is called in the right zone.

Other information:

Ionic info:

Ionic:
   Ionic CLI                     : 6.10.1 (/home/imad/.nvm/versions/node/v10.21.0/lib/node_modules/@ionic/cli)
   Ionic Framework               : @ionic/angular 5.5.0
   @angular-devkit/build-angular : 0.1000.8
   @angular-devkit/schematics    : 10.0.8
   @angular/cli                  : 10.0.8
   @ionic/angular-toolkit        : 2.3.3
Capacitor:
   Capacitor CLI   : 2.4.3
   @capacitor/core : 2.4.3
Utility:
   cordova-res                          : not installed
   native-run (update available: 1.2.2) : 1.0.0
System:
   NodeJS : v10.21.0 (/home/imad/.nvm/versions/node/v10.21.0/bin/node)
   npm    : 6.14.4
   OS     : Linux 4.19
@ionitron-bot ionitron-bot bot added the triage label Nov 25, 2020
@liamdebeasi
Copy link
Contributor

Thanks for the issue. Did you push your changes that show this bug happening? I cloned your repository, but it just looks like a blank Ionic starter app.

@liamdebeasi liamdebeasi added the needs: reply the issue needs a response from the user label Nov 30, 2020
@ionitron-bot ionitron-bot bot removed the triage label Nov 30, 2020
@kawazoe
Copy link
Author

kawazoe commented Nov 30, 2020

Oups! Sorry for that. It should be ok now.

@ionitron-bot ionitron-bot bot added triage and removed needs: reply the issue needs a response from the user labels Nov 30, 2020
@kawazoe
Copy link
Author

kawazoe commented Mar 10, 2021

@liamdebeasi any news on this? It's been 4 months already and this is a pretty big issue.

@malinges
Copy link

Yup, I just got bit by this bug once again, even though I know about it...

@sean-perkins
Copy link
Contributor

Hello everyone! I have an open PR to address this problem.

In the interim, you can test with this dev build:

6.0.13-dev.11647460756.170a3672

Thanks!

@kawazoe
Copy link
Author

kawazoe commented Mar 16, 2022

While I'm no longer working on an ionic project, I just looked at your PR and it looks like it should address the issue. Fantastic!

@ionitron-bot
Copy link

ionitron-bot bot commented Apr 21, 2022

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Apr 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
package: angular @ionic/angular package
Projects
None yet
Development

No branches or pull requests

4 participants