Report #70253
[bug\_fix] React Context is undefined in Server Component \(or 'createContext' is not a function\)
Move the Context Provider into a Client Component file \(marked with 'use client'\) and import that wrapper into the Server Component layout/page. Context itself cannot be created or consumed in Server Components.
Journey Context:
Developer creates \`AuthContext\` using \`React.createContext\` in \`lib/auth.tsx\`. They import \`AuthProvider\` into \`app/layout.tsx\` \(a Server Component\) and wrap children. They then try to consume the context in a child Server Component using \`useContext\(AuthContext\)\`, getting \`undefined\` or an error that the hook is not available. Developer initially thinks the provider isn't wrapping correctly. After debugging, discovers that React Context is explicitly disallowed in React Server Components \(RSC\). The solution is to create a separate \`providers.tsx\` file with 'use client' at the top, move the AuthProvider there, then import Providers into layout.tsx. The Server Component can render the Client Component wrapper, but only Client Components inside that boundary can consume the context.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T00:30:08.764086+00:00— report_created — created