question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Refresh does not request pages in infinite hits again

See original GitHub issue

Describe the bug 🐛

When updating the refresh token, infinite hits will not react to the refetch.

To Reproduce 🔍

Steps to reproduce the behavior:

  1. go to the example
  2. trigger next page
  3. refresh
  4. see no changes in the infinite hits, even if the index would have changed

The example’s index can be changed to an index you control where you make changes to make the effect clearer.

https://codesandbox.io/s/react-instantsearch-app-dq2ro

Expected behavior 💭

Infinite hits reacts to refresh, either by:

  1. clearing the cache completely and restarting on the current page
  2. clearing the cache and the state and restarting on page 0

Likely we should go for option 2, unless there’s a showPrevious.

Additional context

Add any other context about the problem here.

When refresh happens, we need to make sure the infinite hits internal cache is also invalidated.

On React Native, where the list component itself is stateful, we can not rely on the “key” hack, because it rerenders with an empty state when we simply clear the cache. What could be an option is:

  1. clear cache
  2. redo current search
  3. save in cache
  4. rerender

The problem is that you can’t do that as a user reasonably, since you don’t have access to the helper state.

A possible solution is:

In the function refresh in InstantSearchManager, emit an event to all widgets. Then in InfiniteHits, listen to that event, and clear the internal cache as we expect.

Another potential solution is to return a promise from the search which happens in refresh. This should allow people to rerender the InfiniteHits component manually.

Relevant pieces of code:

https://github.com/algolia/react-instantsearch/blob/ec9e0fbd6106d1c3e47f1dbfa6eaac3e20af6bd5/packages/react-instantsearch-core/src/core/createInstantSearchManager.js#L69-L72

Relevant issues:

https://github.com/algolia/react-instantsearch/issues/2464

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:60 (22 by maintainers)

github_iconTop GitHub Comments

4reactions
Haroenvcommented, Oct 28, 2020

Yes, the connector will accept the cache prop as well @meck93. You can check that by using a custom cache which has some logging 😃

3reactions
alexpchincommented, Sep 10, 2019

Hi all,

I was just wondering whether there was any update to this? I’m still having a little trouble “rolling my own” infinite hits using the API. My setup requires the ability to search, show no duplicated results, have infinite scroll etc. Everything with the ConnectInfiniteHits works except the problem stated above.

Thanks in advance, Alex

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found