Skip to content

Commit

Permalink
fix(nextjs): Replace router.refresh() with cookies().delete() (#3518)
Browse files Browse the repository at this point in the history
Co-authored-by: George Desipris <[email protected]>
  • Loading branch information
nikosdouvlis and desiprisg authored Jun 11, 2024
1 parent 4a458fe commit 8741003
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/smooth-carrots-hear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/nextjs': patch
---

Replace router.refresh() with cookies().delete()
8 changes: 7 additions & 1 deletion packages/nextjs/src/app-router/client/ClerkProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ClerkNextOptionsProvider } from '../../client-boundary/NextOptionsConte
import type { NextClerkProviderProps } from '../../types';
import { ClerkJSScript } from '../../utils/clerk-js-script';
import { mergeNextClerkPropsWithEnv } from '../../utils/mergeNextClerkPropsWithEnv';
import { invalidateCacheAction } from '../server-actions/invalidateCache';
import { useAwaitablePush } from './useAwaitablePush';
import { useAwaitableReplace } from './useAwaitableReplace';

Expand Down Expand Up @@ -56,7 +57,12 @@ export const ClientClerkProvider = (props: NextClerkProviderProps) => {
return new Promise(res => {
window.__clerk_internal_invalidateCachePromise = res;
startTransition(() => {
router.refresh();
//@ts-expect-error next exitsts on window
if (window.next?.version && typeof window.next.version === 'string' && window.next.version.startsWith('13')) {
router.refresh();
} else {
invalidateCacheAction();
}
});
});
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use server';

import { cookies } from 'next/headers';

export function invalidateCacheAction() {
return cookies().delete(`__clerk_invalidate_cache_cookie_${Date.now()}`);
}

0 comments on commit 8741003

Please sign in to comment.