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.

bug: Ion-image inside virtual scroll shows wrong image until new one loaded

See original GitHub issue

Bug Report

Ionic version:

[x] 4.x

Current behavior:

When adding ion-image inside virtual scroll and scrolling it is showing old image for some time until the new image is loaded. gXngdrkfbg

Expected behavior:

Should not show wrong image, instead should be empty image until the image is loaded

Steps to reproduce:

Add virtual scroll and add image inside each item, then scroll trough to see wrong image displayed for short time.

Related code:

https://github.com/jgermanis/virtual-scroll-test

Other information:

Ionic info:

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:11
  • Comments:15 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
austinhutchisoncommented, May 24, 2020

Wanted to +1 this issue. I quickly tried @michael-roewin’s suggestion to use <img> instead of <ion-img> but it didn’t seem to stop the image from the last DOM scroll staying in place until the new image is loaded.

In my mind there are two ways to address this

  1. It seems the virtual DOM elements are updated on scroll. If instead there were added and removed dynamically I think that would resolve the problem. Maybe this design is is a choice based on performance.
  2. If we must reuse the same DOM elements and update them with new data on scroll - then we should get some event where we can listen for when the item is out of view, then hide the image / replace with a skeleton placeholder etc.

It’s not acceptable for me personally to have the images flash to the new image on load.

I’m pretty sure I will have to abandon virtual scroll and do some type of pagination.

1reaction
elvisgrahocommented, Jun 3, 2020

To Fix this permanently:

  1. Use this: https://github.com/rintoj/ngx-virtual-scroller

  2. Do this in page where there is ion-content:

  @ViewChild(IonContent, {static: false}) ionContent: IonContent;

  ngAfterViewInit() {
    this.ionContent.getScrollElement().then(scrollElement => {
      this.importantElement = scrollElement;
    });
  }

Now, you can use importantElement right away or store it in the service in case you need it in routes where there is no ion-content.

  1. Replace ion-virtual-scroll with the npm-plugin above.
    <virtual-scroller [parentScroll]='importantElement' #scroll [items]="helloItems">
      <div *ngFor="let item of scroll.viewPortItems">{{item}}</div>
    </virtual-scroller>

Bob IS your uncle.

Read more comments on GitHub >

github_iconTop Results From Across the Web

bug: Ion-image inside virtual scroll shows wrong ... - GitHub
Current behavior: When adding ion-image inside virtual scroll and scrolling it is showing old image for some time until the new image is...
Read more >
Ionic - Scrollable list of big images - Memory Usage
This is useful for VirtualScroll by allowing image responses to be cached, and not rendered, until after scrolling has completed, which allows ...
Read more >
Lazy loading images and managing lists with Ionic VirtualScroll
Only loads images which are visible in the viewport (avoiding unnecessary network requests for images which aren't visible); Uses web workers ...
Read more >
ion-img Tag - Ionic Framework
Img tag lazy loads images whenever the tag is in the viewport. Utilize this component when generating large lists—as images are only loaded...
Read more >
How to Lazy Load Images with Ionic - YouTube
Learn to lazy load images within your Ionic apps with a cool and powerful package that we can customise with hooks exactly for...
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