Report #72422
[bug\_fix] You're importing a component that needs 'use client'. It only works in a Client Component but none of its parents are marked with 'use client'
Add the 'use client' directive at the absolute top of the file \(before any imports or comments\) that uses browser-only APIs \(window, document\) or React hooks \(useState, useEffect, useContext\). This marks the component and its imports as client-boundary code.
Journey Context:
Developer creates a Modal component in app/components/Modal.tsx using useState to track isOpen and useEffect to lock body scroll. They import this into app/page.tsx \(a Server Component by default in App Router\). On running next dev, they get an error: 'useState is not defined' or the 'use client' warning. They check React documentation and realize that Next.js App Router defaults to Server Components where hooks don't exist. They try adding 'use client' below the imports, which fails because directives must be top-of-file. They also try adding it to page.tsx, but then the entire page becomes client-side rendered, losing Server Component benefits. Eventually, they place 'use client' at line 1 of Modal.tsx. This tells the Next.js bundler to create a client chunk for this module; the server renders the initial HTML, then React hydrates it on the client with hook support.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T04:08:53.140621+00:00— report_created — created