|
| 1 | +# Next.js Cache Components Integration Test App |
| 2 | + |
| 3 | +This app tests Clerk's integration with Next.js 16's experimental cache components feature. |
| 4 | + |
| 5 | +## Setup |
| 6 | + |
| 7 | +```bash |
| 8 | +pnpm install |
| 9 | +pnpm dev |
| 10 | +``` |
| 11 | + |
| 12 | +## Configuration |
| 13 | + |
| 14 | +The app enables cache components in `next.config.js`: |
| 15 | + |
| 16 | +```js |
| 17 | +cacheComponents: true, // Enables PPR and cache components |
| 18 | +``` |
| 19 | + |
| 20 | +**Important**: ClerkProvider must be wrapped in `<Suspense>` for cache components to work correctly. |
| 21 | + |
| 22 | +## Test Scenarios |
| 23 | + |
| 24 | +### 1. auth() in Server Component (`/auth-server-component`) |
| 25 | + |
| 26 | +Tests basic usage of `auth()` in a React Server Component. |
| 27 | + |
| 28 | +### 2. auth() in Server Action (`/auth-server-action`) |
| 29 | + |
| 30 | +Tests using `auth()` inside a server action triggered by a client component. |
| 31 | + |
| 32 | +### 3. auth() in API Route (`/api/auth-check`) |
| 33 | + |
| 34 | +Tests using `auth()` in a Next.js API route handler. |
| 35 | + |
| 36 | +### 4. "use cache" with auth() - Error Case (`/use-cache-error`) |
| 37 | + |
| 38 | +Tests that calling `auth()` inside a `"use cache"` function produces the expected error. |
| 39 | +This is an **invalid pattern** because `auth()` uses dynamic APIs (cookies, headers). |
| 40 | + |
| 41 | +### 5. "use cache" Correct Pattern (`/use-cache-correct`) |
| 42 | + |
| 43 | +Demonstrates the correct way to use `"use cache"` with Clerk: |
| 44 | + |
| 45 | +1. Call `auth()` **outside** the cache function |
| 46 | +2. Pass the `userId` **into** the cache function |
| 47 | +3. The cache function only contains cacheable operations |
| 48 | + |
| 49 | +### 6. PPR with auth() (`/ppr-auth`) |
| 50 | + |
| 51 | +Tests Partial Pre-Rendering with authenticated content. |
| 52 | +Static content is pre-rendered while authenticated content streams in dynamically. |
| 53 | + |
| 54 | +### 7. Protected Route (`/protected`) |
| 55 | + |
| 56 | +Tests middleware-based route protection using `auth.protect()`. |
| 57 | + |
| 58 | +## Expected Behaviors |
| 59 | + |
| 60 | +| Scenario | Expected Result | |
| 61 | +| --------------------------------- | ------------------------------------------ | |
| 62 | +| auth() in RSC | Works normally | |
| 63 | +| auth() in Server Action | Works normally | |
| 64 | +| auth() in API Route | Works normally | |
| 65 | +| auth() inside "use cache" | Should throw error | |
| 66 | +| userId passed to "use cache" | Works correctly | |
| 67 | +| PPR + auth() | Dynamic portion streams after static shell | |
| 68 | +| Protected route (unauthenticated) | Redirects to sign-in | |
| 69 | + |
| 70 | +## Related PRs |
| 71 | + |
| 72 | +- PR #7119: Initial exploration of cacheComponents support |
| 73 | +- PR #7530: Initial exploration of PPR + auth() issues |
0 commit comments