DEV Community

Discussion on: Endless Scroll / Infinite Loading with Turbo Streams & Stimulus

Collapse
 
marckohlbrugge profile image
Marc Köhlbrugge

Thanks for sharing this! I used it on buildinpublic.com

There seems to be a timing issue with it though. If a "next page" starts loading, but you navigate away before it's finished, then this "next page" might be end up being appended to the new page you're on.

So you might be browsing User A's profile, click over to User B, and then see User A's second page appended to User B's profile.

One solution would be to abort the loading when a page is navigated away from. I think this can be done by deleting the IntersectionObserver on disconnect although I haven't tried that yet.