-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Closed
Description
I've started to use react-query with next.js SSR using initialData option.
It works pretty good, but looks like queries are cached in server js bundle and are used across all requests.
Here's a minimal example reproducing the issue: https://codesandbox.io/s/react-query-ssr-cache-rkfsh
And a GIF which demonstrates the issue:

Note, that user index is incremented every time, but server always renders 1.
Here's what happens:
indexis 1, there's noqueriesstored yet- user requests the page,
dataquery is created andinitialDatais set - user refreshes the page
- new
initialDatais passed touseQuery, but there already is adataquery, so cached data is user on server render - page is rendered on client, since there's no
queriesin client bundle, newinitialDatais used
I've also checked if swr suffer from the same issue, but it works just fine - see https://codesandbox.io/s/swr-ssr-cache-qrmgn
Do you have any idea how it can be handled on react-query side?
As a workaround, I'm calling clearCachedQueries in _document.getInitialProps, which clears cached queries on server on every request
Metadata
Metadata
Assignees
Labels
No labels