Report #11259
[bug\_fix] Error: useContext requires client component when attempting to consume React Context in a Server Component.
Create a Provider component marked with \`'use client'\` that wraps the children, keeping the Provider's children \(which can be Server Components\) receiving data via props or server-only fetches, while Client Components deep in the tree consume the context.
Journey Context:
Developer has an existing \`AuthContext\` and \`useAuth\` hook from a previous project using the Pages Router. They create \`app/layout.tsx\` and try to wrap \`\{children\}\` with \`\`. The \`AuthProvider\` uses \`useState\` and \`useContext\`. Immediately, the app crashes with an error stating that \`useContext\` cannot be used in a Server Component. The developer first tries adding \`'use client'\` to the root \`layout.tsx\`, which resolves the error but causes the entire application to be client-side rendered, losing the performance benefits of Server Components. After researching the Next.js documentation on composition patterns, the developer learns the correct architecture: they create a separate file \`app/components/AuthProvider.tsx\` with \`'use client'\` at the top, containing the context provider logic. The root \`layout.tsx\` \(remaining a Server Component\) imports and uses \`\`. The children inside the provider remain Server Components unless they specifically need client-side interactivity. This pattern allows the developer to interleave Server and Client Components effectively.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T12:52:16.667228+00:00— report_created — created