Preserve scroll position and dynamically loaded items with infinite scroll #989
Replies: 2 comments 3 replies
-
|
Please open the codesandbox app in a separate tab to see the problem :) Instructions to reproduce with the codesandbox. This is without dynamically loaded items and createHistory things:
This is what happens with dynamically loaded content and createHistory:
Thanks in advance, love the work you do! |
Beta Was this translation helpful? Give feedback.
-
|
Hi @Sidstumple We have a demo for infinite scroll + swup here: https://glitch.com/edit/#!/swup-demo-infinite-scroll-cache?path=app.js I see a few problems with your linked demo:
{
resolveUrl: (url) => {
if (url.startsWith('/projects/?load_more=')) {
return '/projects/';
}
return url;
}
}But as I mentioned before, I'd strongly advise against any history manipulation in this case. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
What did you expect? 🧐
I load more content when the user reaches the end of a container, I also change the URL with a query string (f.e.
?load_more=2). I update the URL using createHistoryRecord, and window.history.pushState (if you could update the docs here to make it more clear you need both, that would be great!).I expect when I click one of the newly loaded items and I go back one page that the scroll position is the same as it was before I clicked the item.
What actually happened? 😵💫
When I click one of the initially loaded items it works as expected, but when I click the dynamically loaded item it scrolls to the top of the page.
Recording from my project:
https://share.cleanshot.com/ySDwNB9Y
I believe the scroll position is not saved correctly when navigating after a createHistoryRecord or something??
Swup and plugin versions 📝
What browsers are you seeing the problem on? 🧭
Chrome, Firefox, Safari, Microsoft Edge
Relevant log output 🤓
URL to minimal reproduction 🔗
https://codesandbox.io/p/devbox/quizzical-kepler-4tj68v?workspaceId=ws_MWvEgzFMVziG8dH1did9UG
Checked all these? 📚
Beta Was this translation helpful? Give feedback.
All reactions