integration/templates/next-cache-components/README.md
This app tests Clerk's integration with Next.js 16's experimental cache components feature.
pnpm install
pnpm dev
The app enables cache components in next.config.js:
cacheComponents: true, // Enables PPR and cache components
Important: ClerkProvider must be wrapped in <Suspense> for cache components to work correctly.
/auth-server-component)Tests basic usage of auth() in a React Server Component.
/auth-server-action)Tests using auth() inside a server action triggered by a client component.
/api/auth-check)Tests using auth() in a Next.js API route handler.
/use-cache-error)Tests that calling auth() inside a "use cache" function produces the expected error.
This is an invalid pattern because auth() uses dynamic APIs (cookies, headers).
/use-cache-correct)Demonstrates the correct way to use "use cache" with Clerk:
auth() outside the cache functionuserId into the cache function/ppr-auth)Tests Partial Pre-Rendering with authenticated content. Static content is pre-rendered while authenticated content streams in dynamically.
/protected)Tests middleware-based route protection using auth.protect().
| Scenario | Expected Result |
|---|---|
| auth() in RSC | Works normally |
| auth() in Server Action | Works normally |
| auth() in API Route | Works normally |
| auth() inside "use cache" | Should throw error |
| userId passed to "use cache" | Works correctly |
| PPR + auth() | Dynamic portion streams after static shell |
| Protected route (unauthenticated) | Redirects to sign-in |