Skip to content
Source
Sign inSign up
TanStack/query

`refetchOnMount: 'always'` does not work with persister #9889

ClosedNamesMT(GitHub profile, opens in a new tab) opened this issue 2 comments

Describe the bug

refetchOnMount: 'always' does not trigger an API refetch with persister, as the first fetch for a query with persister is to load from the store and not API call.

Your minimal, reproducible example

TBA

Steps to reproduce

  1. Use useQuery with refetchOnMount: 'always', persister, and staleTime.
  2. Open browser network tab and reload the page, no API call is made.

Expected behavior

An API call is made to refetch the data.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

Tanstack Query adapter

None

TanStack Query version

v5.90.7

TypeScript version

No response

Additional context

No response

  1. If we are talking about createPersister then refetchOnRestore option should potentially solve your issue.

    /**
       * If set to `true`, the query will refetch on successful query restoration if the data is stale.
       * If set to `false`, the query will not refetch on successful query restoration.
       * If set to `'always'`, the query will always refetch on successful query restoration.
       * Defaults to `true`.
       */
      refetchOnRestore?: boolean | 'always'

    https://tanstack.com/query/latest/docs/framework/react/plugins/createPersister#options

  2. This works with PersistQueryClientProvider out of the box:

    https://github.com/TanStack/query/blob/f4a0cd596b97f15f62b60ebf1490a06c6311bc1b/packages/react-query-persist-client/src/tests/PersistQueryClientProvider.test.tsx#L352-L419

  3. TkDodo closed this

  4. TkDodo added labelsworks as designed

Sign in to join this conversation.