ionic-framework: Animation on page transition on iOS is broken
Bug Report
Ionic version:
[x] 4.x
Current behavior: Page transition is breaking on iOS. Android is working good.

Expected behavior: Transition smooth onto next page.
Steps to reproduce:
Related code:
Typically I’d use this.navCtrl.navigateForward(['route', id]); to navigate to the next page, but 90% of time the animation would stop.
Other information:
Ionic info:
Ionic:
ionic (Ionic CLI) : 4.10.3 (/Users/andjelicnikola/.nvm/versions/node/v10.7.0/lib/node_modules/ionic)
Ionic Framework : @ionic/angular 4.0.2
@angular-devkit/build-angular : 0.11.4
@angular-devkit/schematics : 7.2.2
@angular/cli : 7.2.2
@ionic/angular-toolkit : 1.2.1
Cordova:
cordova (Cordova CLI) : 7.1.0
Cordova Platforms : android 7.1.0, ios 4.4.0
Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 3.1.2, (and 23 other plugins)
System:
ios-deploy : 2.0.0
NodeJS : v10.7.0 (/Users/andjelicnikola/.nvm/versions/node/v10.7.0/bin/node)
npm : 6.8.0
OS : macOS Mojave
Xcode : Xcode 10.1 Build version 10B61
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 10
- Comments: 83 (30 by maintainers)
My current guess is the performance issue you were seeing is actually related to this bug in WebKit: https://bugs.webkit.org/show_bug.cgi?id=201048
Animations in the Shadow DOM tend to freeze/be janky when the layout is invalidated. In this case
Node.insertBeforecauses the issue. Unfortunately, Angular can sometimes call that when evaluating an ngIf, so the issue is easier to dig up in Angular apps.I am discussing with the team as to whether there may be an appropriate workaround we could go with for now.
This is happening because you are assigning subscription variables and/or subscribing in ngOnInit(). I was able to overcome this issue by using ionViewDidEnter() instead of ngOnInit(). However, when you do this, the page looks empty at first. If you don’t want that, you can use ghost elements to fill out the page and then when your API comes through, just display the correct items.
Addition: I didn’t know ionic already has something similar to ghost elements. Please see https://ionicframework.com/docs/api/skeleton-text
If anybody wants to reproduce the problem, just assign an API subscription to a value in ngOnInit() then subscribe it in the ion-content ngIf with async.
In my case, it was:
TS:
HTML:
FIX (replace ngOnInit() with ionViewDidEnter()):
It would be great if this was fixed asap.
@liamdebeasi I just updated the app to ionic 4.7.1 and angular 8.1.2 and the problem is the same. The problem is the same as what I posted in my first, original post. The transition is breaking up and flickering. I have 3 apps and the same things happen on all of them.
Here is my package.json
@liamdebeasi thank you for all the background information. i’m also sure that Ionic does a great job at optimising everything for good performance. i was just suggesting the possibility that this is not related to performance or (missing) optimisation but that this is (simply) a bug. of course i might be wrong here. however since i feel i can’t simply settle on this being the status quo now, i took the effort to create two blank Ionic projects, one with Ionic 4 and one with version 3. I added a second page “Page2” and a button on the home page that navigates there. “Page2” has this in the controller:
and this in the template:
The Ionic 4 version clearly shows the issue (tested on Safari Reponsive Design mode on a fast dev machine, as well as iOS Sim), the Ionic 3 version works just fine.
Is there any updates on this? I’m still seeing this problem even in 4.8.0
Hi, some new with this problem, I have a critical application that will go to production and I have this problem.
Thanks for the follow up. I was able to reproduce this issue. We will look into a fix!
Hi Liam, Thx for getting back on this. You say that this is not an Ionic issue but Ionic is the one responsible for changing their Ionic 4 platform to a PWA-based approach heavily reliant upon Shadow Dom / Webkit, etc. We don’t have any of these issues with Ionic 3 builds. So I hope you can appreciate my frustration when you say “this is not an issue with Ionic.” Over the last year, Ionic has largely ceased ongoing support for Ionic 2/3, which was working well for our mobile apps and Ionic is now concentrating on a PWA approach with Ionic 4. So we were pretty much forced to move to the use of Ionic 4, only to discover that Ionic 4 brings with it serious performance issues like this. It doesn’t matter to us that it’s a webkit issue, what matters to us is that Ionic has put us in this position by relying on external factors that are apparently beyond your control. After 9 months of waiting for a fix, we are getting pretty discouraged.
This issue seems like something that is better handled at the application level than at the framework level.
Using
ionViewDidEnterinstead ofngOnInitworks becauseionViewDidEnteris run after the animation has been completed, whereasngOnInitis fired when the page component is created (before the animation has started).Doing constant rerenders via an
*ngIfor a pipe is going to cause the browser to do a lot of work. This is often referred to as “layout thrashing” . While the navigation animations are handled off the main thread, your JavaScript code and animations do share certain resources. These rerenders are causing the browser to constantly use these resources, leaving fewer resources/computation time for the animation itself.Another point to mention is toggling the
*ngIfstate is going to continually add/remove elements from the DOM, which is a very expensive operation in general. It’s important to remember that your code is oftentimes going to cause Angular to run more code, which is going to cause the browser to have to do even more work (some people have already mentioned this, I just wanted to reiterate it).From the examples that you all have provided, there is quite a lot of work being done while the animation is still transitioning. I would recommend that this work gets done after the animation is done by using
ionViewDidEnter. If you absolutely need the view to be “ready” when the animation starts you will likely need to preload/cache your data, throttle how often your pipes/data causes the view to rerender, or ensure that your elements are not constantly being removed from or added to the DOM.As I said previously, I think this is an issue that would be better handled at the application level via code optimizations than at the framework level. Any thoughts or questions? Thanks!
@liamdebeasi from my tests it looks like the problem only happens if the
ngIfexpression changes during the transition animation. So probably removing/adding nodes from the DOM somehow messes with the animation.I did more testing and it seems that 4.6.2 version does not resolve the problem with page transition.
Here is the code that I put in the footer and on transition, it is not performing as epxected
Hi everyone,
This is still on our radar, but we have been focused on shipping Ionic w/ the Stencil One update. Now that the Stencil One update has been released, I updated the example app (https://github.com/ionic-team/ionic/issues/17649#issuecomment-493106320) to Ionic 4.6.1. (Tested on iPhone 7)
Compared to previous versions of Ionic, I am noticing an improvement in performance with the iOS transition. I do notice a little bit of jank, but it’s not as noticeable as before.
Can other people update their apps to 4.6.1 and confirm whether or not updating reduces the severity of this issue? I am still interested in resolving any remaining jank, but am curious if the update helps at all.
Thanks!
@liamdebeasi Did you have any luck with tracking this one down? I’m still seeing this issue in v4.4.0. It really impacts the UX when all of the page transitions are like this. I find that it frequently happens when using Angulars
ngOnInitmethod to load in data.Any update on this issue ? I have the same problem …
If there is anything that calls controller like
{{ myVariable }}the transition will breakdown. However I have plenty of pages where I will be making the same calls and transition would work fine. I load the pages the same way.I am trying to debug this, but no luck
Ok thanks! I’ll check this issue out some more.
@liamdebeasi I didn’t realize I needed to respond… yes, I still experience the same issue. I am currently on 4.2.0
I just wanted to confirm that it started to happen again… not sure why it was working good for 1 day. I will try to create repository that reproduces the problem.
It seems like upgrade to Ionic 4.1.0 solved the issue.
If it means anything I tested on iPhone 8 Plus iOS 12.1.4