bug(nav): lifecycle events inside ion-nav fire incorrectly
See original GitHub issuePrerequisites
- I have read the Contributing Guidelines.
- I agree to follow the Code of Conduct.
- I have searched for existing issues that already report this problem, without success.
Ionic Framework Version
- v4.x
- v5.x
- v6.x
- Nightly
Current Behavior
I’ve come across with some strange behaviour, when you present a page using ModalController
which wraps ion-nav
.
Parent Page
public async openModal() {
const modal = await this.modalController.create({
component: ModalOutletPage,
componentProps: { component: AddCardPage },
});
await modal.present();
}
Modal Outlet Page
export class ModalOutletPage implements OnInit {
@Input() public component: HTMLElement;
@Input() public componentProps: unknown;
}
<ion-nav [root]="component" [rootParams]="componentProps"></ion-nav>
in this test i console.log() ionViewDidEnter()
, ionViewDidLeave()
, ngOnInit()
, ngOnDestroy()
inside add-card.page.ts
First time opening modal:
on open
- ionViewDidEnter trigger
on close
- ngOnInit trigger
- ngOnDestroy trigger
second time opening modal:
on open
- ngOnInit trigger
- ionViewDidEnter trigger twice
- ionViewDidLeave trigger
- ngOnDestroy trigger
on close
- ngOnInit trigger
- ngOnDestroy trigger
UPDATE
This is the behaviour, if i remove changeDetection: ChangeDetectionStrategy.OnPush
inside modal-outlet.page.ts
:
Expected Behavior
Lifecycle events should trigger correctly
Steps to Reproduce
see video
Code Reproduction URL
https://github.com/DwieDima/ion-nav-lifecycle-bug
Ionic Info
Ionic CLI : 5.4.16 Ionic Framework : @ionic/angular 6.1.15 @angular-devkit/build-angular : 14.1.0 @angular-devkit/schematics : 13.2.6 @angular/cli : 14.1.0 @ionic/angular-toolkit : 6.1.0
Utility:
cordova-res : not installed native-run : not installed
System:
NodeJS : v16.14.2 npm : 8.5.0 OS : macOS Monterey
Additional Information
maybe related to #25638
Issue Analytics
- State:
- Created a year ago
- Reactions:4
- Comments:5 (3 by maintainers)
Top GitHub Comments
@DwieDima thanks for this issue. I’ve confirmed that the PR you have tag as being related, does not have an impact on this behavior.
We will log this as a bug and prioritize in the backlog. Thanks!
@DwieDima @sean-perkins I was able to fix the bug with this code:
BTW, smaller timeouts works!