Firstly I have refrained from using the stock implementation as well but I’d not refer to it as avoiding it. It only became relevant again once I noticed that my mostly independent implementation shows the same errant behaviour as seen in the stock version.
The sentiment of “until they add more features/support…” doesn’t sit well with me though. Shouldn’t we all be prepared or even eager to contributed towards such features/support rather than expect some “them” to do all the work before “we” are prepared to use it.
I have several questions regarding your approach, not the biggest of which is that your code using the data-scroll attribute to designated a scrolling container suggest that you’re ready for or expecting any number of scrolling containers to be present on the screen at once. Logically that’s not a problem but I’ve concluded from looking at UA scroll implementations across multiple devices including touch devices that the usability of interfaces decline rapidly when there’s more than one scrolling area on the screen at once. You end up with the highly frustrating user experiences associated with web pages carrying a boatload of advertisements all fighting for screen space and grabbing even accidental clicks which require the user to take extreme care to navigate around without clicking in the wrong places. Add to that the general disconnect there exist, again most apparent in touch devices, between whole page scroll with pinch-to-zoom and scrolling within a container. Apart from the technical aspects of implementing scroll event handling for the purposes of infinite scroll, would you lean into or away from multiple scroll containers on a page?
This forum’s software, specifically how code snippets are presented in scrollable multi-line containers which makes things quite awkward when you’re scrolling through the thread. I don’t profess to know what a better solution would be, and it could be argued that it’s better if you don’t mind clicking on the code segment by mistake as it has no consequences. But on more predatory pages you have to avoid clicking on adds designed to sweep you away to dark and dangerous places.
As for the code itself, I don’t know if it’s justified or not in a modern context, but I find the notion of adding and removing an event listener as a matter of course to be a good way of making sure that your long-running page will miss at least some events along the way just because the user triggered them at the worst possible instant. I don’t see may way clear to adopt that as a strategy. I prefer adding the event listener once and only once and handle turning it on or off to avoid runaway triggering explicitly using something akin to a semaphore or critical section.
So once the user scrolled to one end of the content, it’s all over, no more infinite scroll in the other direction and/or away from that end and back there again? Doesn’t sound like the kind of user interface I’d like to experience.