diff --git a/.changeset/smart-pants-rule.md b/.changeset/smart-pants-rule.md new file mode 100644 index 00000000000..1045687c62d --- /dev/null +++ b/.changeset/smart-pants-rule.md @@ -0,0 +1,5 @@ +--- +"@clerk/nextjs": patch +--- + +Makes the internally used `invalidateCacheAction()` server action an async function to comply with server actions constraints. More information: https://nextjs.org/docs/messages/invalid-use-server-value diff --git a/packages/nextjs/src/app-router/client/ClerkProvider.tsx b/packages/nextjs/src/app-router/client/ClerkProvider.tsx index 599ff02ac51..6a34407853e 100644 --- a/packages/nextjs/src/app-router/client/ClerkProvider.tsx +++ b/packages/nextjs/src/app-router/client/ClerkProvider.tsx @@ -57,7 +57,7 @@ export const ClientClerkProvider = (props: NextClerkProviderProps) => { return new Promise(res => { window.__clerk_internal_invalidateCachePromise = res; startTransition(() => { - //@ts-expect-error next exitsts on window + //@ts-expect-error next exists on window if (window.next?.version && typeof window.next.version === 'string' && window.next.version.startsWith('13')) { router.refresh(); } else { diff --git a/packages/nextjs/src/app-router/server-actions/invalidateCache.ts b/packages/nextjs/src/app-router/server-actions/invalidateCache.ts index 525242763d0..9ed90dfe516 100644 --- a/packages/nextjs/src/app-router/server-actions/invalidateCache.ts +++ b/packages/nextjs/src/app-router/server-actions/invalidateCache.ts @@ -2,6 +2,10 @@ import { cookies } from 'next/headers'; -export function invalidateCacheAction() { +// This function needs to be async as we'd like to support next versions in the range of [14.1.2,14.2.0) +// These versions required 'use server' files to export async methods only. This check was later relaxed +// and the async is no longer required in newer next versions. +// ref: https://github.com/vercel/next.js/pull/62821 +export async function invalidateCacheAction() { return cookies().delete(`__clerk_invalidate_cache_cookie_${Date.now()}`); }