-
Notifications
You must be signed in to change notification settings - Fork 13.5k
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-nav does not fire change detection for the root page when using OnPush change detection #21423
Comments
Hmm, ok so there's a few things here. It's not 100% due to Ionic, but it is something we should probably document. Basically, the property binding for import {
Component,
NgModule,
ChangeDetectionStrategy,
ɵmarkDirty as markDirty,
} from '@angular/core';
....
export class ProcessComponent {
ModalPageComponent = ModalPageComponent;
ionViewDidEnter(){
markDirty(this)
}
} It might make sense to not use onPush here in the ProcessComponent since it needs to be able to handle this situation. |
That is actually what we ended up doing. It didn't seem like a terrible practice to do that for our situation, as there really is little to nothing in the process component, but we thought it was worth raising the issue in case you were not aware. I am fine with it if the answer is to just not use OnPush in that situation. Some documentation to that effect would definitely be nice, though. Thanks Mike! |
Thanks for the issue! I added some clarification to the docs via ionic-team/ionic-docs#1448. |
Works for me. Thanks! |
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. |
Bug Report
Ionic version:
[x] 4.11.1 (also reproduced in sample in 5.1.1)
Current behavior:
I am presenting a modal using the ModalController. The modal presents a simple component that contains only an
<ion-nav>
with a root component set on it. This is so that I can create a sort of "guided process" within the modal using the<ion-nav>
to navigate between pages of the process. The root page that I am setting on<ion-nav>
usesOnPush
change detection and contains some observable state that is shown in the UI asynchronously. If I set the modal component'sChangeDetectionStrategy
toDefault
, everything works the way I expect with the component set as the root on the<ion-nav>
. However, if I useChangeDetectionStrategy.OnPush
for the modal component, the root page will never display my asynchronous state changes. In fact, it will not even fire the regular angular lifecycle events likengOnInit
. It does fire the ionic lifecycle events, but the angular ones are never called.Expected behavior:
I would expect that my modal component containing the
<ion-nav>
should be able to utilize whateverChangeDetectionStrategy
I choose, and as long as the child component can handle it (and mine can), it should fire angular lifecycle events and update the view accordingly.Steps to reproduce:
I have put together a sample application that has a single button to launch a modal. That modal displays a page using
ChangeDetectionStrategy.OnPush
. The root component loaded in the<ion-nav>
should show text initially, wait 3 seconds, and then update the text. It will actually never show the text at all with the current setup. Switching theModalComponent
toChangeDetectionStrategy.Default
will make it all work as expected.Related code:
Sample app: https://github.com/ekrapfl/nav-on-push
There are comments in
src/app/home/process.component.ts
andsrc/app/home/modal-page.component.ts
to indicate some of the things I have attempted/noticed.Ionic info:
The text was updated successfully, but these errors were encountered: