TanStackT
TanStack17mo ago
19 replies
constitutional-coral

Tips for debugging over-fetching of data / duplication of http requests?

can anyone share tips / pointers for how to debug duplicated http requests emanating from react-query usage?

specific behavior i'm seeing is that a single query invoked via
ensureQueryData()
is re-run despite having just fetched and returned valid data only a few ticks prior. this results in 2 http requests to the same endpoint with the same parameters returning the same data. as far as i can tell, this is NOT due to react's strict mode mechanism as i see it in
production
as well.

i've been manually inspecting the cache with
queryClient.getQueryCache().getAll()
but from that perspective, everything should be working as expected (iow, i didn't see any mislabeled cache items or duplicate entries).

by default, should calling
.ensureQueryData()
multiple times result in multiple fetches? if not, are fetches de-duplicated prior to receiving the http response? or is it possible to yield multiple http requests just by calling
.ensureQueryData()
multiple times prior to receiving the http response?

how should i further debug this?
Was this page helpful?