question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ionic4 flickering and performance issue on *ngIf

See original GitHub issue

Bug Report

Ionic version: [x] 4.x

Current behavior: On ionic4 we see many times performance issues and flickering on adding and removing ionic components from dom.

If we have for example something like that

           <div *ngIf="this.loginSerivce.step === 2">YES</div>
            <ion-chip *ngIf="this.loginSerivce.step === 2" (click)="backToChooseGW()">
                <ion-icon name="arrow-back"></ion-icon>
                <ion-label>{{ selectedGW?.description }}, {{ selectedGW?.serialNumber }}</ion-label>
            </ion-chip>

as you can see there are a div (only for test) and an ion-chip which should render at the same time. If we do exactly the same thing on ionic3 and performe a performance registration with chrome we can see both elements are rendered in exactly the same frame, if we do this in ionic4 we can see some flickering for the ioni-chip and on the performance test the div element is rendered much faster then the ion-chip element.

So if you have many elements on the screen and update a list or others there are a lot of flickering, on ionic3 all this things looks much much much smoother

Same problem with a ion-list with 2 elements, if we update the element it looks really bad, absolutly no problem and very smooth on ionic3

Ionic info:

Ionic:
   ionic (Ionic CLI)             : 4.10.3 (/usr/lib/node_modules/ionic)
   Ionic Framework               : @ionic/angular 4.1.1
   @angular-devkit/build-angular : 0.13.5
   @angular-devkit/schematics    : 7.2.4
   @angular/cli                  : 7.3.5
   @ionic/angular-toolkit        : 1.4.0

Cordova:
   cordova (Cordova CLI) : 8.1.2 (cordova-lib@8.1.1)
   Cordova Platforms     : not available
   Cordova Plugins       : not available

System:
   Android SDK Tools : 26.1.1 (/home/...../software/android/sdk)
   NodeJS            : v10.15.2 (/usr/bin/node)
   npm               : 6.8.0
   OS                : Linux 4.15

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
alainbelezcommented, Apr 3, 2019

@mburger81 checked the repo and adding a trackBy in ngFor seems to fix your problem, i think it happens because angular is recreating the ion-item every time.

//view
    <ion-item *ngFor="let gw of gws; trackBy: trackByFn" button>
        <ion-avatar slot="start">
            <img src="assets/img/lanthings-hdpi-icon.png">
        </ion-avatar>
        <ion-label>
            <h2>{{ gw.description }}</h2>
            <p>{{ gw.serialNumber }}</p>
        </ion-label>
    </ion-item>

//controller
  trackByFn(index: number, item: any): number {
    return item.serialNumber;
  }
1reaction
mburger81commented, Mar 12, 2019

We have the problem on DEV with latest chrome, so the problem should not be only on slow old devices.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ionic4 flickering and performance issue on *ngIf #17732
I figured out today the flickering is ONLY happening if we have the button property in the ion-item for the ngFor list. <ion-item...
Read more >
Updating the data to the *ngFor object the view is flickering
I'm updating the data to the object that the view is rendering , In android it is working fine but in IOS entire...
Read more >
How to prevent flickering when using *ngIf? - Stack Overflow
When you use *ngIf , the element is not in the DOM (if the condition is false ) and will be placed into...
Read more >
Troubleshooting Flickering Displays on Intel® NUC
Flickering or flashing issues are most often seen when you're connecting a display to the Intel® NUC's HDMI port. It's less commonly seen...
Read more >
Ionic View Transition Flickering Issue - ADocLib
1983 Cited by 125 ABSTRACT Nicotinic acetylcholine channels show bursts of activity where open channel currents are separated from each other by short...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found