Replies: 3 comments 4 replies
-
Are we talking about a hard page reload / navigation here? |
Beta Was this translation helpful? Give feedback.
-
@TkDodo That right there was the question I needed. We had setup react query wrong with our project. On every page navigation, it was re-rendering one of the base App components that setup the reactQuery instance, which re-initialized the state from local-storage. There was a race condition that was sometimes saving the local storage in time and often times not. For anyone else who runs into this issue, here's how we fixed it for gatsby.
|
Beta Was this translation helpful? Give feedback.
-
oh that's nice. in case you have a hard page reload for some reason, like What you can do in v4 (currently in alpha) is to use the separate persistQueryClientSave method to trigger a save. It is async, so you can await it, and then trigger the redirect. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
We're using react-query with localstorage as a persistent cache and gatsby as our framework.
We encountered an issue today where we were optimistically updating a query key, and immediately navigating to another page. The data was not getting persisted into local storage because that seems to be an async operation, and the page we navigated to had stale data.
We were able to hack it into working by wrapping our
navigate
function in asetTimeout
and setting a really low throttle timeout
`
It would be really nice if there was a hook into the
queryClient
that allowed us to tell it to persist the data immediately, before navigating to another page.Beta Was this translation helpful? Give feedback.
All reactions