Next.js Discord

Discord Forum

Refetching server component payload on mutation

Unanswered
Siamese Crocodile posted this in #help-forum
Open in Discord
Siamese CrocodileOP
I've a home page that runs a function that checks session

    const sessionId = (await cookies()).get(SESSION_COOKIE)?.value;

    if (!sessionId) {
      return null;
    }

  return <div />


And a login dialog that runs a client side mutation which sets up this cookie (external backend sets it)

After sucesfull mutation I want to refetch the server components because we actually have this cookie now but calling router.refresh() from next/navigation does not work and components still do have old payload.

Only solution that I found is to create a server action that uses revalidatePath('/', 'layout') when client side mutation succeds.

That's not desired - can't I refresh it somehow client side without messing up with server actions?

0 Replies