vue-query icon indicating copy to clipboard operation
vue-query copied to clipboard

useQueries doesn't seem to unpack deep ref options

Open Evertt opened this issue 3 years ago • 6 comments

I mean, I can do it myself, but I thought vue-query was made to do it for me. It works with the normal useQuery().

So I'm talking about the enabled option for example. Which can be a ref or a computed and then when you use it in useQuery() then it automatically unwraps the ref/computed. But when I use it in useQueries() I get an error from react-query that enabled is not a boolean and indeed, when I check, it is indeed still a computed.

Oh yeah I'm using version 1.25.2 btw.

Evertt avatar Aug 09 '22 16:08 Evertt

Well, In v1 only useQuery/useInfiniteQuery unwrap refs automatically. In v2 all composables besides useQueries.

So it is something that needs to be added and possibly back ported to v1

DamianOsipiuk avatar Aug 09 '22 17:08 DamianOsipiuk

I think so, personally. Like it's just strange that useQuery() would cloneDeepUnref the options, but useQueries() wouldn't. And unfortunately you don't export cloneDeepUnref, so now I have to copy that function to my own src folder.

Evertt avatar Aug 10 '22 05:08 Evertt

The idea is not to implement it on your side, but contribute to the repository and add a support for it for everyone to use 😉

DamianOsipiuk avatar Aug 10 '22 06:08 DamianOsipiuk

@Evertt Try https://github.com/DamianOsipiuk/vue-query/releases/tag/v1.26.0

DamianOsipiuk avatar Aug 22 '22 21:08 DamianOsipiuk

I tried, and at first it seemed to work, but later it seemed like the attributes that I get back every query, like data, stopped being reactive. So I went back to 1.25 and my previous workaround. 😬

Edit

Wait, that's not precise enough. If I asked for the data attribute of one of those queries immediately on page load, then it would work. But I also have a popover element, which means that when I hover over an element, a new component appears, that uses the same list of useQueries() as the first component did. But it gets a different query (at a different index in the list) and then the data attribute of that query isn't reactive for some reason.

While it was reactive while I was using my workaround. 😅

Evertt avatar Aug 24 '22 19:08 Evertt

Few question:

  • could you check if with the latest version you are passing queries array as reactive?
  • is is possible that your workaround stabilized the queries order in the array?
  • what Vue version are you using?

DamianOsipiuk avatar Aug 24 '22 21:08 DamianOsipiuk

This should be fixed in @tanstack/vue-query

DamianOsipiuk avatar Feb 10 '23 20:02 DamianOsipiuk