Stuck in fetching state if user changes page while fetching
Not sure if this is a bug or something I didn't configure properly but when a user changes the page while its loading, the query gets stuck infinitely in the "fetching state"
This is what I have in my query provider, I've been playing around the settings and I just can't figure out what's causing this annoying issue
I'm on v5.45.0
Looking for any help thanks! ๐๐ป
20 Replies
fascinating-indigoโข15mo ago
encountering the same issue
๐
@TkDodo ๐ฎ would mean a ton if you could help out there
this might be a v5 ubg
bug
fascinating-indigoโข15mo ago
GitHub
The query gets stuck at
fetching
status when re-fetched data has ...Describe the bug The query gets stuck at fetching status when you try to re-fetch data and it has cycles in it. Your minimal, reproducible example https://codesandbox.io/p/sandbox/react-query-mfsz4...
fascinating-indigoโข15mo ago
seems to be related
i think a workaround would be to just keep triggering with refetch till data is there
๐ค
fascinating-indigoโข15mo ago
GitHub
queries stuck on loading state in Next.js layout.tsx ยท Issue #7475 ...
Describe the bug I am using Clerk for auth, Next.js layout.tsx, TanStack query. When user gets redirected from /sign-in to /app/**, the queries inside of layout.tsx hangs on fetching/loading state ...
fascinating-indigoโข15mo ago
stuck on fetching for us too

fascinating-indigoโข15mo ago
similar thing to what the guy in the github issue has
@TkDodo ๐ฎ
๐
i know ure super busy
so apologies ๐
we got a deadline to hit ๐ฌ ๐
let me know if i can provide any more information
reproducing will be a bit difficult
@Ryu
are u using prefetchQuery
thats the thing that made it stuck in fetching for me
rival-blackโข15mo ago
if you put the QueryClient in react state and dont' have a global
loading.tsx
in next, it won't workfascinating-indigoโข15mo ago
we're now only prefetching on desktop when u can actually hover as opposed to mobile
to clarify: ours was inside a client component, and not in a layout ๐
rival-blackโข15mo ago
here's a good writeup about the problem:
https://github.com/TanStack/query/issues/6116#issuecomment-1904051005
GitHub
useSuspenseQuery infinite refetch after SSR (Next.js App Router) ยท ...
Describe the bug After a page using useSuspenseQuery is SSR'd in the Next.js app router, the query will infinitely refetch. This also occurs if a loading.tsx file is added. Your minimal, reprod...
rival-blackโข15mo ago
but as always, I can't help with just a screenshot / code snippet
if it's important to you, please take the time to make a standalone reproduction
@Tiger ๐
you're mentioning different issues here. one is about nextJs specifically, the other one about having circular data structures stored in the cache.
You might have an issue with similar symptoms, but that doesn't mean it's the same issue.
distinguished-blushOPโข15mo ago
Nope, I'm using the normal query
Omg I will try it out!
Thanks!
fascinating-indigoโข15mo ago
i fixed it brother ๐ซก
ty a ton
i see
different issues here
๐
rival-blackโข15mo ago
what was the fix ?
fascinating-indigoโข15mo ago
not using prefetch query on mobile
doing it onHover
rival-blackโข15mo ago
where did you do it before?
fascinating-indigoโข15mo ago
which also happens on mobile ๐
i did it during onhover
its like a chat list
two column view layout on desktop
so we only need the prefetch on desktop
i think what could be happening is prefetch happens but doesnt finish
and collides with useQuery
might be an edge case not taken care of in hindsight ๐ค
if i find some time over the next days i dont mind trying to reproduce it (super busy days ahead, but a week or two maybe)
rival-blackโข15mo ago
not really, that's a standard case. If prefetching doesn't finish, useQuery will just "pick up" the promise
fascinating-indigoโข15mo ago
i see
still strange becasue stuck in fetching
i'd expect it to finish then
distinguished-blushOPโข15mo ago
I think this solution has been working so far! Haven't encountered it again. Thank you so much!
distinguished-blushOPโข15mo ago
Unfortunately it seems to be still happening in production :< Not sure what's going on here
