Hey everyone — We are using typesense with `typese...
# community-help
e
Hey everyone — We are using typesense with
typesense-instantsearch-adapter
and
react-instantsearch-dom
in a NextJS application. We store the filters, search query, and currently selected hit id in the url query params as well for sharing purposes. We found that if we leave the search page open for a while without interacting — the next time we select a hit, typesense will resend the search request and cause search to load. This doesn’t happen if you are actively using the search and only happens when the tab becomes stale. I’ve found that commented this line in the attached screenshot which sets the selected hit id in the url query params causes the request to be sent if the tab is stale. Does anyone know why typesense would resend search requests in this situation/how to prevent it?
j
There is a client-side cache inside of the adapter, I suspect that expires when you leave the window open
e
If I comment the setParams out the request doesnt get sent so the cache only expires on url param update?
The url update is also a shallow route replace
j
URL updates are not handled by the adapter. So that's unrelated to the cache
The cache key is based on the search parameters for a given request
e
the search parameters are unchanged only the hit_id is changed but that is not used as a search parameter
f
When you pass in the server object in the adapter class, try to change
cacheSearchResultsForSeconds
to be a smaller value, like 10 seconds or so. By default it's 2 minutes, so if you set it to 10s you can verify that it sends the request when that expires
e
looks like it is indeed the cache and its because our url query params are connected to the filters so any change to the url triggers a search but cache was preventing it within 2 minutes
Do you have any docs/guides for implementing search that updates url query params as well in a better way?