No refetch on query key change
Repro: https://codesandbox.io/s/vue-query-keys-8c95g0?file=/src/App.vue
I'm having issues where my query does not refetch even though its query key has changed. If the component is remounting the query runs with the updated archived state. Am I missing something? I am using
@tanstack/vue-query + @lukemorales/query-key-factory
mauricewegner
CodeSandbox
vue-query-keys - CodeSandbox
vue-query-keys by mauricewegner using @lukemorales/query-key-factory, @tanstack/vue-query, axios, core-js, register-service-worker, tslib, vue
14 Replies
deep-jade•3y ago
Hi 👋
Have you tried using the dedicated developer tools to see if the query key is actually changing?
extended-salmonOP•3y ago
Hi @Louis 👋
Yes, the query key is actually changing but it does not show up as a new query unless the component remounts. Then the query appears as a new query with the updated archived state (which is coming from a state manager)
deep-jade•3y ago
It sounds like there's something odd at play here. Please can you provide a minimal reproduction? I'm not familiar with the query key factory package so I can't see if it's being misused
extended-salmonOP•3y ago
Will do
extended-salmonOP•3y ago
Here's a little repro @Louis
https://codesandbox.io/s/vue-query-keys-8c95g0?file=/src/App.vue
mauricewegner
CodeSandbox
vue-query-keys - CodeSandbox
vue-query-keys by mauricewegner using @lukemorales/query-key-factory, @tanstack/vue-query, axios, core-js, register-service-worker, tslib, vue
deep-jade•3y ago
Thanks. I didn't realise this was a Vue issue; I've never worked with Vue before but I noticed you have an invalid limit prop. Change the limit and have a look in the console, fix this issue and then let me know if the problem persists 🙂
extended-salmonOP•3y ago
Could you recheck? I'm not receiving errors on codesandbox about any invalid props
deep-jade•3y ago
Try changing the limit value and then checking the console
extended-salmonOP•3y ago
Ah yes i see what you mean
doesn't change the problem whatsoever, lemme update anyways
I've updated it but the core reason of the problem is that although this prop is changing the query does not automatically refetch
deep-jade•3y ago
I'm not familiar with Vue so I'll leave this for someone who is. Apologies I couldn't offer more help!
extended-salmonOP•3y ago
I could listen to the prop change and then manually refetch but as it is part of the query key it shouldn't be necessary
All good, thank you anyways 👍
fair-rose•3y ago
Maybe @MrMentor can have a look?
modern-teal•3y ago
Change
to
And it will work in this example.
Reason being
props is a reactive proxy and accessing and passing limit directly looses reactive wrapper.
This it the same situation as destructuring reactive where you loose reactivity
Other way would be to
And then access filters.value in queryFnextended-salmonOP•3y ago
@MrMentor That totally makes sense. It was indeed the lost reactivity which caused this issue. Thank you very much for your fast help guys 👍