feat(nextjs): Isolate nonce fetch in Suspense boundary for PPR support#7773
feat(nextjs): Isolate nonce fetch in Suspense boundary for PPR support#7773jacekradko wants to merge 7 commits intomainfrom
Conversation
Move nonce fetching from the server ClerkProvider's main body into a separate DynamicClerkScripts server component wrapped in Suspense. This allows pages using dynamic=true to remain statically renderable and compatible with PPR/cacheComponents. - Create DynamicClerkScripts async server component - Add getNonce cached function to utils - Skip client ClerkScripts when server scripts are used - Pass __internal_skipScripts through KeylessProvider
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
|
📝 WalkthroughWalkthroughAdds an internal boolean prop 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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: |
…ndling Extract duplicated script rendering into a shared ClerkScriptTags component used by both ClerkScripts (client) and DynamicClerkScripts (server). Add try/catch to getNonce() so errors in prerendering or "use cache" contexts degrade gracefully instead of propagating unhandled.
…n RSC Import clerkJSScriptUrl, buildClerkJSScriptAttributes, clerkUIScriptUrl from @clerk/shared/loadClerkJsScript instead of @clerk/react/internal in the shared ClerkScriptTags component. The @clerk/react/internal barrel re-exports modules that use React.createContext, which breaks when the RSC bundler evaluates the barrel in server component context.
Summary
DynamicClerkScriptsserver component wrapped in Suspensedynamic=trueto remain statically renderable and compatible with PPR/cacheComponentsProblem
In the Next.js App Router server
ClerkProvider, we awaitnoncefrom headers viagetNonceHeaders(). This callsheaders()which opts the entire page out of static rendering and breaks PPR/cacheComponents.Solution
Isolate the nonce fetch in a Suspense boundary:
DynamicClerkScriptsasync server component that fetches nonce and renders scriptsgetNoncecached function to utilsdynamic=true, render<Suspense><DynamicClerkScripts/></Suspense>ClerkScriptswhen server scripts are used via__internal_skipScriptspropTest plan
dynamic=true- scripts should render correctlyCloses USER-4607
Summary by CodeRabbit
New Features
Refactor