Skip to content

refetchOnMount and queryClient.invalidateQueries() do not work as expected when using experimental_createQueryPersister #9667

@willwillems

Description

@willwillems

Describe the bug

When using the persistor, what we wanted to do was serve up the stored data as stale and immediately refetch. That is not the default behavior, so what we tried to do is set refetchOnMount to 'always'. This does not make it refetch on initial mount.

The second thing we tried is: when our app loads we invalidate all queries using queryClient.invalidateQueries(). But queries that haven't initialized yet are not invalidated. When not using the persistor, this makes total sense, but when you are using it, this leads to some very unexpected behavior.

Your minimal, reproducible example

https://stackblitz.com/edit/tanstack-query-xma74mr5?file=src%2FPosts.vue

Steps to reproduce

  1. Go to page
  2. Refresh page within 5m (stale time)
  3. Data is not re-fetched on page load

Expected behavior

I expect queryClient.invalidateQueries() or refetchOnMount: 'always' to make the data stale and refetched.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • OS mac OS
  • Browser Chrome & FF

Tanstack Query adapter

vue-query

TanStack Query version

5.89.0

TypeScript version

No response

Additional context

I love Tanstack Query and wanna use it but I just want the functionality like SWRV where the page initially loads with local storage data (that is marked as stale) and then immediately begins re-fetching.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions