Report #10300
[bug\_fix] window is not defined / useState is not valid in a Server Component
Add the "use client" directive at the very top of the file \(before imports\). Root cause: Next.js App Router defaults to Server Components where browser APIs \(window, document\) and React hooks \(useState, useEffect\) are not available during server-side rendering.
Journey Context:
You're migrating a form component from Pages Router to App Router. You paste it into app/contact/page.tsx and immediately get "ReferenceError: window is not defined" during next build, or "useState is not valid in a Server Component". You check the file—there's no window reference in your code, but useState implies client-side interactivity. You try dynamic import with ssr: false, which works but breaks SEO and causes layout shift. After checking the Next.js docs on Rendering, you realize App Router assumes Server Components by default. The fix is simply adding "use client" at the top of the file to tell Next.js to send this component to the browser for hydration.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T10:17:24.617753+00:00— report_created — created