T
TanStack10mo ago
robust-apricot

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
generous-apricot
generous-apricot10mo 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.
robust-apricot
robust-apricotOP10mo 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
generous-apricot
generous-apricot10mo 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?