Next.js Discord

Discord Forum

redirect() => "Error: Server Functions cannot be called during initial render. ..."

Unanswered
German Hound posted this in #help-forum
Open in Discord
German HoundOP
I use Nextjs 14, when I use redirect function of next/navigation in Layout, I receive an error:
Error: Server Functions cannot be called during initial render. This would create a fetch waterfall. Try to use a Server Component to pass data to Client Components instead.

8 Replies

What is isLogged @German Hound
Show the function code pls
Are you sure it's from the redirect, does removing it fix the error
@Arinji Are you sure it's from the redirect, does removing it fix the error
German HoundOP
Certainly, when I comment line redirect, code is run right
Sphecid wasp
@German Hound what you might need to do is either add 'use server' to the top of where the FUNCTION starts, or move the function to another file and add 'use server' to the top of that file.
German HoundOP
Thank all, I found bug, It is in Logout component after redirect. I call direct logout action without inside useEffect.