I’m working on a small app in Next.js, and I’ve not quite wrapped my head around the client-side vs server-side rendering.
I’ve been working from this great guide on setting up NextJS with Supabase.
According to the Next.js doc:
Once "use client" is defined in a file, all other modules imported into it, including child components, are considered part of the client bundle
So if I’m using an AuthProvider
to wrap the app (as in the guide), but that AuthProvider
is marked "use client"
, I’m wondering if the {children}
in the layout are also automatically part of the client bundle.
My guess is "no", because they aren’t children of the AuthProvider
, just adjacent ReactElements (or something), but I’d appreciate someone confirming and clarifying the terminology for me.
// AuthProvider.tsx
"use client";
...
// layout.tsx
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html lang="en">
<body>
<AuthProvider>
{children}
</AuthProvider>
</body>
</html>
);
}
Thanks!
2
Answers
You cannot call in a client component body a server component, but it’s totally fine to pass it as part of its
props
, for example withchildren
as you can read on the doc:But you can pass your server component to the client component as part of its
props
:I am not pretty sure about the answer
I had a similar situation couple of days ago & found a snippet of code that was of great benefit to me.
Then you can wrap any part of your application (or your entire app) with this wrapper which prevents SSR and guarantee a CS components.