Course map
Stage 1: App Router Foundations
Stage 2: The Rendering Model
Stage 3: Data, Caching and Mutations
Stage 4: Full-Stack Next.js
Stage 5: Production and Specialization

Part 05 / Topic 5 of 6

How to tell where a component actually ran

WholesalePage's own code includes one line that exists purely to answer the question this section is named after:

console.log("WholesalePage rendering on the server, typeof window:", typeof window);

A console.log inside a Server Component never reaches the browser's console — there is no browser involved in running this line at all. It shows up in whichever terminal is running next dev or next build, and nowhere else. Proven for real: curling the page's HTML shows no trace of the log text anywhere in the response body...

$ curl -s http://localhost:PORT/store/wholesale | grep -c "WholesalePage rendering"
0

...while the build's own terminal output — the one actually running next build — shows it printed directly into the build log, during the "Generating static pages" step:

$ npm run build
...
  Generating static pages using 17 workers (13/27) ...
WholesalePage rendering on the server, typeof window: undefined
WholesalePage rendering on the server, typeof window: undefined
  Generating static pages using 17 workers (20/27)
...

Two things are worth noticing in that real output, not just the one this section set out to prove. First, typeof window printed undefined — not "undefined" the string being special-cased, the actual runtime fact that window was never declared in this process at all, because this process is a Node.js build worker, not a browser. That is the single most reliable fact to reach for when debugging "did this code run on the server or the client?" anywhere in a Next.js app — Client Components have a real window (eventually, after hydration); Server Components never do. Second, the line printed twice for one page during one build — Next.js's static generation is free to render a component more than once while producing its output (in this harness, observed consistently as exactly twice across repeated builds), so a console.log used for debugging is fine, but any Server Component code with a real side effect beyond logging (incrementing a counter, sending an email) needs to be written knowing it might run more than once per build.

Full file: examples/02-wholesale-page.tsx.

Done here? The practice set for Part 5 — including the solutions — is on the part page.

Search the guide