Report #94009
[bug\_fix] Missing 'use client' directive for browser hooks/APIs
Add the string literal 'use client' at the very top of the file \(before any imports\) that uses browser-only APIs \(window, document\) or React hooks like useState, useEffect, useContext. If only a small part of the component needs client logic, extract that into a separate Client Component file and import it.
Journey Context:
Developer is migrating from Next.js Pages Router to App Router. They move a component file from pages/ to app/. The component uses useState and localStorage. Immediately get a hard error: "You're importing a component that needs useState. It only works in a Client Component but none of its parents are marked with 'use client'." Developer is confused because it worked in Pages Router \(which is client-side rendered by default\). Tries adding 'use client' inside the function body—doesn't work. Tries adding it after imports—doesn't work \(parser error\). Learns it must be at the very top before imports. Also realizes that once they mark it 'use client', any server-only data fetching must happen in a parent Server Component and be passed as props, leading to refactoring.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T16:22:49.144525+00:00— report_created — created