Report #64372
[bug\_fix] React Context Provider used in App Router without 'use client' boundary
Create a separate file \(e.g., \`app/providers.tsx\`\) with \`"use client"\` at the top that exports the Provider wrapper component. Import and use that wrapper in your Server Component layout or page.
Journey Context:
Developer tries to use a React Context Provider in the App Router by defining it directly in \`app/layout.tsx\` or importing it from a library like NextAuth or React Query. They get an error: "useContext must be used inside a Client Component because createContext is not supported in Server Components." They try adding \`"use client"\` to the \`layout.tsx\`, but then realize that marks the entire application tree as a Client Component, losing the benefits of Server Components \(zero client JS for static parts\). They try to split the provider into a separate file but still define the provider logic in the same file as the server layout. Eventually, they understand the composition pattern: create a \`providers.tsx\` file that has \`"use client"\` at the very top and exports a component that renders all the context providers. Then, in the root \`layout.tsx\` \(which remains a Server Component\), they import the Providers component and wrap \`\{children\}\` with it. This keeps the layout server-side while the provider boundary is client-side.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T14:32:01.871215+00:00— report_created — created