Question regarding mental model for client/server components & fine grained seperation bw them
Unanswered
Spectacled bear posted this in #help-forum
Spectacled bearOP
I've understood that server components basically allow us to do server side rendering and handling caching on a component level instead of page level. One thing I wanted to ask was regarding static html.
Here we have 10000 lines of html that will not require data fetching or any execution of javascript on server side for its logic, it also has no interactivity.
Here the 10000 lines of static html are seperated into a server component, the button that requires interactivity and makes use of useState is turned into a client component and is embedded inside the ServerComponent.
Since nextjs 13 will pre render the client components anyway, does it make sense to seperate static html into server components even though they're not making use of any javascript server-side, for example fetching data from database? Would including those 10000 lines of static html in a client component have any downsides?
Here we have 10000 lines of html that will not require data fetching or any execution of javascript on server side for its logic, it also has no interactivity.
"use client";
import { useState } from "react";
function ClientComponent() {
const [state, setState] = useState<number>(0);
function increase() {
setState((prevState) => prevState + 1);
}
return (
<div>
{/* ...10000 lines of static html that doesn't need interactivity */}
<button onClick={increase}>+ Increase</button>
</div>
);
}Here the 10000 lines of static html are seperated into a server component, the button that requires interactivity and makes use of useState is turned into a client component and is embedded inside the ServerComponent.
"use server";
async function ServerComponent() {
return (
<div>
{/* ...10000 lines of static html that doesn't need interactivity */}
<ClientComponent />
</div>
);
}
"use client";
import { useState } from "react";
function ClientComponent() {
const [state, setState] = useState<number>(0);
function increase() {
setState((prevState) => prevState + 1);
}
return <button onClick={increase}>Increase</button>;
}Since nextjs 13 will pre render the client components anyway, does it make sense to seperate static html into server components even though they're not making use of any javascript server-side, for example fetching data from database? Would including those 10000 lines of static html in a client component have any downsides?
10 Replies
Spectacled bearOP
whoever's replying please tag me so i get the notification
@Spectacled bear I've understood that server components basically allow us to do server side rendering and handling caching on a component level instead of page level. One thing I wanted to ask was regarding static html.
Here we have 10000 lines of html that will not require data fetching or any execution of javascript on server side for its logic, it also has no interactivity.
ts
"use client";
import { useState } from "react";
function ClientComponent() {
const [state, setState] = useState<number>(0);
function increase() {
setState((prevState) => prevState + 1);
}
return (
<div>
{/* ...10000 lines of static html that doesn't need interactivity */}
<button onClick={increase}>+ Increase</button>
</div>
);
}
Here the 10000 lines of static html are seperated into a server component, the button that requires interactivity and makes use of useState is turned into a client component and is embedded inside the ServerComponent.
ts
"use server";
async function ServerComponent() {
return (
<div>
{/* ...10000 lines of static html that doesn't need interactivity */}
<ClientComponent />
</div>
);
}
"use client";
import { useState } from "react";
function ClientComponent() {
const [state, setState] = useState<number>(0);
function increase() {
setState((prevState) => prevState + 1);
}
return <button onClick={increase}>Increase</button>;
}
Since nextjs 13 will pre render the client components anyway, does it make sense to seperate static html into server components even though they're not making use of any javascript server-side, for example fetching data from database? Would including those 10000 lines of static html in a client component have any downsides?
well generally, most of the time, you want to leave out the non-interactive part in the server ESPECIALLY if you have 100000 lines. Itd be nice to send the user the html version of those 10000000 lines instead of rendering it again request time right? but then again
As of now, based on the docs, next.js is not yet able to mix static server components with dynamic server components.
But I haven't fully test if those 10000000000 lines of html codes get cached in one way or another if its being dynamically requested
As of now, based on the docs, next.js is not yet able to mix static server components with dynamic server components.
But I haven't fully test if those 10000000000 lines of html codes get cached in one way or another if its being dynamically requested
i mean it's a genuine thought, i'm getting fed up trying to seperate static/server and client components
especially since it is file based
idk how next does it internally and whether it has performance gains or anything, but whenever i see a component with only a small interactive part, even though the component itself might not be that large, I'm getting that urge to always seperate it out
the 10000 lines static html was an extreme example of that

Japanese anchovy
I know for me, I've been utilizing basic html/css to include those interactions when appropriate. I know you cant do that for all cases but for things like a collapsible panel and such you can definately utilize html/css to make use of that where as before we would handle it with state
@Spectacled bear idk how next does it internally and whether it has performance gains or anything, but whenever i see a component with only a small interactive part, even though the component itself might not be that large, I'm getting that urge to always seperate it out
why would that be a problem? i feel like thats the way to to do it