Report #49692
[bug\_fix] Error: You're importing a component that needs useEffect. It only works in a Client Component but none of its parents are marked with "use client"
Add the directive 'use client' at the very top of the file \(above imports\) that contains the hook or browser API usage. If the hook is used in a shared component, mark that specific component file, not the parent Server Component. The root cause is that React Server Components cannot execute effects or hold client-side state; only Client Components \(which are pre-rendered on server but hydrated in browser\) can use useEffect, useState, and context consumers.
Journey Context:
Developer creates a Modal component with useState for isOpen and useEffect to lock body scroll. They place it in components/Modal.tsx and import it into app/page.tsx \(a Server Component\). The dev server immediately crashes with the error mentioning useEffect. Developer is confused because they thought all components were client components by default \(coming from Pages Router\). They try adding 'use client' to page.tsx, which fixes the error but defeats the purpose of Server Components. They eventually realize they should only mark the specific component file \(Modal.tsx\) with 'use client', allowing the page to remain a Server Component that streams the modal's HTML as part of the initial payload, or they can pass Server Components as children to the Client Component Modal.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T13:53:29.441018+00:00— report_created — created