Next.js Discord

Discord Forum

Next.js 14.2.4 – "Rendered more hooks than during the previous render" when using redirect/notFound

Unanswered
American Sable posted this in #help-forum
Open in Discord
American SableOP
In some routes, such as /jobs, I have RSC (React Server Components) where I call redirect() and notFound() inside an if block based on a cookie value. When I navigate to /jobs, instead of redirecting or showing the not-found page, I get a client-side exception:

Exception: Render more hooks than during previous render

Expected: Redirect to /404 page

3 Replies

American SableOP
This behavior is coming wherever I've used the redirect function in server components.
African Slender-snouted Crocodile
Does the same behavior occur for you using the notFound function?

https://nextjs.org/docs/app/api-reference/functions/not-found

Does the same issue still occur with all client child components commented out?
I would expect this to come from a client component.
If the behavior only occurs on redirect, the client component that's causing the issue might be a child of the page that was redirected to.