Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useSuspenseQuery do not respect cached data in persister #8400

Open
lislon opened this issue Dec 4, 2024 · 0 comments
Open

useSuspenseQuery do not respect cached data in persister #8400

lislon opened this issue Dec 4, 2024 · 0 comments

Comments

@lislon
Copy link

lislon commented Dec 4, 2024

Describe the bug

I would like to pre-cache useQuery data, so when the user visits app a second time, the app will show stale data, and refetch in background.

I used persisted with useQuery before it was working as expected, but when I switched to useSuspenseQuery, the cached data is not used anymore.

const queryClient = new QueryClient({
  defaultOptions: {
    queries: {
      gcTime: 1000 * 60 * 60 * 24 * 7, // 7 days
      staleTime: 0,
    },
  },
});
// ...
function App() {
  useSuspenseQuery({
    queryKey: ['test'],
    queryFn: async () => {
      await sleep(1000);
      return 'ok';
    },
  });
  return <div>App is ready. Data cached. Try to reload</div>;
}

Your minimal, reproducible example

https://stackblitz.com/edit/vitejs-vite-ihky3z?file=index.tsx

Steps to reproduce

  1. Wait till app is loaded
  2. Observe: The data is cached in localStorage
  3. Press refresh button to reload the page

Expected behavior

The loader should not be shown for second time.

How often does this bug happen?

None

Screenshots or Videos

No response

Platform

  • Chrome 131.0.6778.87 (Official Build) (64-bit)

Tanstack Query adapter

react-query

TanStack Query version

5.62.2

TypeScript version

5.7.2

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant