completefrontend

Predict the outputMedium

An async component is imported into a Client Component instead of being passed in. Does the build pass, and what happens in the browser?

TeaPrice is an async component that awaits the tea's price, and its file has no directive. TeaCard, a Client Component with an Add a cup button, imports it and renders it with the number of cups. The page, a Server Component, renders TeaCard. What does the server send for /, and what does the page show when you open it and when you click Add a cup?

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/prices.ts
const prices: Record<string, number> = { green: 4, mint: 3, oolong: 5.5 };
 
export async function getPrice(slug: string) {
  return prices[slug];
}
app/tea-price.tsx
import { getPrice } from "./prices";
 
export default async function TeaPrice({ slug, cups }: { slug: string; cups: number }) {
  const price = await getPrice(slug);
  return (
    <p>
      {cups} × ${price.toFixed(2)} = ${(cups * price).toFixed(2)}
    </p>
  );
}
app/tea-card.tsx
"use client";
 
import { useState } from "react";
import TeaPrice from "./tea-price";
 
export default function TeaCard() {
  const [cups, setCups] = useState(1);
  return (
    <section>
      <h1>Oolong tea</h1>
      <TeaPrice slug="oolong" cups={cups} />
      <button onClick={() => setCups(cups + 1)}>Add a cup</button>
    </section>
  );
}
app/page.tsx
import TeaCard from "./tea-card";
 
export default function Home() {
  return (
    <main>
      <TeaCard />
    </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 and next start.
  2. You ask the server for /.
  3. You open / in a browser.
  4. You click Add a cup.

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…