DEV Community

Cover image for Server Components aren't SSR!
Bishoy Bishai
Bishoy Bishai

Posted on • Originally published at bishoy-bishai.github.io

Server Components aren't SSR!

Look my friend, sit down, have a coffee ☕. We need to talk.

In the dev world, people are shouting about React Server Components (RSC) like it’s just SSR with a fancy new haircut. But trust me, as someone who survived the "dark ages" of IE6 and spaghetti JQuery, this is a totally different dance.

If SSR is a recorded video of a football match, RSC is the actual tactical board moving in real-time. Let's break it down before we get a Red Card 🟥 for bad architecture.


Imagine you go to a restaurant:

  • Traditional SSR: The kitchen cooks the whole meal, puts it on a plate, and brings it to your table. You see the food immediately (Fast First Paint), but if you want to change the salt, you have to send the whole plate back.
  • React Server Components: The chef sends you the heavy stuff (the steak, the slow-cooked sauce) directly from the heat, but leaves the "seasoning" (the interactivity) for you to do at the table. You don't get a huge box of ingredients you won't use; you only get the finished parts that stay on the plate.

🏃‍♂️ SSR

Actually, SSR is like watching a recorded match. The server does all the work to generate the HTML.

  1. The Whistle Blows: You ask for a page.
  2. The Server Sprints: It renders everything into a big string of HTML.
  3. The Delivery: The browser shows the HTML instantly.
  4. The "Cramp" (Hydration): The page looks ready, but you can't click anything yet. The browser is busy downloading a massive JavaScript file to "hydrate" the page. It's like a player standing on the pitch but waiting for his soul to enter his body before he can run.

The Problem: Even if your footer is just static text, you still send the JavaScript code for it to the client. That's a waste of energy, like running a 10km marathon just to buy a loaf of bread.


💃 RSC

Now, Server Components? This is a smooth 1, 2, 3, Tap! 💃

RSCs don't send HTML. They send a special description of the UI. It’s like a music sheet instead of the whole MP3 file.

  • Zero Bundle Size: If a component stays on the server, its code never leaves the server. Your JavaScript bundle stays slim, like a striker in top form.
  • Direct Access: You can talk to your Database directly inside the component. No more fetching data through 500 layers of APIs. It's like the manager talking directly to the captain without needing three assistants in the middle.
// 🥩 The Server Component (The Steak)
// No 'use client' here. We are in the kitchen!
import { db } from './vibe-database';

export default async function MusicPlaylist() {
  const songs = await db.query('SELECT * FROM bachata_hits'); // Direct DB access!

  return (
    <div>
      <h1>Party Mix 🎶</h1>
      {songs.map(song => (
        <div key={song.id}>
          <p>{song.title} - {song.artist}</p>
          {/* We "import" interactivity only where needed */}
          <PlayButton songId={song.id} /> 
        </div>
      ))}
    </div>
  );
}

Enter fullscreen mode Exit fullscreen mode

⚠️ Avoiding the "Red Card" (Common Mistakes)

Look my friend, don't trip over the ball:

  1. The 'use client' Boundary: You only use this at the "leaves" of your tree. Don't put it at the top level or you just turned your whole app back into a heavy JS bundle. It’s like trying to lead a Bachata dance by only moving your pinky finger—it doesn't work!
  2. The Secret Sauce: You cannot use useState or useEffect in a Server Component. If you try, the compiler will give you a Yellow Card 🟨 immediately.
  3. Streaming: Use <Suspense>. It’s like VAR—it takes a second to check the data, but the rest of the game keeps moving.

🏟️ Summary Table: SSR vs. RSC

Feature SSR (The Old Pro) RSC (The New Star)
Output Pure HTML String Serialized UI Tree (JSON-like)
JS Bundle Includes everything Zero JS for server-only parts
Interactivity After Hydration Only in Client Components
Data Fetching Happens at Page Level Happens at Component Level

💡 Dance Floor Secret

Don't over-engineer. Start everything as a Server Component by default. It’s the "Home Base." Only when you need a "click," a "hover," or a "state" do you move that specific part to a Client Component.

It’s like cooking: keep the heat in the kitchen (Server), and only bring the salt and pepper to the table (Client). Your users' phones will thank you because they aren't melting while trying to parse 2MB of JavaScript!


✨ Let's keep the conversation going!

If you found this interesting, I'd love for you to check out more of my work or just drop in to say hello.

✍️ Read more on my blog: bishoy-bishai.github.io

Let's chat on LinkedIn: linkedin.com/in/bishoybishai

📘 Curious about AI?: You can also check out my book: Surrounded by AI


WebDev #ReactJS #NextJS #ProgrammingMetaphors #FullStack

Top comments (0)