Skip to content

Commit 879aaad

Browse files
author
Jacek
committed
fix(nextjs): skip invalidateCacheAction on Next.js 16 to unblock setActive
On Next.js 16.2.0 with cacheComponents, the invalidateCacheAction server action (which calls cookies() from next/headers) hangs indefinitely, blocking setActive() from completing after sign-in. The sign-in API returns complete but the session is never set because setActive is stuck awaiting the server action. Skip the server action on Next.js 16 and rely on router.refresh() in onAfterSetActive for cache invalidation instead.
1 parent e9dfc01 commit 879aaad

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

‎packages/nextjs/src/app-router/client/ClerkProvider.tsx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ const NextClientClerkProvider = <TUi extends Ui = Ui>(props: NextClerkProviderPr
6363
// Once `setActive` performs the navigation, `__internal_onAfterSetActive` will kick in and perform a router.refresh ensuring shared layouts will also update with the correct authentication context.
6464
if ((nextVersion.startsWith('15') || nextVersion.startsWith('16')) && intent === 'sign-out') {
6565
resolve(); // noop
66+
} else if (nextVersion.startsWith('16')) {
67+
// On Next.js 16 with cacheComponents, calling invalidateCacheAction (a server action that
68+
// calls cookies()) hangs indefinitely, blocking setActive from completing. The router.refresh()
69+
// in onAfterSetActive is sufficient to invalidate the cache on Next.js 16+.
70+
resolve();
6671
} else {
6772
void invalidateCacheAction().then(() => resolve());
6873
}

0 commit comments

Comments
 (0)