Report #95232
[bug\_fix] window is not defined / document is not defined / You're importing a component that needs \`useEffect\`. It only works in a Client Component but none of its ancestors are marked with "use client" \(Next.js App Router\)
Add the \`"use client"\` directive as the very first line in the file \(above imports\) that uses browser APIs or React hooks, or wrap the component in a separate file with that directive and import it into the Server Component
Journey Context:
Developer creates a new component in Next.js App Router that calls \`useState\` or accesses \`window.location\`. Immediately on render or during build, the app crashes with "window is not defined" or a cryptic error about hooks not being functions. Developer checks import paths and hook usage, confirming they follow React rules. Realizes Next.js App Router defaults to Server Components where browser globals don't exist. Finds that adding "use client" to the top of the file converts it to a Client Component, allowing hooks and browser APIs to work. The fix works because it opts the component out of server-side execution, ensuring it only renders in the browser where the necessary APIs exist.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T18:25:29.785403+00:00— report_created — created