Maximum callstack exceeded when using `prefetchQuery` in NextJS 14
Hey there!
I recently discovered this library and have been trying to swap out my generic OpenAPI client using fetch with
react-query using axios.
I'm in a NextJS 14 project using the app router and trying to handle SSR for initial load by following the Advanced SSR guide for the NextJS app router.
I have the following code:
Where getLeaderboard is an axios-based function generated by https://orval.dev. I've set up my providers as followed like the guide:
When I load this route in my browser, I get the following stack trace:
Can anyone point me in a direction as to what I'm doing wrong?
Thanks!8 Replies
foreign-sapphire•2y ago
useQueryClient
You create a qc on every render
implicit-lime•2y ago
@M00LTi I only see
new QueryClient() in the server component, where it's fine ?foreign-sapphire•2y ago
You are right!
Maybe a full stack trace would help…
exotic-emeraldOP•2y ago
i do make a queryClient in the provider file that’s used on client
orval also exports functions per query to get query options so i changed it to this: await queryClient.prefetchQuery(getGetLeaderboardQueryOptions());
i still get the same issue 😦
that function returns this:
exotic-emeraldOP•2y ago

exotic-emeraldOP•2y ago
sadly the full trace isn't that helpful
https://codesandbox.io/p/devbox/nextjs-react-query-mv3y2l
@TkDodo 🔮 here's a codesandbox of my implementation if this helps
🙂
implicit-lime•2y ago
you return a full axios response object, which is recursive and not serializable
extract data and just return that
first thing to do is to just
return { foo: "bar" } from your queryFn to rule out anything with actual data fetching
and of course it works with that: https://codesandbox.io/p/devbox/nextjs-react-query-forked-jq98tjexotic-emeraldOP•2y ago
i don't have permission to view that it seems but i think i get the idea thanks!