-
Notifications
You must be signed in to change notification settings - Fork 543
fix(infiniteHits): fix cache not using proper state #6671
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit e01ed54:
|
packages/instantsearch.js/src/connectors/infinite-hits/connectInfiniteHits.ts
Outdated
Show resolved
Hide resolved
packages/instantsearch.js/src/connectors/infinite-hits/__tests__/connectInfiniteHits-test.ts
Show resolved
Hide resolved
packages/instantsearch.js/src/connectors/infinite-hits/__tests__/connectInfiniteHits-test.ts
Show resolved
Hide resolved
packages/instantsearch.js/src/connectors/infinite-hits/__tests__/connectInfiniteHits-test.ts
Show resolved
Hide resolved
packages/instantsearch.js/src/connectors/infinite-hits/__tests__/connectInfiniteHits-test.ts
Outdated
Show resolved
Hide resolved
packages/instantsearch.js/src/connectors/infinite-hits/__tests__/connectInfiniteHits-test.ts
Outdated
Show resolved
Hide resolved
@@ -337,6 +336,11 @@ export default (function connectInfiniteHits< | |||
state: existingState, | |||
instantSearchInstance, | |||
}) { | |||
const getCacheHits = () => { | |||
const state = parent.getPreviousState() || existingState; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn’t this still causing us to read mismatching cache? We seem to be getting the state, not saving the cache variable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the issue was that the state was mismatching during the first pass of the getWidgetRenderState
when showPrevious
and showMore
is undefined. We want those functions to dynamically get the cache from a fn ref rather than use the cache that's passed to it at the start.
I've confirmed it again, this does solve the bug. The test case also fails with the change removed.
Summary
Using helper state for getting a page would cause cache miss since infinite hits doesn't have access to base level widgets in a multi index scenario. Using the latest cache directly fixes this.
CR-8905
Closes: #6653
Result
Get previous page works correctly when preloaded via routing and multi index.