Skip to content

Commit 8fadb1d

Browse files
authored
fix(clerk-js): Invalidate server cache for after-auth custom flows (#6425)
1 parent f6375f0 commit 8fadb1d

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

.changeset/modern-clocks-sip.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/clerk-js': patch
3+
---
4+
5+
Fix server-side session cache not being invalidated for after-auth custom flows

packages/clerk-js/bundlewatch.config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"files": [
33
{ "path": "./dist/clerk.js", "maxSize": "618KB" },
4-
{ "path": "./dist/clerk.browser.js", "maxSize": "72.2KB" },
4+
{ "path": "./dist/clerk.browser.js", "maxSize": "74KB" },
55
{ "path": "./dist/clerk.legacy.browser.js", "maxSize": "115.08KB" },
66
{ "path": "./dist/clerk.headless*.js", "maxSize": "55KB" },
77
{ "path": "./dist/ui-common*.js", "maxSize": "113KB" },

packages/clerk-js/src/core/clerk.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,6 +1325,29 @@ export class Clerk implements ClerkInterface {
13251325
};
13261326

13271327
#handlePendingSession = async (session: PendingSessionResource) => {
1328+
/**
1329+
* Do not revalidate server cache when `setActive` is called with a pending
1330+
* session within components, to avoid flash of content and unmount during
1331+
* internal navigation
1332+
*/
1333+
const shouldInvalidateCache = !this.#componentNavigationContext;
1334+
1335+
const onBeforeSetActive: SetActiveHook =
1336+
shouldInvalidateCache &&
1337+
typeof window !== 'undefined' &&
1338+
typeof window.__unstable__onBeforeSetActive === 'function'
1339+
? window.__unstable__onBeforeSetActive
1340+
: noop;
1341+
1342+
const onAfterSetActive: SetActiveHook =
1343+
shouldInvalidateCache &&
1344+
typeof window !== 'undefined' &&
1345+
typeof window.__unstable__onAfterSetActive === 'function'
1346+
? window.__unstable__onAfterSetActive
1347+
: noop;
1348+
1349+
await onBeforeSetActive();
1350+
13281351
if (!this.environment) {
13291352
return;
13301353
}
@@ -1358,6 +1381,8 @@ export class Clerk implements ClerkInterface {
13581381

13591382
this.#setAccessors(session);
13601383
this.#emit();
1384+
1385+
await onAfterSetActive();
13611386
};
13621387

13631388
public __internal_navigateToTaskIfAvailable = async ({

0 commit comments

Comments
 (0)