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•9mo 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-yellowOP•9mo 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 thatexotic-emerald•9mo ago
then it maybe wasn't really stale: https://github.com/TanStack/query/blob/aef7ba209aeb53338dca262d48aef5719e8ac792/packages/query-core/src/queryClient.ts#L156-L161
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