Next.js App Router - useQuery client-side only? #6136
-
Apologies if this has already been asked, couldn't find a definite answer. As the title suggests, I'm trying to use RQ with Next.js 13 and the app router but am a little confused about how exactly it's meant to function for client-side only fetching. The problem I'm running into is that despite not setting up any of the hydration or initial data pre-fetching, when I use I've confirmed that it's running on the server because I get a nice stack trace when fetch tries to build a URL from a relative path to my route handler e.g. Is there a way to stop Appreciate any insights, definitely still getting to grips with the brave new app router world! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Solved my issue, kinda... The query I was running had suspense enabled, which I'd hoped would mean my client-component marked page would begin rendering (client side), suspend due to data fetching and show my Unfortunately, enabling suspense seems to trigger Looking at the docs for v4, I found:
Given I'm not wanting to server render, this suggests that there should be no attempt to fetch on the server. Or is it not possible to use suspense client side only like this? Entirely possible I've misunderstood how suspense is meant to work! Edit: Reading the v5 docs for suspense gives me the feeling that the only way to use suspense is to make sure all queries are set up to pre-fetch on the server. Just that excerpt from the v4 docs that had me confused! |
Beta Was this translation helpful? Give feedback.
Solved my issue, kinda...
The query I was running had suspense enabled, which I'd hoped would mean my client-component marked page would begin rendering (client side), suspend due to data fetching and show my
loading.tsx
page, then it'd un-suspend once the data had finished fetching client-side.Unfortunately, enabling suspense seems to trigger
useQuery
to run on the server. Because it doesn't have access to cookies, the requests fail (I can see this happening in my Nextjs dev server logs) and it's several seconds until RQ gives up on the server, everything renders in the browser and the requests go through as normal.Looking at the docs for v4, I found:
Similarily, you must currently pre…