Initial client side request being made when using a portal with SSR enabled
lechinoix opened this issue Β· comments
π Current behavior
When using an instant search hook inside a portal, client side requests are triggered inducing a raise in requests consumption. I do not understand why so the example might be misleading to the actual root cause sorry :/
π Steps to reproduce
- Load the page
- It will be rendered server side (1 query to Algolia)
- It will then be rendered client side with the server state
- But a useless client side request to Algolia is also made
Live reproduction
https://codesandbox.io/p/sandbox/loving-danilo-ghkkxl
π Expected behavior
No client side request to Algolia on page load
Package version
react-instantsearch-hooks: 6.44.1, algoliasearch: 4.14.3
Operating system
macOS
Browser
Chrome
Code of Conduct
- I agree to follow this project's Code of Conduct
This is happening because every widget mount and unmount triggers a new network request. Because a different widget is mounted on the client than on the server, InstantSearch does not know that this request is already "done".
The cache is not shared between the client and the server, the first request on client is simply skipped, but that means if it needs to be done a second time, it won't be skipped.
I think the way to solve this would be to change the NoSSR implementation from NoSSR > Panel > CurrentRefinements
to SSR ? CurrentRefinements : Panel > CurrentRefinements
or equivalent, which keeps the widgets mounted static.