You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
useSuspenseQuery ignores the staleTime config parameter when it is a function instead of a number.
// staleTime number - ✅ worksuseSuspenseQuery({staleTime: Infinity,// ...})// staleTime function - ❌ does not work: staleTime value defaults to a value of 1 second insteaduseSuspenseQuery({staleTime: ()=>Infinity,// ...})
exportconstensureSuspenseTimers=(defaultedOptions: DefaultedQueryObserverOptions<any,any,any,any,any>,)=>{if(defaultedOptions.suspense){// Always set stale time when using suspense to prevent// fetching again when directly mounting after suspendingif(typeofdefaultedOptions.staleTime!=='number'){// ❗🚩Issue heredefaultedOptions.staleTime=1000}if(typeofdefaultedOptions.gcTime==='number'){defaultedOptions.gcTime=Math.max(defaultedOptions.gcTime,1000)}}}
Describe the bug
useSuspenseQuery
ignores thestaleTime
config parameter when it is a function instead of a number.Your minimal, reproducible example
https://codesandbox.io/p/github/afdca/tanstack-query-suspense-staletime/master
Steps to reproduce
Expected behavior
useSuspenseQuery
should not ignore thestaleTime
config parameter when it is a function.How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
Tanstack Query adapter
react-query
TanStack Query version
v5.59.12
TypeScript version
v5.6.3
Additional context
The issue seems to come from the
ensureSuspenseTimers
function: https://github.com/TanStack/query/blob/main/packages/react-query/src/suspense.ts#L27The following fix should work:
The text was updated successfully, but these errors were encountered: