Error: Switched to client rendering because the server rendering errored: UNAUTHORIZED
What could be the possible reason for this error?
This is how my NextJS structure looks when using tRPC.
- /app/settings/page.tsx
- /components/settings/view/categories-view.tesx
- /components/settings/section/categories-section.tsx

16 Replies
Cookies aren’t being properly passed on when fetching in SSR, still a restriction with useSuspenseQuery.
when I tried to comment back the
shouldDehydrateQuery I'm not getting that error, but the continuously sending a request is my problem when I'm not logged in and try to refresh the page, It will always sending a request on the api even I have a Suspense and ErrorBoundary, so on the network tab on chrome dev tools I have a thousands request
Yeah, you shouldn’t retry on server
I use this to prevent retries on server render:
so the
shouldDehydrateQuery should be enabled? and I will only add this to prevent the continuously sending request?here's the sample of the error that I'm talking about continuously sending request

when the
shouldDehydrateQuery is enabled
even I have Suspense and ErrorBoundaryYou should leave the shouldDehydrateQuery as is
Keep whatever the defaults were given by trpc
Okay thank you, I will try your code.
And actually, the guide I followed is this tRPG Tanstack React Query (Server Components).
Yeah, they sometimes do not provide good defaults
your code is missing the variable of
isServer where I can get this
can you provide the full code? @BeBoRE
React query gives you this
oohh I see, thank you, I'm new to trpc and react query, I just following the youtube clone by @CodeWithAntonio
I am still getting this issue!
What was the solve for this? @heyitsiveen
I have the same
error, but in my case is because on the first page load (in nextjs) the headers and cookies are "undefined".
I tried this code:
but the same error, is there a way to await for the headers or something to avoid the error? (the stack for the backend is hono + better auth btw)

