T
TanStackโ€ข15mo ago
distinguished-blush

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! ๐Ÿ™๐Ÿป
"use client"

import React from "react"
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"

export function ReactQueryProvider({
children,
}: {
children: React.ReactNode
}) {
const [queryClient] = React.useState(
new QueryClient({
defaultOptions: {
queries: {
retry: true,
staleTime: 5 * 1000,
networkMode: "always",
retryDelay: 5000,
},
},
})
)

return (
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
)
}
"use client"

import React from "react"
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"

export function ReactQueryProvider({
children,
}: {
children: React.ReactNode
}) {
const [queryClient] = React.useState(
new QueryClient({
defaultOptions: {
queries: {
retry: true,
staleTime: 5 * 1000,
networkMode: "always",
retryDelay: 5000,
},
},
})
)

return (
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
)
}
20 Replies
fascinating-indigo
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
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
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
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
fascinating-indigoโ€ข15mo ago
stuck on fetching for us too
No description
fascinating-indigo
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
rival-blackโ€ข15mo ago
if you put the QueryClient in react state and dont' have a global loading.tsx in next, it won't work
fascinating-indigo
fascinating-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
rival-blackโ€ข15mo ago
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
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-blush
distinguished-blushOPโ€ข15mo ago
Nope, I'm using the normal query Omg I will try it out! Thanks!
fascinating-indigo
fascinating-indigoโ€ข15mo ago
i fixed it brother ๐Ÿซก ty a ton i see different issues here ๐Ÿ‘
rival-black
rival-blackโ€ข15mo ago
what was the fix ?
fascinating-indigo
fascinating-indigoโ€ข15mo ago
not using prefetch query on mobile doing it onHover
rival-black
rival-blackโ€ข15mo ago
where did you do it before?
fascinating-indigo
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
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
fascinating-indigoโ€ข15mo ago
i see still strange becasue stuck in fetching i'd expect it to finish then
distinguished-blush
distinguished-blushOPโ€ข15mo ago
I think this solution has been working so far! Haven't encountered it again. Thank you so much!
distinguished-blush
distinguished-blushOPโ€ข15mo ago
Unfortunately it seems to be still happening in production :< Not sure what's going on here
No description

Did you find this page helpful?