completefrontend

Predict the outputMedium

A Server Component and a Client Component both read NEXT_PUBLIC_SHOP_NAME and SUPPLIER_NAME. What does each show?

The tea shop's .env file has two variables, one with the NEXT_PUBLIC_ prefix and one without. The home page, a Server Component, shows both, and so does its footer, a Client Component. What text is in the HTML the server sends, and what does the page show in a browser once its JavaScript has run?

.env
NEXT_PUBLIC_SHOP_NAME=Leaf and Kettle
SUPPLIER_NAME=Green Hills Estate
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
import ShopFooter from "./shop-footer";
 
export default function Home() {
  return (
    <main>
      <h1>{process.env.NEXT_PUBLIC_SHOP_NAME}</h1>
      <p>Our teas come from {process.env.SUPPLIER_NAME}.</p>
      <ShopFooter />
    </main>
  );
}
app/shop-footer.tsx
"use client";
 
export default function ShopFooter() {
  return (
    <footer>
      <p>Thanks for visiting {process.env.NEXT_PUBLIC_SHOP_NAME}.</p>
      <p>Supplied by {process.env.SUPPLIER_NAME}.</p>
    </footer>
  );
}

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.

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…