Closed anddoutoi closed 1 month ago
My reading of https://tanstack.com/query/latest/docs/framework/react/guides/important-defaults is that this is expected behavior. The query is mounted with initialData
that is stale, stale data is refetched under mount usually, but refetchOnMount is disabled, so the queryFn never runs.
Is there a use case you have were this behavior is being problematic? Curious why you would combine initialData
and setting refetchOnMount
to false - if it's for stopping the initial fetch you'd set initialDataFetchedAt
to Date.now()
and provide a staleTime
of like 30 seconds or so.
@DogPawHat this is a bit embarrassing but I think I was a bit tired when I stumbled upon this and judged it as an issue at first. I got it mixed up with refetchOnWindowFocus.
You’re right about the defaults.
Closing this and thanking for the rubber duck debugging.
Describe the bug
version: 5.59.0
See https://codesandbox.io/p/sandbox/react-query-initialdataupdatedat-refetchonmount-issue-m5yxps for minimal reproduction.
queryFn
is not called ifrefetchOnMount
isfalse
even ifinitialDataUpdatedAt
is old.This works as expected:
while this does not:
Your minimal, reproducible example
https://codesandbox.io/p/sandbox/react-query-initialdataupdatedat-refetchonmount-issue-m5yxps
Steps to reproduce
Use the following code:
refetchOnMount
tofalse
.Expected behavior
Expect it to work the same way when
refetchOnMount
istrue
.How often does this bug happen?
Every time
Screenshots or Videos
Platform
version: 5.59.0, all platforms
Tanstack Query adapter
None
TanStack Query version
5.59.0
TypeScript version
5.6
Additional context
No response