-
Notifications
You must be signed in to change notification settings - Fork 530
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
Duplicate Results in scopedResults with Routing Enabled in NextJS #6479
Comments
There's multiple things going on here:
This is because the main index has the same index name as the explicitly rendered index. This seems like a bug in useInstantSearch where it reads the results for all indices without deduplicating by indexId.
This will be related to timing where useInstantSearch is called before it renders the child indices, and thus they aren't available in scoped results. In theory they should be available as the search happens backend and all results are available for the other widgets, so this likely is also a bug in useInstantSearch. You can work around this by rendering your scopedResults using code after the indices are mounted (in a child component of the Search in your example, underneath the Index components. I'd like to look into if this pattern can be made possible in InstantSearch and the duplicate results can be fixed. What use case are you trying to create with scopedResults? Maybe you could use |
We are using If this can be achieved using |
The duplicate can be solved by removing (filtering out) the first result, as it's the same as the result of the root index. I've checked and unfortunately connectAutocomplete has the same behaviour. For ensuring this always renders the results (even on the server, before we find where the bug is happening), you can render the stats after the indices are mounted. |
That’s strange, I’m reproducing this issue on the provided CodeSandbox using the following steps:
I’ve attached a video below showing the issue as it appears for me in the CodeSandbox. Screen.Recording.2024-12-19.at.13.mp4 |
Ah I see, only when you're loading the page on a navigation, not when it's loaded ad-hoc. I can reproduce it but I don't find the source of the problem yet. |
🐛 Current behavior
When routing is enabled, navigating from one page to another page that displays search results (where a search parameter maps to the query used by Algolia) leads to duplicated entries in the scopedResults array returned by the useInstantSearch hook.
This issue occurs in a setup where we are using multi-index search with
InstantSearchNext
.🔍 Steps to reproduce
Steps to Reproduce:
q=london
.scopedResults
array in the console:Live reproduction
https://codesandbox.io/p/devbox/beautiful-maria-g85swl
💭 Expected behavior
The scopedResults do not contain duplicates.
Package version
next 15.0.4, react-instantsearch 7.13.9, react-instantsearch-nextjs 0.3.20, algoliasearch 5.17.1
Operating system
No response
Browser
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: