Hi all,
Central to Phoenix and LiveView’s charm is that most users, including myself, prefer to leave the bits of javascript coding it requires to the professionals. While that’s a wonderful thing, it also has the side-effect that when you do need to step into that world you have an extremely small set of very busy individuals involved enough to offer any insights or shared experiences. That’s where I’m finding myself today and I guess it means I’m reaching out to our javascript unicorns here.
I’m getting tripped up by the intricacies of implementing infinite scroll and I’m looking for others who may have written parts of, tested or used or tried to use the stock implementation that exists to support infinite scroll and perhaps encountered the same issues.
Since my pagination does not align with the offset and limit principle, my dom structure doesn’t align with the semantics of firstChild and lastChild and I need to infinite scrolling in both the horizontal and the vertical directions simultaneously I can’t directly use the provisions made for infinite scroll in hook.js and thus had to implement my own hook and support functions.
Before starting my own implementation I followed the example from the guide and though I got it working it never worked in a way I’d describe as robust - I could get it to scroll up or down one line at a time if done slowly, but when making big jumps or repeating even small jumps too quickly it seemed to lose track of things and either just stop scrolling or detect an overrun and rever to the first page. I thought at the time that I’d seen enough of how the hook and sample went about their business and started with my own implementstion.
Though doing my own implementation was rough for many reasons, the javascript I ended up with have little in common with the original except for the notion of a pendingOp. I even used a completely independent implementation of bounce rather than the stock code’s throttle implementation. I copied the pendingOp concept in an attempt to clean up the rather messy alternative of adding and removing event listeners to avoid the infinite loop created by calling element.scrollIntoView while handling a scroll event. I couldn’t faithfully copy the pendingOp concept since my code was structured differently so I just did something similar instead.
All of which points towards my code and the stock code having less and less in common. Yet, and this is what baffles me, I ended up with javascript scroll event handling that gets overwhelmed in what appears to be the sact same way - If I scroll in small steps, not too quickly, it behaves perfectly, but when I try to move around too quickly I get to a point where the content is physically scrolled to the one of the ends without the listener getting triggered for those events.
My working hypothesis is that the issue must lie in the debouncing or throttling mechanism being oblivious to the pendingOp semantics in both the stock and my own implementation so it ends up swallowing events that should fire and firing events that has no effect.
Any advances on that? If you have any experience with or insights into how the stock code is meant to work or under what conditions it fails I’d love to take your accounts of that on board before I choose which rabbit hole to try next.
To be clear, this is about things that happen with the stock standard InfiniteScroll hook as called upon by the example code in the LiveView guide. Posting my version of code that goes about its mildly different business in a slightly differently will just complicate the discussion. I believe if I can gain an understanding of what trips up the stock code it’s likely the same thing that’s tripping up my code. If I’m wrong about that it’s on me, but then at least we’d have managed to identify and hopefully addressed an issue with the standard LiveView code.
P.S. A potentially key issue I’ve encountered here is stems from the sample code provided in the LiveView guide under Client-side Integration / Bindings / Scroll events and infinite pagination is given as code snippets leaving a lot of guesswork in setting up a test bed for the facility. It might help if someone who genuinely understands how it is meant to work including what the requisite environment would be compiled a complete reference implementation of infinite pagination / scrolling as a gist or sub-project. It’s just a suggestion in acknowledgment of that possibility that the errant behaviour I found had been the consequence of incorrectly interpreting what the guide meant to convey to me.