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

enabled option not respected when query is used in multiple places #138

Closed
sabasayer opened this issue Dec 19, 2024 · 0 comments
Closed
Labels
🐞 bug this isn't working as expected

Comments

@sabasayer
Copy link

I have created a query using the defineQuery method with the enabled option set to false by default. However, if I use this query in multiple places, it runs automatically, even though I haven't set enabled to true or called refresh or refetch.

Reproduction

  1. Query definition: The query is defined in test-query.ts.
  2. Usage: It is used in App.vue and pages/index.vue.

If the query is used in only one place, it works as expected and does not run. But when it's used in multiple places, the query runs automatically unless refetchOnMount is explicitly set to false.

Stackblitz Reproduction Link

The problem

The issue lies in query-store.ts.

image

When the query is used in one place, the logic does not enter the else block, so fetch or refresh is not called. However, when the query is used in multiple places, the else block is triggered, and if refetchOnMount is not set to false, the query is executed regardless of the enabled option.

This creates inconsistent behavior where the initial fetching logic depends on how many places the query is used.

Expected behavior

The query should not run unless one of the following conditions is met:

  1. enabled is explicitly set to true.
  2. refresh or refetch is called manually.
@github-project-automation github-project-automation bot moved this to 🆕 Triaging in Pinia Colada Roadmap Dec 19, 2024
@posva posva added the 🐞 bug this isn't working as expected label Dec 19, 2024
@posva posva moved this from 🆕 Triaging to Todo in Pinia Colada Roadmap Dec 19, 2024
@posva posva closed this as completed in a85ac9f Dec 19, 2024
@github-project-automation github-project-automation bot moved this from Todo to Done in Pinia Colada Roadmap Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug this isn't working as expected
Projects
Archived in project
Development

No branches or pull requests

2 participants