completefrontend

Predict the outputHard

You type a note on a tea page, open another tea, then come back with Back and with a <Link>. What's kept, and what renders again?

Each tea's page has a note box, a Client Component that keeps what you type in useState, and a stock line that waits for connection() inside <Suspense>, so it renders for each request and logs when it does. The teas layout links to Green tea and Mint tea. Cache Components and Partial Prefetching are on, as create-next-app sets them up. What does the page show after each step, and what does the server log?

app/layout.tsx
export const metadata = { title: "Leaf and Kettle" };
 
export default function RootLayout({ children }: LayoutProps<"/">) {
  return (
    <html lang="en">
      <body>{children}</body>
    </html>
  );
}
lib/teas.ts
export type Tea = { slug: string; name: string; about: string };
 
export const teas: Tea[] = [
  { slug: "green", name: "Green tea", about: "Light and fresh." },
  { slug: "mint", name: "Mint tea", about: "Cool and sweet." },
  { slug: "oolong", name: "Oolong tea", about: "Rich and smooth." },
];
 
export function getTea(slug: string) {
  return teas.find((tea) => tea.slug === slug);
}
app/teas/layout.tsx
import Link from "next/link";
 
export default function TeasLayout({ children }: LayoutProps<"/teas">) {
  return (
    <>
      <nav>
        <Link href="/teas/green">Green tea</Link> <Link href="/teas/mint">Mint tea</Link>
      </nav>
      {children}
    </>
  );
}
app/teas/[slug]/page.tsx
import { Suspense } from "react";
import { notFound } from "next/navigation";
import { getTea, teas } from "@/lib/teas";
import Stock from "./stock";
import TastingNote from "./tasting-note";
 
export function generateStaticParams() {
  return teas.map((tea) => ({ slug: tea.slug }));
}
 
export default async function TeaPage({ params }: PageProps<"/teas/[slug]">) {
  const { slug } = await params;
  const tea = getTea(slug);
  if (!tea) notFound();
 
  return (
    <main>
      <h1>{tea.name}</h1>
      <Suspense fallback={<p>Checking stock…</p>}>
        <Stock slug={tea.slug} />
      </Suspense>
      <TastingNote />
    </main>
  );
}
app/teas/[slug]/stock.tsx
import { connection } from "next/server";
 
const stock: Record<string, number> = { green: 12, mint: 4, oolong: 7 };
 
export default async function Stock({ slug }: { slug: string }) {
  await connection();
  console.log(`Checking stock for ${slug}`);
  return <p>In stock: {stock[slug]}</p>;
}
app/teas/[slug]/tasting-note.tsx
"use client";
 
import { useState } from "react";
 
export default function TastingNote() {
  const [note, setNote] = useState("");
  return (
    <label>
      Your note <input value={note} onChange={(event) => setNote(event.target.value)} />
    </label>
  );
}

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 and next start, and open /teas/green in a browser.
  2. You type Two minutes, no more into Your note.
  3. You click the Mint tea link.
  4. You press the browser's Back button.
  5. You click the Mint tea link again.
  6. You click the Green tea link.

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…