-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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:
index
is 1, there's noqueries
stored yet- user requests the page,
data
query is created andinitialData
is set - user refreshes the page
- new
initialData
is passed touseQuery
, but there already is adata
query, so cached data is user on server render - page is rendered on client, since there's no
queries
in client bundle, newinitialData
is 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