Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/modern-clocks-sip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/clerk-js': patch
---

Fix server-side session cache not being invalidated for after-auth custom flows
2 changes: 1 addition & 1 deletion packages/clerk-js/bundlewatch.config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"files": [
{ "path": "./dist/clerk.js", "maxSize": "618KB" },
{ "path": "./dist/clerk.browser.js", "maxSize": "72.2KB" },
{ "path": "./dist/clerk.browser.js", "maxSize": "74KB" },
{ "path": "./dist/clerk.legacy.browser.js", "maxSize": "115.08KB" },
{ "path": "./dist/clerk.headless*.js", "maxSize": "55KB" },
{ "path": "./dist/ui-common*.js", "maxSize": "113KB" },
Expand Down
25 changes: 25 additions & 0 deletions packages/clerk-js/src/core/clerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1325,6 +1325,29 @@ export class Clerk implements ClerkInterface {
};

#handlePendingSession = async (session: PendingSessionResource) => {
/**
* Do not revalidate server cache when `setActive` is called with a pending
* session within components, to avoid flash of content and unmount during
* internal navigation
*/
const shouldInvalidateCache = !this.#componentNavigationContext;

const onBeforeSetActive: SetActiveHook =
shouldInvalidateCache &&
typeof window !== 'undefined' &&
typeof window.__unstable__onBeforeSetActive === 'function'
? window.__unstable__onBeforeSetActive
: noop;

const onAfterSetActive: SetActiveHook =
shouldInvalidateCache &&
typeof window !== 'undefined' &&
typeof window.__unstable__onAfterSetActive === 'function'
? window.__unstable__onAfterSetActive
: noop;

await onBeforeSetActive();

if (!this.environment) {
return;
}
Expand Down Expand Up @@ -1358,6 +1381,8 @@ export class Clerk implements ClerkInterface {

this.#setAccessors(session);
this.#emit();

await onAfterSetActive();
};

public __internal_navigateToTaskIfAvailable = async ({
Expand Down
Loading