Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vue-query] Callback for enabled does not provide query as parameter #7905

Open
Jak-Ch-ll opened this issue Aug 15, 2024 · 2 comments
Open

Comments

@Jak-Ch-ll
Copy link

Jak-Ch-ll commented Aug 15, 2024

Describe the bug

Since v5.48.0 and the changes in #7566 the enabled property for TanStack Query in general does accept a callback function, which provides the the query as argument.

Sadly this does not work with vue-query, as vue-query did already accept a getter since #6018, which does not provide the query. It technically is possible to return a function from the getter and that one will provide the query, but that does not fit the current types and docs. In addition it seems to run unnecessarily often, as you can see in my example repro.

Your minimal, reproducible example

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

Steps to reproduce

  1. Open the console
  2. The parameter outerQuery in undefined

Expected behavior

The parameter outerQuery to be the query

Tanstack Query adapter

vue-query

TanStack Query version

5.51.21

@DamianOsipiuk
Copy link
Contributor

This would only work if we also change the query type to be optional.
Otherwise it's a chicken and the egg problem.
First time when enabled getter would be run, we do not have observer yet and query might also not exist.

@Mini-ghost
Copy link
Contributor

This is just an idea, but I haven't had the time to verify its feasibility recently.

Perhaps we only need to add a length check here:

if (typeof clonedOptions.enabled === 'function') {
clonedOptions.enabled = clonedOptions.enabled()
}

if (
  typeof clonedOptions.enabled === 'function' &&
  clonedOptions.enabled.length === 0
) {
  clonedOptions.enabled = clonedOptions.enabled()
}

However, I haven’t thoroughly explored how to reinforce the type definition issue yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants