metafizzy / infinite-scroll

📜 Automatically add next page
https://infinite-scroll.com
7.41k stars 1.74k forks source link

Prevent Infinite Scroll "Preload" Runaway #941

Open Archmonger opened 3 years ago

Archmonger commented 3 years ago

Description When preloading, it is currently possible to get stuck in an infinite loop of preload. InfiniteScroll will either need to be able to detect this situations and wait it out, or have a maxPreload value.

Reproduce In order to set up the situation, put a InfiniteScroll'd masonry into an iFrame. But prior to the iFrame loading, make the iFrame have a display: none; attribute. When in this situation, the height of any "infinite-scrollers" on the page are presumably forced to 0 due to display: none, so preload will preload forever.

Can be reproduced by putting Conreq into an Organizr iframe tab, then immediately clicking on a different tab before Conreq loads.

Struggled to create a codepen for this.

Potential Resolutions

  1. Have a maxPreload value where the user can enforce a maximum amount of pages that are allowed to be preloaded.
  2. If infinite scroll container height stays 0 across the first two preloads, then InfiniteScroll should resort to polling the container and waiting for its height to become a real value.
  3. Detect if the user is in an iFrame and/or if the browser window does not have focus. Do not preload until focus is obtained.