Skip to content

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

Merged
merged 5 commits into from
Jul 16, 2025
Merged

Conversation

shaejaz
Copy link
Contributor

@shaejaz shaejaz commented Jul 10, 2025

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.

Copy link

codesandbox-ci bot commented Jul 10, 2025

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:

Sandbox Source
example-react-instantsearch-next-app-dir-example Configuration

@shaejaz shaejaz linked an issue Jul 10, 2025 that may be closed by this pull request
1 task
@shaejaz shaejaz marked this pull request as ready for review July 15, 2025 10:21
@shaejaz shaejaz requested a review from Haroenv July 15, 2025 10:22
@@ -337,6 +336,11 @@ export default (function connectInfiniteHits<
state: existingState,
instantSearchInstance,
}) {
const getCacheHits = () => {
const state = parent.getPreviousState() || existingState;
Copy link
Contributor

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

Copy link
Contributor Author

@shaejaz shaejaz Jul 16, 2025

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.

@shaejaz shaejaz merged commit ec495e0 into master Jul 16, 2025
14 checks passed
@shaejaz shaejaz deleted the fix/ih-cached-hits branch July 16, 2025 10:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multi-Index Infinite Hits - Show More/Show Previous on refresh Bug
2 participants