query icon indicating copy to clipboard operation
query copied to clipboard

enabled: false should not ever fire a query or populate the local store

Open mattsputnikdigital opened this issue 1 year ago • 1 comments

Describe the bug

I am having issues with useLoaderData having its promise (from React Query) cancelled due to a useQuery / subscription sitting above the route in question that would like to access the infinite data once it is populated. This then ruins the suspense / await component functionality as errors are propagated.

This is just to display a little bit of info in the header that would come from the infinite data total records count.

I have tried every different way to access the local store and setting enabled: false and not providing a queryFn would seem like the answer but it still fires a query with then creates a local version of empty data which causes other issues when the real query is fired.

I would like a way to either totally disable a query from ever running until a condition, such as data existing / or an active query running elsewhere. There doesn't seem to be a way to achieve this.

Your minimal, reproducible example

Sorry

Steps to reproduce

Unable to build a working demo at the moment

Expected behavior

I would like a way to totally disable a query and just return undefined if no data is already populated.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

All platforms, all browsers

Tanstack Query adapter

react-query

TanStack Query version

^5.29.2

TypeScript version

5.4.5

Additional context

No response

mattsputnikdigital avatar Apr 13 '24 16:04 mattsputnikdigital

I don't understand the issue so I'd need to see a reproduction to continue here please

TkDodo avatar Apr 13 '24 17:04 TkDodo

closing until we see a reproduction

TkDodo avatar Jul 17 '24 13:07 TkDodo

I'm having the same issue, essentially even with enabled false the fetch is still fired. is that expected?

edit it was because I was calling refetch once I disabled that, it worked as expected :)

coofzilla avatar Jul 30 '24 03:07 coofzilla