Skip to content

Vue: Query key doesn't match the current value of ref used inside query function after invalidateQueries #6414

Closed
@henribru

Description

@henribru

Describe the bug

This seems like essentially the same problem as #5910, except with invalidateQueries instead of refetch. It also happens with resetQueries (maybe more?). Basically, the query key that's passed into the query function can be out of sync with the current value of the ref after the ref is changed.

Your minimal, reproducible example

https://stackblitz.com/edit/vitejs-vite-dnf3kd?file=src%2FApp.vue

Steps to reproduce

  1. Open up the reproduction
  2. Look at the console logs, which print:
foo foo
foo bar
bar bar

Notice that in in the second line, queryKey[1] and foo.value are out of sync. There's also an extra fetch due to this.

Expected behavior

I would have expected it to print:

foo foo
bar bar

where the query key is in sync with the ref and there's no redundant fetch.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • OS: Windows 10
  • Browser: Chrome
  • Version: 119

Tanstack Query adapter

vue-query

TanStack Query version

v5.8.4

TypeScript version

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions