completefrontend

Predict the outputHard

A tea page has a cached description, then a slow and a fast <Suspense>. What's in the first HTML, and what appears in what order?

Oolong tea's page shows its description, which is cached, then its reviews, which take 1500 ms to read, then its stock, which takes 300 ms. Each <Suspense> boundary has its own fallback, and the two slow reads log when they finish. You ask the server for the page, then open the home page in a browser and click the Oolong tea link. What does each show, and what does the terminal print?

app/layout.tsx
import Link from "next/link";
 
export const metadata = { title: "Leaf and Kettle" };
 
export default function RootLayout({ children }: LayoutProps<"/">) {
  return (
    <html lang="en">
      <body>
        <nav>
          <Link href="/">Home</Link> <Link href="/teas/oolong">Oolong tea</Link>
        </nav>
        {children}
      </body>
    </html>
  );
}
app/page.tsx
export default function Home() {
  return <h1>Leaf and Kettle</h1>;
}
lib/shop.ts
import { connection } from "next/server";
import { cacheLife } from "next/cache";
 
const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
 
// From the shop's CMS: the same for everyone, so it's cached.
export async function getDescription() {
  "use cache";
  cacheLife("days");
  await wait(100);
  return "Rolled by hand and roasted twice.";
}
 
// From the reviews service, for each request: 1500 ms.
export async function getReviews() {
  await connection();
  await wait(1500);
  console.log("reviews: ready");
  return ["Kenji: Rich and smooth.", "Ana: My Sunday pot."];
}
 
// From the warehouse, for each request: 300 ms.
export async function getStock() {
  await connection();
  await wait(300);
  console.log("stock: ready");
  return 12;
}
app/teas/oolong/page.tsx
import { Suspense } from "react";
import { getDescription, getReviews, getStock } from "@/lib/shop";
 
async function Reviews() {
  const reviews = await getReviews();
  return (
    <ul>
      {reviews.map((review) => (
        <li key={review}>{review}</li>
      ))}
    </ul>
  );
}
 
async function Stock() {
  const stock = await getStock();
  return <p>In stock: {stock}</p>;
}
 
export default async function OolongPage() {
  const description = await getDescription();
 
  return (
    <main>
      <h1>Oolong tea</h1>
      <p>{description}</p>
      <h2>Reviews</h2>
      <Suspense fallback={<p>Loading reviews…</p>}>
        <Reviews />
      </Suspense>
      <h2>Buy</h2>
      <Suspense fallback={<p>Checking the stock…</p>}>
        <Stock />
      </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, then next start.
  2. You ask the server for /teas/oolong.
  3. You open / in a browser.
  4. You click the Oolong tea link and wait until the stock shows.
  5. You wait until the reviews show.

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…