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

Disabled query still creates queryCache entry #137

Open
niklaswolf opened this issue Dec 17, 2024 · 0 comments
Open

Disabled query still creates queryCache entry #137

niklaswolf opened this issue Dec 17, 2024 · 0 comments

Comments

@niklaswolf
Copy link

If a query is disabled initially, there is still an entry created in the query-cache for it.
Let's take the following example to build something like a useLazyQuery:

export const useLazyQuery = defineQuery(() => {
  const externalId = ref<string>('')

  const {
    data,
    refresh,
    status
  } = useQuery({
    key: () => ['group', `external-${externalId.value}`],
    query: async () => {
      // fetch something here
    },
    enabled: false
  })

  async function fetchAsync(id: string) {
    externalId.value = id
    const { data } = await refresh()

    return data
  }

return {data, fetchAsync}

It can be observed, that a cache entry is created for the disabled query before the first fetch.
It has the key external-.
After the fetchAsync function has been called the first time, another cache entry external-<ID> is created.

Seems like this doesn't break anything in my app right now, but I discovered it during debugging and thought this is worth reporting.

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

No branches or pull requests

1 participant