ngOnInit event executed after ionViewDidEnter

I have a strange behavior in an ionic4 application, I will try to explain the problem although it is quite difficult to reproduce it.

When the application (only occurs on Android) has been open for a few hours (in the foreground or background, it is indifferent, but the process was not killed), certain views of the application do not load correctly if are accessed from the menu. The menu uses the this.navCtrl.navigateRoot ([url]) method to access the new view, and when the error occurs what appears is the screen with the header, content and footer colors but without rendering any elements (no content)

The extrange goes here:

  • On the one hand, I have “console.log” in all life cycle events, and I see that although ionViewWillEnter and ionViewDidEnter have been executed, ngOnInit has not been executed
  • In “network” tab from devtools, I can see that all API request were executed with no errors.
  • If I swipe from left to right, the menu is displayed correctly and the ngOnInit event is executed and the view loads correctly with no errors
  • If I press the Android “back button”, the ngOnInit event is also executed and the view loads correctly
  • If I go to background and return inmediately, the ngOnInit event is also executed

Console log from the last point:
== ngOnInit ==

As you can see, ngOnInit is executed before the platform resume event…

Any ideas?

Given the characteristics of the problem, it is very difficult to me to reproduce it, since when the application has not been open for a long time, this problem does not occur.

Thank you

While you wait for better answers, whenever I run into a situation like this, I decide that I am relying on something that I shouldn’t, and try to eliminate that in my code. Is there any way you can structure your code so that you don’t care in what order these events happen, or is the problem entirely within code outside your control?

Thanks for your reply rapropos.

I tried that before, making my code not dependent on that events, but the main problem is that ngOnInit is not executed until I make any of the actions I said (scroll menu, click back, or background/foreground). If I dont do any of these actions, the view is empty and nothing works.

After a lot of research, now I am pretty sure that the problem is “side-menu” related, because if I go to these pages using other link outside the menu (I have a tabbar in the footer with links to some of these pages) the problem does not occurs.

I will keep investigating…

Another thing to keep an eye out for is jumping outside the Angular zone. Are you using any plugins or external libraries that are not Angular-aware, such as Cordova plugins without a corresponding Ionic-Native wrapper?