Skip to content
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-img can sometimes not load in on a lower-end CPU device due to Intersection Observer API behavior #23703

Closed
4 of 6 tasks
Jacob-McKay opened this issue Jul 30, 2021 · 5 comments
Labels
package: core @ionic/core package type: bug a confirmed bug report
Milestone

Comments

@Jacob-McKay
Copy link
Contributor

Prequisites

Ionic Framework Version

  • v4.x
  • v5.x
  • v6.x

Current Behavior

Sometimes (on a lower-end mobile device, or chrome browser with CPU throttling enabled), the ion-img will not display even when it is scrolled into view. This is because the Intersection Observer API may pass in multiple items to the callback where the code assumes only one item (where the last item is the current value stating the img is in the viewport).

Expected Behavior

If the ion-img has been supplied a src, and has been scrolled into view, I expect the image to load and be visible to the user.

Steps to Reproduce

Linked is an experiment you can run with CPU Throttling enabled in your code, it's kind of what my app is doing, it has a bunch of images hooked up to the Intersection Observer API and you will see logged to the console the times that there is more than one item in the callback.

Code Reproduction URL

https://codepen.io/Jacob-McKay/pen/LYympzR

Ionic Info

No response

Additional Information

No response

@ionitron-bot ionitron-bot bot added the triage label Jul 30, 2021
@Jacob-McKay Jacob-McKay changed the title bug: bug: ion-img can sometimes not load in on a lower-end CPU device due to Intersection Observer API behavior Jul 30, 2021
@liamdebeasi
Copy link
Contributor

Thanks for the issue. Can you provide some additional steps to reproduce the issue? I tried your CodePen on a low end device with CPU throttling enabled. I was able to get multiple entries per IO callback, but the first entry (index zero) was the entry that stated the img is in the viewport, so I was not able to reproduce the exact behavior you described.

@liamdebeasi liamdebeasi added the needs: reply the issue needs a response from the user label Aug 2, 2021
@ionitron-bot ionitron-bot bot removed the triage label Aug 2, 2021
@Jacob-McKay
Copy link
Contributor Author

Great job catching that!. I had tunnel vision on the last entry being the one that is visible because in my app I was launching a modal with an image where I first noticed this (going from not visible to visible). Since my codepen is a different scrolling example the Intersection Observer sees the img appear then disappear before the slower main thread has a chance to get notified (that's where I assumed the batch of entries comes from). My fix is incomplete then because the image was visible but the current code would ignore that. Perhaps we should just listen for any entries that have a true isIntersecting, rather then caring about the order. lol maybe it's a feature not a bug that since the image zipped by so fast we avoided the cost of loading it :P

@ionitron-bot ionitron-bot bot added triage and removed needs: reply the issue needs a response from the user labels Aug 2, 2021
@liamdebeasi
Copy link
Contributor

I am looking at this a bit more and I think your solution in #23704 is correct. The Intersection Observer entries go from oldest to newest, so the last entry should represent the latest state of the ion-img.

@liamdebeasi liamdebeasi added package: core @ionic/core package type: bug a confirmed bug report labels Aug 2, 2021
@ionitron-bot ionitron-bot bot removed the triage label Aug 2, 2021
@liamdebeasi
Copy link
Contributor

Thanks for the issue. This has been resolved via #23704, and a fix will be available in an upcoming release of Ionic Framework.

@liamdebeasi liamdebeasi added this to the 5.6.14 milestone Aug 9, 2021
@ionitron-bot
Copy link

ionitron-bot bot commented Sep 8, 2021

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.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
package: core @ionic/core package type: bug a confirmed bug report
Projects
None yet
Development

No branches or pull requests

2 participants