completefrontend

Predict the outputHard

Two pages call console.log while they render. What prints during next build, and what for each request?

The home page logs when it renders. The order page shows a heading, and its OrderStatus component waits for connection(), then logs. Both are Server Components, and Cache Components is on, as create-next-app sets it up. You build the app, start it, and ask for each page twice. What does the terminal show, and when?

app/layout.tsx
export const metadata = { title: "Leaf and Kettle" };
 
export default function RootLayout({ children }: LayoutProps<"/">) {
  return (
    <html lang="en">
      <body>{children}</body>
    </html>
  );
}
app/page.tsx
export default function Home() {
  console.log("Rendering the home page");
  return (
    <main>
      <h1>Leaf and Kettle</h1>
      <p>Fresh tea, packed by hand.</p>
    </main>
  );
}
app/order/page.tsx
import { Suspense } from "react";
import { connection } from "next/server";
 
async function OrderStatus() {
  await connection();
  console.log("Checking the order status");
  return <p>Your tea is on its way.</p>;
}
 
export default function OrderPage() {
  return (
    <main>
      <h1>Your order</h1>
      <Suspense fallback={<p>Checking your order…</p>}>
        <OrderStatus />
      </Suspense>
    </main>
  );
}

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:

  1. You run next build.
  2. You run next start.
  3. You ask the server for / twice.
  4. Then you ask it for /order twice.

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…