TanStack / query

🤖 Powerful asynchronous state management, server-state utilities and data fetching for the web. TS/JS, React Query, Solid Query, Svelte Query and Vue Query.
https://tanstack.com/query
MIT License
42.77k stars 2.93k forks source link

`setQueryData` not persisting data with `PersistQueryClientProvider` #8053

Closed HelNershingThapa closed 2 months ago

HelNershingThapa commented 2 months ago

Describe the bug

I'm experiencing an issue where data set using setQueryData is not being persisted when using PersistQueryClientProvider. I am using @react-native-async-storage/async-storage as the storage solution.

Your minimal, reproducible example

https://snack.expo.dev/@helnershingthapa/setquerydata-with-persistqueryclientprovider

Steps to reproduce

  1. Set up the PersistQueryClientProvider with a persister created using createAsyncStoragePersister.
  2. Use setQueryData to create query's data within a component. Click the button to update the query data.
  3. Reload the app and observe that the data ({ isButtonClicked: true }) is not persisted.

Expected behavior

The expectation is that data should persist across sessions.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

Tanstack Query adapter

react-query

TanStack Query version

v5.56.2

TypeScript version

v5.3.3

Additional context

No response

TkDodo commented 2 months ago

your issue reproduction works for me. Ater reloading the app, I do see isButtonClicked: true.

Note that writes are throttled (one write per second) so if you click the button and instantly quit the app, it likely won't be saved.