Next.js Discord

Discord Forum

Do Server Components render multiple times?

Unanswered
Jersey Wooly posted this in #help-forum
Open in Discord
Jersey WoolyOP
I have a react server component page that handles user onboarding which can be completed in multiple places, one of which will redirect to my onboarding page with sign up data stored in session.
My understanding is that server components are only rendered/executed once on the server and then the client takes over. I'm now having an issue where the page seems to be rendered twice (two console.logs and two database entries), is my understanding of server components wrong or is there something else I'm missing?

Here's a simplified version of my code:
async function completeSignup(signupData) {
  console.log("DB CALL");
  await db.insertSignupData(signupData);
}

export default async function ServerPage() {
  const {hasSignedUp, signupData} = getSessionData();
  
  if (!hasSignedUp) {
    await completeSignup(signupData);
    return <DisplaySuccess />
  }
  
  return <SignupForm />
}


I'm using next 14.2 and react 18

0 Replies