Problem/Motivation
We use this module on a travel site and it works great on most pages.
We use the Infinite Scroll Pager option with Automatically Load Content ticked.
On some pages however, for reasons we don't understand, the module immediately initiates the loading of the next page of Views results even before the user has scrolled or moved their mouse cursor.
Then when the next page is loaded, it continues to load another Views page, and another, and another, until all pages are loaded.
All the time the user makes no mouse gesture whatsoever.
The screen does not auto-scroll either while additional results are auto-loaded.
Steps to reproduce
We were unable to reliably pinpoint under what exact conditions this happens. We just know it does, sometimes.
Debugging the JS we found that the top of the pager element, pager.offset().top, expressed in pixels was always the same low number (294px), page after page, after page. This would explain why the auto-loading never stops.
Proposed resolution
We found that by removing one line from the js/infinite-scroll.js file, the module started behaving as expected on ALL our pages that have infinite scroll.
Patch attached to the comment below.
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | fix-infinite-loading-without-scroll-3207098-18.patch | 1.13 KB | renukakulkarni |
| #8 | stop-immediate-autoloading-3207098-8.patch | 389 bytes | oheller |
| #2 | stop-immediate-autoloading-3207098-2.patch | 574 bytes | rdeboer |
Comments
Comment #2
rdeboerOne-line patch attached:
A side-effect of the solution is that the "Button text" (default "Load more") as set in the Views UI is briefly visible as the user scrolls towards the bottom of the page. But we actually like that! We changed the text via the Views UI to Loading more...as that is exactly what happens that moment.
Alternatively, if you do not wish to see any text or bullet-list symbol, you could enter a space as "Button text" in the Views UI and use CSS to set
list-style-type: noneNote that
display: noneon the pager element may interfere with correct operation.Comment #3
rdeboerComment #4
rdeboerComment #5
rdeboerComment #6
attheshow commentedWe're seeing the same issue on version 1.8. Unfortunately the patch didn't seem to resolve the situation for us. Downgrading to 1.7 resolves the issue.
Comment #7
oheller commentedWe are using the views_infinite_scroll with Drupal 9's media library.
In infinite-scroll.js ln:96 `if (isLoadNeeded()){ $window.trigger(scrollEvent); });` creates the loop that continues to load all the items. When I comment out the `if (isLoadNeeded()){ $window.trigger(scrollEvent); });` I no longer load all the items without scrolling.
Patch to follow.
Comment #8
oheller commentedPatch removing the if(isLoadNeeded()){ $window.trigger(scrollEvent) });
Comment #9
attheshow commentedPatch #8 is working for us.
Comment #10
mattdeckerio commentedI applied this patch but found that it didn't work for me.
Further investigation revealed that the vertical positioning of [data-drupal-views-infinite-scroll-pager="automatic"] is what is used to determine if more results need to be loaded. In my case, this selector was appearing at the top of the view due to Drupal core's .visually-hidden which uses absolute positioning.
I moved this selector to the bottom of the view via css and the infinite scrolling now works as designed.
Comment #11
davisa commented#10 comment was useful and fixed it for me when used together with a patch. Thanks.
Comment #12
rdworianyn commentedThe patch in #8 and the CSS in #10 appear to correct the issue, but only when logged in. For anonymous usage, it still continues to scroll automatically. The reason that I found for this was that the views for logged in users typically contain the .contextual-region class as a wrapper for the view.
Since pager.offset().top looks for the closest parent element with a relative or absolute position, it will normally just work for anyone that has the contextual regions, since those have a default relative position.
To make this work for anonymous users, I just added a relative position to the view's parent element and then everything started working exactly as expected.
Hope this helps someone else with this issue or makes it easy to create a patch and correct this globally.
Comment #13
anybodyIs this still an issue with 2.0.x? If yes, please update the version and set the status active again with clear steps or (best) with a test showing what's broken. In this case it might require a reroll as MR.
2.0.x is the active development branch.
If nobody replies, we should assume this is fixed and close this issue outdated.
Thanks!
Comment #14
bobi-mel commentedThe issue is relevant in version 2.0.x. Fixed the bug using the patch in #8 and the CSS in #10.
Comment #15
anybodyPlease prepare a MR against 2.0.x and also see the related issues. Perhaps that should be better solved combined.
Adding this to the META issue for that reason.
Comment #16
briangervais commentedThe patch in #8 fixed the issue for us. The CSS in #10 wasn't needed in our case.
Comment #17
renukakulkarni commentedThe attached patch https://www.drupal.org/files/issues/2025-04-04/fix-infinite-loading-with... has been tested with the latest version of the module (2.0.3) and fixes the following issues:
Comment #18
renukakulkarni commentedComment #19
ivan.vujovicAny patches removing this block of code:
will undo the change that was done for https://www.drupal.org/project/views_infinite_scroll/issues/2916926.
Instead, I approve the CSS solutions suggested in comment #10.
In my case, these CSS fixes did the job: