-
Notifications
You must be signed in to change notification settings - Fork 424
feat(nextjs): Add support for Next.js 16 cache components #7595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Add `isNextjsUseCacheError()` helper to detect "use cache" context errors - Update `isPrerenderingBailout()` to detect cache component prerendering errors - Update `buildRequestLike()` to provide helpful error message with code example when auth() is called inside a "use cache" function - Update `clerkClient()` to re-throw "use cache" errors - Add unit tests for error detection helpers
🦋 Changeset detectedLatest commit: 376fd84 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
📝 WalkthroughWalkthroughAdds detection and handling for Next.js 16 "use cache" component errors across the Clerk Next.js package. Introduces precompiled regexes, an exported helper 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 📜 Recent review detailsConfiguration used: Repository YAML (base), Organization UI (inherited) Review profile: CHILL Plan: Pro Disabled knowledge base sources:
📒 Files selected for processing (1)
🧰 Additional context used📓 Path-based instructions (10)**/*.{js,jsx,ts,tsx}📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Files:
**/*.{js,jsx,ts,tsx,json,md,yml,yaml}📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Files:
packages/**/src/**/*.{ts,tsx}📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Files:
**/*.{ts,tsx,js,jsx}📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Files:
packages/**/src/**/*.{ts,tsx,js,jsx}📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Files:
**/*.ts?(x)📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Files:
**/*.{ts,tsx}📄 CodeRabbit inference engine (.cursor/rules/typescript.mdc)
Files:
**/*.{js,ts,jsx,tsx}📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Files:
**/*.{js,ts,jsx,tsx,json,md,yml,yaml}📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Files:
**/*⚙️ CodeRabbit configuration file
Files:
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (27)
🔇 Additional comments (4)
✏️ Tip: You can disable this entire section by setting Comment |
@clerk/agent-toolkit
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/dev-cli
@clerk/expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/react
@clerk/react-router
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/ui
@clerk/upgrade
@clerk/vue
commit: |
Wrap auth() and currentUser() in try-catch to catch "use cache" errors that bubble up from the Next.js cache boundary. The original implementation only caught errors inside buildRequestLike(), but Next.js throws these errors at a higher level.
| // note: new error message syntax introduced in [email protected] | ||
| // but we still want to support older versions. | ||
| // https://github.com/vercel/next.js/pull/61332 (dynamic-rendering.ts:153) | ||
| const routeRegex = /Route .*? needs to bail out of prerendering at this point because it used .*?./; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: consider hoisting this pattern out of the function like the others in this file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed
Summary
Adds baseline support for Next.js 16 cache components (
cacheComponents) by improving error detection and providing helpful error messages.isNextjsUseCacheError()helper to detect "use cache" context errorsisPrerenderingBailout()to detect cache component prerendering errorsbuildRequestLike()to provide helpful error message whenauth()is called inside a"use cache"functionclerkClient()to re-throw "use cache" errorsProblem
When Next.js 16 cache components are enabled and a developer calls
auth()orcurrentUser()inside a"use cache"function, they receive a cryptic error aboutheaders()rejecting during prerendering.Solution
Detect these errors and provide a helpful message with a code example showing the correct pattern:
Test plan
isPrerenderingBailout()andisNextjsUseCacheError()How to verify
Setup
Create or use a Next.js 16 app with
cacheComponentsenabled innext.config.ts:Install the PR preview package:
Test the error detection
Create a page that calls
auth()inside a"use cache"function:Expected behavior
Before this PR: Cryptic error about
headers()rejecting during prerenderingAfter this PR: Clear error message explaining the issue and showing the correct pattern:
Related
Summary by CodeRabbit
New Features
Improvements
✏️ Tip: You can customize this high-level summary in your review settings.