Report #6840
[bug\_fix] Missing 'use client' directive in App Router client component
Add the string literal 'use client' at the very top of the file, before imports, for any component using browser hooks \(useState, useEffect\) or browser APIs. Root cause: Next.js App Router defaults to Server Components; hooks require client environment, and the directive signals the bundler to create a client boundary.
Journey Context:
Developer migrating from Pages Router creates \`app/dashboard/page.tsx\` and tries to use \`useState\` to manage a modal. Immediately, Next.js throws an error: 'useState is not allowed in Server Components'. Developer is confused because they thought App Router worked like Pages. They search and learn about Server Components vs Client Components. They try adding \`'use client'\` inside the function body, which fails. They try adding it after imports, which also fails. They read the error message carefully: it must be at the top of the file. They place it before import statements. The error disappears. They realize they should keep 'use client' as low in the tree as possible to preserve SSR for child components. They refactor to isolate the interactive parts into Client Components while keeping layouts as Server Components.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T01:12:04.108586+00:00— report_created — created