A Client Component logs when it renders. What does next start print for the page's HTML, and for its RSC payload?
Leaf and Kettle's order page reads the order for each request, after connection(), and shows it with CupCounter, a Client Component that logs every time it renders. You build and start the app, ask for /order as a browser does, then ask for it again with the header rsc: 1, which is how Next.js's router asks for a page during a client-side navigation. The router's other headers are left out, so the server answers with the payload of the whole page. What does each response hold, and what does the terminal print?
app/layout.tsxexport const metadata = { title: "Leaf and Kettle" };
export default function RootLayout({ children }: LayoutProps<"/">) {
return (
<html lang="en">
<body>{children}</body>
</html>
);
}
app/order/page.tsximport { Suspense } from "react";
import { connection } from "next/server";
import CupCounter from "./cup-counter";
async function Order() {
await connection();
console.log("Order: read from the database");
return (
<section>
<p>Mint tea, packed this morning.</p>
<CupCounter tea="Mint tea" cups={2} />
</section>
);
}
export default function OrderPage() {
return (
<main>
<h1>Your order</h1>
<Suspense fallback={<p>Finding your order…</p>}>
<Order />
</Suspense>
</main>
);
}
app/order/cup-counter.tsx"use client";
import { useState } from "react";
export default function CupCounter({ tea, cups }: { tea: string; cups: number }) {
const [count, setCount] = useState(cups);
console.log(`CupCounter: rendering ${count} cups of ${tea}`);
return <button onClick={() => setCount(count + 1)}>{`${count} cups of ${tea}`}</button>;
}
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
/order. - You ask for
/order?_rsc=with the headerrsc: 1.
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…