A Client Component hides its server-rendered children until a click. What runs during next build, and what does the click change?
The Oolong tea page is a Server Component. It renders Reveal, a Client Component with a Show brewing notes button, and passes it BrewingNotes, a Server Component, as children. Reveal renders its children only once it's open. All three components log when they render. What does the terminal show during next build and next start, what's in the HTML the server sends, and what does the page show after the click?
app/layout.tsxexport const metadata = { title: "Leaf and Kettle" };
export default function RootLayout({ children }: LayoutProps<"/">) {
return (
<html lang="en">
<body>{children}</body>
</html>
);
}
app/page.tsximport BrewingNotes from "./brewing-notes";
import Reveal from "./reveal";
export default function TeaPage() {
console.log("TeaPage rendered");
return (
<main>
<h1>Oolong tea</h1>
<Reveal>
<BrewingNotes />
</Reveal>
</main>
);
}
app/brewing-notes.tsxexport default function BrewingNotes() {
console.log("BrewingNotes rendered");
return <p>Steep at 90°C for three minutes.</p>;
}
app/reveal.tsx"use client";
import { useState, type ReactNode } from "react";
export default function Reveal({ children }: { children: ReactNode }) {
const [open, setOpen] = useState(false);
console.log(`Reveal rendered, open: ${open}`);
return (
<section>
<button onClick={() => setOpen(!open)}>{open ? "Hide brewing notes" : "Show brewing notes"}</button>
{open && children}
</section>
);
}
It's a project create-next-app made (Next.js 16.4.3, TypeScript, the App Router, and Cache Components on) with these files, built with next build and run with next start. What happens:
- You run
next build, thennext start. - You ask the server for
/. - You open
/in a browser. - You click Show brewing notes.
The answer
Work out what Next.js does at each step: what the build prints, what each request answers, and what the page shows. Then check.
Checking your sign-in…