T
TanStackโ€ข2y ago
wise-white

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
helpful-purple
helpful-purpleโ€ข2y ago
encountering the same issue ๐Ÿ™ @TkDodo ๐Ÿ”ฎ would mean a ton if you could help out there this might be a v5 ubg bug
helpful-purple
helpful-purpleโ€ข2y 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...
helpful-purple
helpful-purpleโ€ข2y ago
seems to be related i think a workaround would be to just keep triggering with refetch till data is there ๐Ÿค”
helpful-purple
helpful-purpleโ€ข2y 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 ...
helpful-purple
helpful-purpleโ€ข2y ago
stuck on fetching for us too
No description
helpful-purple
helpful-purpleโ€ข2y 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
equal-jade
equal-jadeโ€ข2y ago
if you put the QueryClient in react state and dont' have a global loading.tsx in next, it won't work
helpful-purple
helpful-purpleโ€ข2y 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 ๐Ÿ‘
equal-jade
equal-jadeโ€ข2y 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...
equal-jade
equal-jadeโ€ข2y 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.
wise-white
wise-whiteOPโ€ข2y ago
Nope, I'm using the normal query Omg I will try it out! Thanks!
helpful-purple
helpful-purpleโ€ข2y ago
i fixed it brother ๐Ÿซก ty a ton i see different issues here ๐Ÿ‘
equal-jade
equal-jadeโ€ข2y ago
what was the fix ?
helpful-purple
helpful-purpleโ€ข2y ago
not using prefetch query on mobile doing it onHover
equal-jade
equal-jadeโ€ข2y ago
where did you do it before?
helpful-purple
helpful-purpleโ€ข2y 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)
equal-jade
equal-jadeโ€ข2y ago
not really, that's a standard case. If prefetching doesn't finish, useQuery will just "pick up" the promise
helpful-purple
helpful-purpleโ€ข2y ago
i see still strange becasue stuck in fetching i'd expect it to finish then
wise-white
wise-whiteOPโ€ข2y ago
I think this solution has been working so far! Haven't encountered it again. Thank you so much!
wise-white
wise-whiteOPโ€ข2y 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?