T
TanStack9mo ago
tame-yellow

ensureQueryData and preloading routes

Should ensureQueryData refetch stale data when used in a tanstack router loader and a Link to that route is set to preload? I'd expect the page data to be already loaded when navigating Links, but the stale data is briefly displayed before the new data is fetched.
3 Replies
exotic-emerald
exotic-emerald9mo ago
it doesn't - it only ensures that you get any kind of data, so when stale data is in the cache, it will just return that and do nothing. you can pass revalidateIfStale: true to trigger a revalidation in the background.
tame-yellow
tame-yellowOP9mo ago
Hmmm okay thanks! I did try revalidateIfStale: true within my ensureQueryData but it didn't seem to change anything. Not sure if its something on my router config causing that
exotic-emerald
exotic-emerald9mo ago
GitHub
query/packages/query-core/src/queryClient.ts at aef7ba209aeb53338dc...
🤖 Powerful asynchronous state management, server-state utilities and data fetching for the web. TS/JS, React Query, Solid Query, Svelte Query and Vue Query. - TanStack/query

Did you find this page helpful?