InfiniteHits widget and cache error

Hello :wave:

I’m following up on this thread which is about the InstantSearch.js infiniteHits widget and cache setting not working as intended.

I’ve created a clean project. Source code can be found here.

I’ve created a video which shows the issue which you can view here.

In the video, you will see that when I click on the results: 83-erich, 64-rae or 56-jessamine, caching works as intended. The scroll position is restored when I leave and come back to the search page.

When I click on these results: 80-aline, 66-sarah, 55-eleanor, caching does not work. I’m returned to the top of the page instead of to the correct scroll position in search.

I’ve verified that this behaviour seems to happen in the latest version of Chrome, but not Safari.

As I’m new to Algolia, I’ve tried to follow the docs, but if this is user error, please let me know! :slight_smile:

I’m cc @haroen as you replied to my initial post. Hope this is ok to do. But welcome help from anyone on this.

why do you clear the client’s cache here? this will not have any impact on your page really, since the cache is per javascript runtime algolia-project/search-infinitehits.js at main · utxoutput/algolia-project · GitHub

Otherwise the scroll restoration is actually a browser feature that indeed works better in Safari than in Chrome. You can disable the browser’s restoration: History.scrollRestoration - Web APIs | MDN

and then add an event listener on the back button where you scrollTo the previously stored scroll position.

However, I would leave the situation as-is, browsers are bound to improve here in the future, and what’s working oddly on your site, might not work oddly anymore tomorrow

1 Like

Honest answer: I don’t know. I’m new at this. I thought it was the right thing to do. Will remove.

So I guess the short version is that what I see as a problem is not actually an issue. And I should leave things as it but delete the line you highlighted.

1 Like

In short, that would be my conclusion, yes. A “proper” solution would involve doing “single-page” page navigation (taking over the browser’s job with event listeners) as well as taking over the back button to restore scroll position. Since this is a very involved process, I can’t give you a simple “if this changes, it’s fixed for you” unfortunately, except that the scroll restoration problem is unrelated to InstantSearch at this point.

The cache clearing is indeed not needed!

1 Like

Haroen, thank you.

Appreciate the detailed response. Are you available for freelancing? :grin:

1 Like

Sorry, I don’t have time to freelance!


No problem, had to ask. Thanks again for the help.

1 Like