Closed shaejaz closed 1 month ago
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 d0397382fcb6a5612ab4160402f812c673ad8f1f:
Sandbox | Source |
---|---|
example-instantsearch-getting-started | Configuration |
example-react-instantsearch-getting-started | Configuration |
example-react-instantsearch-next-app-dir-example | Configuration |
example-react-instantsearch-next-routing-example | Configuration |
example-vue-instantsearch-getting-started | Configuration |
FX-2955
Summary Double queries happen when the state of instantsearch and insights no longer matches at the time of the first query on page load.
The
search-insights
onUserTokenChange
andonAuthenticatedUserTokenChange
callbacks are not able to set theuser-token
by the time the first search query is sent. When theuser-token
is changed by these callbacks, the state has changed from the first query. If a new query is scheduled after this(for example with dynamic widgets), the cache misses due to the changed state and second query is made.When
useCookie
is set to true, insights needs to create a anonymous token and save it as a cookie. Instantsearch would have the token updated with the callback from before, but this does not happen in time for the first query. So anonymous token generation and saving in cookies is now also handled by instantsearch.The insights queue is now being access in the middleware's
started
function to make sure any token set before instantsearch was started are part of the state by the time the first query is made.