Report #75567
[bug\_fix] React Context is unavailable in Server Components. Attempting to use createContext/useContext in a Server Component errors or returns undefined
Context is a client-side feature because it relies on the React tree being rendered in the browser where a single instance of the context can be provided and consumed. In the App Router, create your Context and Provider in a file marked with "use client", then import the Provider into your layout or page \(which can be Server Components\). The children passed to the Provider can be Server Components because they are passed as props \(children prop\), which React handles specially without making them client components.
Journey Context:
Developer is migrating a Next.js site to App Router. They have a \`ThemeProvider\` using React Context that wraps the app. They put the provider in \`app/layout.tsx\` which is a Server Component by default. They import \`ThemeContext\` from a file that uses createContext. The app crashes with an error saying Context is not supported in Server Components, or the context value is undefined despite a Provider being present. The developer searches and finds that Context is client-only. They move the Provider component to a new file with "use client", then import that Provider into layout.tsx. It works. They learn that Server Components can render Client Components, and when they pass Server Components as children to a Client Component \(the Provider\), those children don't need "use client" because they are passed as props, not rendered by the client component's own JSX logic. This is the 'composition pattern' for interleaving server and client components.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T09:26:31.869431+00:00— report_created — created