Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
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