Skip to content

Conversation

@jacekradko
Copy link
Member

@jacekradko jacekradko commented Nov 26, 2025

Description

This PR implements a stale-while-revalidate (SWR) pattern for session tokens in getToken(). Instead of blocking on token refresh when a token is close to expiration, we return the cached token immediately and trigger a background refresh.

Fixes: USER-4087

Dashboard testing PR: https://github.com/clerk/dashboard/pull/7990

How It Works

Token TTL Timeline (token expires at T=0)
─────────────────────────────────────────────────────────────────────►
                                                                    T=0
                                                                 (expires)

│←─────── Fresh zone ───────→│←── SWR zone ──→│←─ Danger ─→│
         needsRefresh=false      needsRefresh=true    force sync fetch
         (return cached)         (return cached +     (delete from cache)
                                  background refresh)

         > threshold             5s - threshold        < 5s

Key Behaviors

  1. Fresh zone (TTL > threshold): Return cached token, no refresh needed
  2. SWR zone (5s < TTL < threshold): Return cached token immediately, trigger background refresh
  3. Danger zone (TTL < 5s): Force synchronous fetch (poller may not get to it in time)

Configuration

The backgroundRefreshThreshold option (formerly leewayInSeconds) controls when background refresh is triggered:

// Default: refresh starts 15s before expiration
const token = await session.getToken();

// Custom: refresh starts 30s before expiration
const token = await session.getToken({ backgroundRefreshThreshold: 30 });

// Minimum is 5s (the poller interval)
const token = await session.getToken({ backgroundRefreshThreshold: 10 });

Additional Options

  • refreshIfStale (internal): When true, forces a blocking fetch instead of SWR behavior. Useful as an escape hatch when you absolutely need a fresh token and can wait for it.

Implementation Details

Token Cache (tokenCache.ts)

  • get() returns { entry, needsRefresh } instead of just the entry
  • needsRefresh signals when background refresh should occur
  • Tokens < 5s from expiration are deleted from cache (forces sync fetch)
  • Supports cross-tab synchronization via BroadcastChannel

Session (Session.ts)

  • #refreshTokenInBackground(): Triggers refresh without blocking, doesn't cache the pending promise so concurrent calls still get the stale token
  • resolvedToken on cache entries enables synchronous reads (avoids microtask overhead)
  • Background refresh deduplication via #backgroundRefreshInProgress Set

AuthCookieService

  • Uses default SWR behavior (no refreshIfStale)
  • refreshTokenOnFocus returns cached token immediately to update cookie before SWR/similar libraries refetch

Breaking Changes (Core 3)

  1. Renamed option: leewayInSecondsbackgroundRefreshThreshold
  2. Lower minimum: 5s instead of 15s (aligns with poller interval)
  3. SWR behavior: Tokens in the threshold window are returned immediately instead of blocking

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

@changeset-bot
Copy link

changeset-bot bot commented Nov 26, 2025

🦋 Changeset detected

Latest commit: d2cac65

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 20 packages
Name Type
@clerk/clerk-js Minor
@clerk/shared Minor
@clerk/chrome-extension Patch
@clerk/expo Patch
@clerk/agent-toolkit Patch
@clerk/astro Patch
@clerk/backend Patch
@clerk/expo-passkeys Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/localizations Patch
@clerk/msw Patch
@clerk/nextjs Patch
@clerk/nuxt Patch
@clerk/react-router Patch
@clerk/react Patch
@clerk/tanstack-react-start Patch
@clerk/testing Patch
@clerk/ui Patch
@clerk/vue Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 26, 2025

📝 Walkthrough

Walkthrough

This pull request implements stale-while-revalidate behavior for session token retrieval. The token cache API was refactored to return a structured result object containing the cache entry and a needsRefresh flag instead of returning the entry directly. The Session class now includes background token refresh logic that fetches fresh tokens asynchronously when cached tokens approach expiration, returning the current valid token immediately. The leewayInSeconds option in GetTokenOptions was renamed to backgroundRefreshThreshold with adjusted minimum and default values. A new POLLER_INTERVAL_IN_MS constant was exported, and TokenCacheEntry now includes a resolvedToken field for synchronous token reads. Tests and documentation were updated to reflect these changes, and bundle sizes were increased slightly to accommodate the new functionality.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(clerk-js): Stale-while-revalidate session token' directly and clearly summarizes the main feature being added—implementing stale-while-revalidate behavior for session tokens in clerk-js.
Linked Issues check ✅ Passed The pull request fully addresses USER-4087 objectives: cached tokens are returned even within leeway windows (avoiding deletion), background refresh is triggered asynchronously, and latency for hot-path getToken() calls is eliminated.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing stale-while-revalidate behavior: token cache refactoring, background refresh mechanism, GetTokenOptions updates, documentation, and minor bundle size adjustments for the new functionality.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


📜 Recent review details

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between be63362 and d2cac65.

📒 Files selected for processing (6)
  • packages/clerk-js/src/core/resources/Session.ts
  • packages/clerk-js/src/core/resources/__tests__/Session.test.ts
  • packages/clerk-js/src/core/tokenCache.ts
  • packages/shared/src/types/session.ts
  • packages/upgrade/src/versions/core-3/changes/gettoken-leeway-minimum.md
  • packages/upgrade/src/versions/core-3/changes/gettoken-stale-while-revalidate.md
🧰 Additional context used
📓 Path-based instructions (14)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

All code must pass ESLint checks with the project's configuration

Files:

  • packages/clerk-js/src/core/resources/__tests__/Session.test.ts
  • packages/shared/src/types/session.ts
  • packages/clerk-js/src/core/tokenCache.ts
  • packages/clerk-js/src/core/resources/Session.ts
**/*.{js,jsx,ts,tsx,json,md,yml,yaml}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use Prettier for consistent code formatting

Files:

  • packages/clerk-js/src/core/resources/__tests__/Session.test.ts
  • packages/shared/src/types/session.ts
  • packages/clerk-js/src/core/tokenCache.ts
  • packages/clerk-js/src/core/resources/Session.ts
  • packages/upgrade/src/versions/core-3/changes/gettoken-stale-while-revalidate.md
  • packages/upgrade/src/versions/core-3/changes/gettoken-leeway-minimum.md
packages/**/src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

TypeScript is required for all packages

Files:

  • packages/clerk-js/src/core/resources/__tests__/Session.test.ts
  • packages/shared/src/types/session.ts
  • packages/clerk-js/src/core/tokenCache.ts
  • packages/clerk-js/src/core/resources/Session.ts
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Follow established naming conventions (PascalCase for components, camelCase for variables)

Files:

  • packages/clerk-js/src/core/resources/__tests__/Session.test.ts
  • packages/shared/src/types/session.ts
  • packages/clerk-js/src/core/tokenCache.ts
  • packages/clerk-js/src/core/resources/Session.ts
packages/**/src/**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

packages/**/src/**/*.{ts,tsx,js,jsx}: Maintain comprehensive JSDoc comments for public APIs
Use tree-shaking friendly exports
Validate all inputs and sanitize outputs
All public APIs must be documented with JSDoc
Use dynamic imports for optional features
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Implement proper logging with different levels

Files:

  • packages/clerk-js/src/core/resources/__tests__/Session.test.ts
  • packages/shared/src/types/session.ts
  • packages/clerk-js/src/core/tokenCache.ts
  • packages/clerk-js/src/core/resources/Session.ts
**/*.{test,spec}.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

**/*.{test,spec}.{ts,tsx,js,jsx}: Unit tests are required for all new functionality
Verify proper error handling and edge cases
Include tests for all new features

Files:

  • packages/clerk-js/src/core/resources/__tests__/Session.test.ts
**/*.ts?(x)

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use proper TypeScript error types

Files:

  • packages/clerk-js/src/core/resources/__tests__/Session.test.ts
  • packages/shared/src/types/session.ts
  • packages/clerk-js/src/core/tokenCache.ts
  • packages/clerk-js/src/core/resources/Session.ts
**/*.{test,spec,e2e}.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use real Clerk instances for integration tests

Files:

  • packages/clerk-js/src/core/resources/__tests__/Session.test.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/typescript.mdc)

**/*.{ts,tsx}: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoid any type - prefer unknown when type is uncertain, then narrow with type guards
Implement type guards for unknown types using the pattern function isType(value: unknown): value is Type
Use interface for object shapes that might be extended
Use type for unions, primitives, and computed types
Prefer readonly properties for immutable data structures
Use private for internal implementation details in classes
Use protected for inheritance hierarchies
Use public explicitly for clarity in public APIs
Use mixins for shared behavior across unrelated classes in TypeScript
Use generic constraints with bounded type parameters like <T extends { id: string }>
Use utility types like Omit, Partial, and Pick for data transformation instead of manual type construction
Use discriminated unions instead of boolean flags for state management and API responses
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation at the type level
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Document functions with JSDoc comments including @param, @returns, @throws, and @example tags
Create custom error classes that extend Error for specific error types
Use the Result pattern for error handling instead of throwing exceptions
Use optional chaining (?.) and nullish coalescing (??) operators for safe property access
Let TypeScript infer obvious types to reduce verbosity
Use const assertions with as const for literal types
Use satisfies operator for type checking without widening types
Declare readonly arrays and objects for immutable data structures
Use spread operator and array spread for immutable updates instead of mutations
Use lazy loading for large types...

Files:

  • packages/clerk-js/src/core/resources/__tests__/Session.test.ts
  • packages/shared/src/types/session.ts
  • packages/clerk-js/src/core/tokenCache.ts
  • packages/clerk-js/src/core/resources/Session.ts
**/*.test.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Use React Testing Library for component testing

Files:

  • packages/clerk-js/src/core/resources/__tests__/Session.test.ts
**/*.{js,ts,jsx,tsx}

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Use ESLint with custom configurations tailored for different package types

Files:

  • packages/clerk-js/src/core/resources/__tests__/Session.test.ts
  • packages/shared/src/types/session.ts
  • packages/clerk-js/src/core/tokenCache.ts
  • packages/clerk-js/src/core/resources/Session.ts
**/*.{js,ts,jsx,tsx,json,md,yml,yaml}

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Use Prettier for code formatting across all packages

Files:

  • packages/clerk-js/src/core/resources/__tests__/Session.test.ts
  • packages/shared/src/types/session.ts
  • packages/clerk-js/src/core/tokenCache.ts
  • packages/clerk-js/src/core/resources/Session.ts
  • packages/upgrade/src/versions/core-3/changes/gettoken-stale-while-revalidate.md
  • packages/upgrade/src/versions/core-3/changes/gettoken-leeway-minimum.md
**/*

⚙️ CodeRabbit configuration file

If there are no tests added or modified as part of the PR, please suggest that tests be added to cover the changes.

**/*: Only comment on issues that would block merging, ignore minor or stylistic concerns.
Restrict feedback to errors, security risks, or functionality-breaking problems.
Do not post comments on code style, formatting, or non-critical improvements.
Keep reviews short: flag only issues that make the PR unsafe to merge.
Group similar issues into a single comment instead of posting multiple notes.
Skip repetition: if a pattern repeats, mention it once at a summary level only.
Do not add general suggestions, focus strictly on merge-blocking concerns.
If there are no critical problems, respond with minimal approval (e.g., 'Looks good'). Do not add additional review.
Avoid line-by-line commentary unless it highlights a critical bug or security hole.
Highlight only issues that could cause runtime errors, data loss, or severe maintainability issues.
Ignore minor optimization opportunities, focus solely on correctness and safety.
Provide a top-level summary of critical blockers rather than detailed per-line notes.
Comment only when the issue must be resolved before merge, otherwise remain silent.
When in doubt, err on the side of fewer comments, brevity and blocking issues only.
Avoid posting any refactoring issues.

Files:

  • packages/clerk-js/src/core/resources/__tests__/Session.test.ts
  • packages/shared/src/types/session.ts
  • packages/clerk-js/src/core/tokenCache.ts
  • packages/clerk-js/src/core/resources/Session.ts
  • packages/upgrade/src/versions/core-3/changes/gettoken-stale-while-revalidate.md
  • packages/upgrade/src/versions/core-3/changes/gettoken-leeway-minimum.md
**/*.{md,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Update documentation for API changes

Files:

  • packages/upgrade/src/versions/core-3/changes/gettoken-stale-while-revalidate.md
  • packages/upgrade/src/versions/core-3/changes/gettoken-leeway-minimum.md
🧬 Code graph analysis (2)
packages/clerk-js/src/core/resources/__tests__/Session.test.ts (4)
packages/clerk-js/src/test/core-fixtures.ts (1)
  • clerkMock (249-256)
packages/clerk-js/src/core/tokenCache.ts (1)
  • SessionTokenCache (451-451)
packages/react/src/isomorphicClerk.ts (1)
  • session (722-728)
packages/clerk-js/src/core/resources/Session.ts (2)
  • Session (44-499)
  • token (422-433)
packages/clerk-js/src/core/tokenCache.ts (1)
packages/clerk-js/src/core/auth/SessionCookiePoller.ts (1)
  • POLLER_INTERVAL_IN_MS (7-7)
🪛 LanguageTool
packages/upgrade/src/versions/core-3/changes/gettoken-leeway-minimum.md

[uncategorized] ~47-~47: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ... 5s - threshold < 5s ``` ### Rate Limiting Warning Setting `backgroundRefreshThre...

(EN_COMPOUND_ADJECTIVE_INTERNAL)

🔇 Additional comments (10)
packages/upgrade/src/versions/core-3/changes/gettoken-stale-while-revalidate.md (1)

1-48: Documentation looks accurate and complete.

The documented behavior (15s default, 5s minimum threshold, SWR pattern, cross-tab sync) aligns with the implementation in tokenCache.ts and Session.ts.

packages/shared/src/types/session.ts (1)

341-365: Type definitions are well-structured with appropriate documentation.

The JSDoc accurately describes the new backgroundRefreshThreshold behavior and correctly marks refreshIfStale as internal.

packages/upgrade/src/versions/core-3/changes/gettoken-leeway-minimum.md (1)

1-54: Migration documentation is clear and includes appropriate warnings.

The rate limiting warning for high backgroundRefreshThreshold values is a valuable addition.

packages/clerk-js/src/core/resources/__tests__/Session.test.ts (1)

422-737: Comprehensive test coverage for SWR behavior.

The tests thoroughly cover the stale-while-revalidate pattern including:

  • Concurrent call deduplication during background refresh
  • Error resilience (token remains usable after refresh failure)
  • Successful refresh flow with cache update
  • Both refreshIfStale and backgroundRefreshThreshold options
packages/clerk-js/src/core/resources/Session.ts (3)

47-51: Static Set for tracking in-flight refreshes is correctly implemented.

The #backgroundRefreshInProgress Set properly prevents concurrent background refreshes for the same token, and the finally block at line 490-492 ensures cleanup regardless of success or failure.


454-493: Background refresh implementation follows SWR best practices.

The implementation correctly:

  1. Prevents concurrent refreshes via the static Set
  2. Updates cache only after successful refresh (line 483)
  3. Suppresses errors since callers already have a valid stale token
  4. Ensures cleanup in the finally block

366-368: Threshold validation correctly scoped to session tokens only.

The validation !template && Number(backgroundRefreshThreshold) >= 60 appropriately restricts the 60-second backgroundRefreshThreshold limit to default session tokens. Template tokens are excluded because they support custom expiration times via the expiresInSeconds parameter (confirmed by backend tests showing 3600-second lifespans with templates).

packages/clerk-js/src/core/tokenCache.ts (3)

51-58: TokenCacheGetResult interface provides clear SWR semantics.

The interface cleanly separates the cached entry from the refresh signal, enabling callers to make informed decisions about background refresh.


203-239: Cache lookup correctly implements stale-while-revalidate logic.

The implementation properly:

  1. Handles unresolved tokens (expiresIn undefined → Infinity → no premature refresh)
  2. Forces synchronous refresh when TTL ≤ 5s (poller interval)
  3. Enforces minimum threshold of 5s at line 232
  4. Returns both entry and needsRefresh flag for caller decision

366-369: Synchronous read optimization correctly implemented.

Storing resolvedToken after the promise resolves enables the optimization in Session.ts line 393 (cacheResult.entry.resolvedToken ?? (await cacheResult.entry.tokenResolver)) to avoid microtask overhead for already-resolved tokens.


Comment @coderabbitai help to get the list of available commands and usage tips.

@vercel
Copy link

vercel bot commented Nov 26, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
clerk-js-sandbox Ready Ready Preview, Comment Jan 13, 2026 3:49am

@jacekradko jacekradko marked this pull request as ready for review December 1, 2025 17:23
const tokenResolver = Token.create(path, params, false);

// Cache the promise immediately to prevent concurrent calls from triggering duplicate requests
SessionTokenCache.set({ tokenId, tokenResolver });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will update the tokenResolver during the background refresh. As per the separate comment, this is not a problem during this getToken call, but wont this be a problem for any subsequent getToken calls?

I haven't verified this, so it's just my reading of the code, but I saw no test cases for this which might also be nice to add.

Say I have two queries using getToken, both triggered from components that render together. The first getToken call triggers a background refresh, which sets the tokenResolver to a promise. This first getToken returns the value immediately as it awaits the previous tokenResolver.

The second call to getToken runs immediately after, does not call a background refresh since one is in progress, but it does read the value via await tokenResolver which is now the promise for the background refresh, because of this, the second getToken call does not SWR correctly even if it should?

Since we might have to touch tokenResolver etc to fix this, this might (or might not!) be a good time to tackle something related too. Awaiting already finished promises still always resolve in a microtask at the end of the JS frame, which is inefficient, so we'll want some way to read the value synchronously after the fetch has finished. Just mentioning that in case this happens to align nicely with a fix for the above.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch. Indeed, concurrent calls while refreshing would behave incorrectly as we were awaiting the new in-flight token resolver instead of returning the stale value. To address this, we no longer cache the tokenResolver running in the background until it succeeds, unlike the normal fetch case where it's cached immediately to dedupe requests. We also added a resolvedToken value to the cache so it can be read synchronously without awaiting the resolver, which avoids the microtask overhead you mentioned.

b3f14aa

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also expanded the test coverage of the SWR behavior

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 2, 2025

Open in StackBlitz

@clerk/agent-toolkit

npm i https://pkg.pr.new/@clerk/agent-toolkit@7317

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@7317

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@7317

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@7317

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@7317

@clerk/dev-cli

npm i https://pkg.pr.new/@clerk/dev-cli@7317

@clerk/expo

npm i https://pkg.pr.new/@clerk/expo@7317

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@7317

@clerk/express

npm i https://pkg.pr.new/@clerk/express@7317

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@7317

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@7317

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@7317

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@7317

@clerk/react

npm i https://pkg.pr.new/@clerk/react@7317

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@7317

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@7317

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@7317

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@7317

@clerk/ui

npm i https://pkg.pr.new/@clerk/ui@7317

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@7317

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@7317

commit: d2cac65

Copy link
Member

@Ephem Ephem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the latest changes! Using the poller for the background revalidation makes sense to me. I think there's still some torny parts to untangle, and besides the latest comments, something still feels harder than it should be here, so I wonder if we've found the correct mental model for this yet?

I have a few early thoughts, let's chat!


if (expiresSoon) {
// Token expired or dangerously close to expiration - force synchronous refresh
if (remainingTtl <= POLLER_INTERVAL_IN_MS / 1000) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default LEEWAY was 10s, and SYNC_LEEWAY was 5s, so if I'm reading this correctly, we used to sync fetch when less than 15s was remaining? Now this value is 5s?

I wonder if 5s is enough considering latency and all other factors?

However we change this it's a breaking change so let's remember to document it properly in the changelog when we've figured it out.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. Before we would do a blocking fetch under the 15s, now we use the stale value when it's under 15s but more than 5 seconds. The idea there is that the poller would async fetch the token before we get to the 5s. If that doesn't occur then we would force a sync fetch.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And yes, this is a breaking change so it's going to be part of Core 3

}

return value.entry;
const effectiveLeeway = Math.max(leeway, MIN_REMAINING_TTL_IN_SECONDS);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part is a bit weird. MIN_REMAINING_TTL_IN_SECONDS is 15s, and default LEEWAY is 10s, but the Math.max ensures we never go below 15s right?

If this is what we want(?), I think we should increase the LEEWAY to 15s as well, that way we document that "you can only raise this".

Thinking more on it, this PR now changes the public leewayInSeconds to only apply if you also use the internal refreshTokenOnFocus option? That seems off.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 In agreement here, this effectively forces leeway to always be equal to or greater than MIN_REMAINING_TTL_IN_SECONDS, do we want that value to be 5 or 15 going forward?

try {
const token = await this.clerk.session.getToken();
// Use refreshIfStale to fetch fresh token when cached token is within leeway period
const token = await this.clerk.session.getToken({ refreshIfStale: true });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also affects the refreshTokenOnFocus, but do we want that? Because those cases can be a race to finish setting the cookie before any external data fetching runs, it seems prudent to use the available token then?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔

Comment on lines +380 to +381
// Prefer synchronous read to avoid microtask overhead when token is already resolved
const cachedToken = cacheResult.entry.resolvedToken ?? (await cacheResult.entry.tokenResolver);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I mentioned in chat, when I made the comment about this I didn't think it through fully. To get the full benefits, we'd have to make sure _getToken/getToken itself to be synchronous when data is already available (or maybe more likely add the .status and .value/.reason fields to the promise).

This likely only makes sense if/when we decide to expose this promise to the end user so they can use it though.

I see you've used resolvedToken as the way to be able to have a background refetch running while still reading the currently cached token though so this still has immediate value. That was a bit unclear at first, but I think it makes sense, will need to think some more on it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. And yeah, right now the value is key to allow for returning the stale value, while we wait for the poller to do it's thing

@nikosdouvlis nikosdouvlis force-pushed the vincent-and-the-doctor branch from d24d455 to 12a12f5 Compare December 8, 2025 17:40
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/clerk-js/src/core/resources/__tests__/Session.test.ts (1)

543-544: Consider using a helper to generate mock JWTs consistently.

The manually crafted newMockJwt works for this test since it's comparing raw strings, but for maintainability, consider using the createJwtWithTtl helper (from tokenCache.test.ts) or a shared fixture to ensure JWT claims are always valid and consistent across tests.

packages/clerk-js/src/core/tokenCache.ts (1)

210-227: SWR logic is sound, but consider clarifying leeway behavior.

The implementation correctly:

  1. Evicts tokens with ≤5s remaining (forcing synchronous fetch)
  2. Signals needsRefresh when remaining TTL < effective leeway (minimum 15s)
  3. Returns the cached entry immediately regardless of staleness

However, the leeway parameter is effectively ignored when < 15s due to the floor at MIN_REMAINING_TTL_IN_SECONDS. While this is documented in the JSDoc, callers passing values like 10s (the default) may not realize their value has no effect.

Consider either:

  • Raising DEFAULT_LEEWAY to 15s to match the minimum, or
  • Adding a debug log when the provided leeway is floored

This is a minor clarity improvement and not blocking.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between ff335a0 and b1104ce.

📒 Files selected for processing (7)
  • packages/clerk-js/src/core/__tests__/tokenCache.test.ts (20 hunks)
  • packages/clerk-js/src/core/auth/AuthCookieService.ts (1 hunks)
  • packages/clerk-js/src/core/auth/SessionCookiePoller.ts (2 hunks)
  • packages/clerk-js/src/core/resources/Session.ts (2 hunks)
  • packages/clerk-js/src/core/resources/__tests__/Session.test.ts (4 hunks)
  • packages/clerk-js/src/core/tokenCache.ts (9 hunks)
  • packages/shared/src/types/session.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (12)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

All code must pass ESLint checks with the project's configuration

Files:

  • packages/shared/src/types/session.ts
  • packages/clerk-js/src/core/auth/AuthCookieService.ts
  • packages/clerk-js/src/core/auth/SessionCookiePoller.ts
  • packages/clerk-js/src/core/__tests__/tokenCache.test.ts
  • packages/clerk-js/src/core/tokenCache.ts
  • packages/clerk-js/src/core/resources/__tests__/Session.test.ts
  • packages/clerk-js/src/core/resources/Session.ts
**/*.{js,jsx,ts,tsx,json,md,yml,yaml}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use Prettier for consistent code formatting

Files:

  • packages/shared/src/types/session.ts
  • packages/clerk-js/src/core/auth/AuthCookieService.ts
  • packages/clerk-js/src/core/auth/SessionCookiePoller.ts
  • packages/clerk-js/src/core/__tests__/tokenCache.test.ts
  • packages/clerk-js/src/core/tokenCache.ts
  • packages/clerk-js/src/core/resources/__tests__/Session.test.ts
  • packages/clerk-js/src/core/resources/Session.ts
packages/**/src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

TypeScript is required for all packages

Files:

  • packages/shared/src/types/session.ts
  • packages/clerk-js/src/core/auth/AuthCookieService.ts
  • packages/clerk-js/src/core/auth/SessionCookiePoller.ts
  • packages/clerk-js/src/core/__tests__/tokenCache.test.ts
  • packages/clerk-js/src/core/tokenCache.ts
  • packages/clerk-js/src/core/resources/__tests__/Session.test.ts
  • packages/clerk-js/src/core/resources/Session.ts
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Follow established naming conventions (PascalCase for components, camelCase for variables)

Files:

  • packages/shared/src/types/session.ts
  • packages/clerk-js/src/core/auth/AuthCookieService.ts
  • packages/clerk-js/src/core/auth/SessionCookiePoller.ts
  • packages/clerk-js/src/core/__tests__/tokenCache.test.ts
  • packages/clerk-js/src/core/tokenCache.ts
  • packages/clerk-js/src/core/resources/__tests__/Session.test.ts
  • packages/clerk-js/src/core/resources/Session.ts
packages/**/src/**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

packages/**/src/**/*.{ts,tsx,js,jsx}: Maintain comprehensive JSDoc comments for public APIs
Use tree-shaking friendly exports
Validate all inputs and sanitize outputs
All public APIs must be documented with JSDoc
Use dynamic imports for optional features
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Implement proper logging with different levels

Files:

  • packages/shared/src/types/session.ts
  • packages/clerk-js/src/core/auth/AuthCookieService.ts
  • packages/clerk-js/src/core/auth/SessionCookiePoller.ts
  • packages/clerk-js/src/core/__tests__/tokenCache.test.ts
  • packages/clerk-js/src/core/tokenCache.ts
  • packages/clerk-js/src/core/resources/__tests__/Session.test.ts
  • packages/clerk-js/src/core/resources/Session.ts
**/*.ts?(x)

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use proper TypeScript error types

Files:

  • packages/shared/src/types/session.ts
  • packages/clerk-js/src/core/auth/AuthCookieService.ts
  • packages/clerk-js/src/core/auth/SessionCookiePoller.ts
  • packages/clerk-js/src/core/__tests__/tokenCache.test.ts
  • packages/clerk-js/src/core/tokenCache.ts
  • packages/clerk-js/src/core/resources/__tests__/Session.test.ts
  • packages/clerk-js/src/core/resources/Session.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/typescript.mdc)

**/*.{ts,tsx}: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoid any type - prefer unknown when type is uncertain, then narrow with type guards
Implement type guards for unknown types using the pattern function isType(value: unknown): value is Type
Use interface for object shapes that might be extended
Use type for unions, primitives, and computed types
Prefer readonly properties for immutable data structures
Use private for internal implementation details in classes
Use protected for inheritance hierarchies
Use public explicitly for clarity in public APIs
Use mixins for shared behavior across unrelated classes in TypeScript
Use generic constraints with bounded type parameters like <T extends { id: string }>
Use utility types like Omit, Partial, and Pick for data transformation instead of manual type construction
Use discriminated unions instead of boolean flags for state management and API responses
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation at the type level
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Document functions with JSDoc comments including @param, @returns, @throws, and @example tags
Create custom error classes that extend Error for specific error types
Use the Result pattern for error handling instead of throwing exceptions
Use optional chaining (?.) and nullish coalescing (??) operators for safe property access
Let TypeScript infer obvious types to reduce verbosity
Use const assertions with as const for literal types
Use satisfies operator for type checking without widening types
Declare readonly arrays and objects for immutable data structures
Use spread operator and array spread for immutable updates instead of mutations
Use lazy loading for large types...

Files:

  • packages/shared/src/types/session.ts
  • packages/clerk-js/src/core/auth/AuthCookieService.ts
  • packages/clerk-js/src/core/auth/SessionCookiePoller.ts
  • packages/clerk-js/src/core/__tests__/tokenCache.test.ts
  • packages/clerk-js/src/core/tokenCache.ts
  • packages/clerk-js/src/core/resources/__tests__/Session.test.ts
  • packages/clerk-js/src/core/resources/Session.ts
**/*.{js,ts,jsx,tsx}

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Use ESLint with custom configurations tailored for different package types

Files:

  • packages/shared/src/types/session.ts
  • packages/clerk-js/src/core/auth/AuthCookieService.ts
  • packages/clerk-js/src/core/auth/SessionCookiePoller.ts
  • packages/clerk-js/src/core/__tests__/tokenCache.test.ts
  • packages/clerk-js/src/core/tokenCache.ts
  • packages/clerk-js/src/core/resources/__tests__/Session.test.ts
  • packages/clerk-js/src/core/resources/Session.ts
**/*.{js,ts,jsx,tsx,json,md,yml,yaml}

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Use Prettier for code formatting across all packages

Files:

  • packages/shared/src/types/session.ts
  • packages/clerk-js/src/core/auth/AuthCookieService.ts
  • packages/clerk-js/src/core/auth/SessionCookiePoller.ts
  • packages/clerk-js/src/core/__tests__/tokenCache.test.ts
  • packages/clerk-js/src/core/tokenCache.ts
  • packages/clerk-js/src/core/resources/__tests__/Session.test.ts
  • packages/clerk-js/src/core/resources/Session.ts
**/*.{test,spec}.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

**/*.{test,spec}.{ts,tsx,js,jsx}: Unit tests are required for all new functionality
Verify proper error handling and edge cases
Include tests for all new features

Files:

  • packages/clerk-js/src/core/__tests__/tokenCache.test.ts
  • packages/clerk-js/src/core/resources/__tests__/Session.test.ts
**/*.{test,spec,e2e}.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use real Clerk instances for integration tests

Files:

  • packages/clerk-js/src/core/__tests__/tokenCache.test.ts
  • packages/clerk-js/src/core/resources/__tests__/Session.test.ts
**/*.test.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Use React Testing Library for component testing

Files:

  • packages/clerk-js/src/core/__tests__/tokenCache.test.ts
  • packages/clerk-js/src/core/resources/__tests__/Session.test.ts
🧬 Code graph analysis (5)
packages/clerk-js/src/core/auth/AuthCookieService.ts (1)
packages/clerk-js/src/core/resources/Session.ts (1)
  • token (402-413)
packages/clerk-js/src/core/auth/SessionCookiePoller.ts (1)
packages/astro/src/async-local-storage.client.ts (1)
  • run (17-19)
packages/clerk-js/src/core/tokenCache.ts (1)
packages/clerk-js/src/core/auth/SessionCookiePoller.ts (1)
  • POLLER_INTERVAL_IN_MS (7-7)
packages/clerk-js/src/core/resources/__tests__/Session.test.ts (4)
packages/clerk-js/src/test/core-fixtures.ts (1)
  • clerkMock (249-256)
packages/clerk-js/src/core/tokenCache.ts (1)
  • SessionTokenCache (440-440)
packages/react/src/isomorphicClerk.ts (1)
  • session (721-727)
packages/clerk-js/src/core/resources/Session.ts (2)
  • Session (44-439)
  • token (402-413)
packages/clerk-js/src/core/resources/Session.ts (3)
packages/clerk-js/src/core/tokenCache.ts (1)
  • SessionTokenCache (440-440)
packages/clerk-js/src/core/events.ts (2)
  • eventBus (32-32)
  • events (7-15)
packages/clerk-js/src/core/resources/Token.ts (1)
  • Token (7-57)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (28)
  • GitHub Check: Integration Tests (billing, chrome, RQ)
  • GitHub Check: Integration Tests (nextjs, chrome, 15)
  • GitHub Check: Integration Tests (nextjs, chrome, 16, RQ)
  • GitHub Check: Integration Tests (quickstart, chrome, 16)
  • GitHub Check: Integration Tests (machine, chrome, RQ)
  • GitHub Check: Integration Tests (nextjs, chrome, 16)
  • GitHub Check: Integration Tests (quickstart, chrome, 15)
  • GitHub Check: Integration Tests (billing, chrome)
  • GitHub Check: Integration Tests (machine, chrome)
  • GitHub Check: Integration Tests (custom, chrome)
  • GitHub Check: Integration Tests (nuxt, chrome)
  • GitHub Check: Integration Tests (ap-flows, chrome)
  • GitHub Check: Integration Tests (handshake, chrome)
  • GitHub Check: Integration Tests (vue, chrome)
  • GitHub Check: Integration Tests (react-router, chrome)
  • GitHub Check: Integration Tests (tanstack-react-start, chrome)
  • GitHub Check: Integration Tests (astro, chrome)
  • GitHub Check: Integration Tests (handshake:staging, chrome)
  • GitHub Check: Integration Tests (localhost, chrome)
  • GitHub Check: Integration Tests (sessions:staging, chrome)
  • GitHub Check: Integration Tests (sessions, chrome)
  • GitHub Check: Integration Tests (express, chrome)
  • GitHub Check: Integration Tests (generic, chrome)
  • GitHub Check: Formatting | Dedupe | Changeset
  • GitHub Check: Build Packages
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (15)
packages/shared/src/types/session.ts (1)

343-351: Well-documented internal API addition for SWR behavior.

The refreshIfStale option is properly marked as @internal with clear documentation explaining its purpose. This enables the token poller to proactively refresh tokens before they expire without exposing this mechanism to public consumers.

packages/clerk-js/src/core/auth/AuthCookieService.ts (1)

165-166: Correct use of refreshIfStale for proactive token refresh.

This ensures the poller and focus handler fetch fresh tokens when the cached token is within the leeway window. The focus handler's use of updateCookieImmediately: true (line 150) mitigates the race condition concern from previous reviews by ensuring the cookie is updated via microtask before external data-fetching libraries refetch.

packages/clerk-js/src/core/auth/SessionCookiePoller.ts (1)

6-7: Good: Exposing poller interval as a constant for cross-module alignment.

Exporting POLLER_INTERVAL_IN_MS enables the token cache to use the same interval for its "hard cutoff" logic, ensuring tokens aren't returned when they'll expire before the next poll opportunity. The 5-second interval with numeric separator is clear and readable.

packages/clerk-js/src/core/resources/__tests__/Session.test.ts (1)

421-578: Comprehensive SWR behavior test coverage.

The test suite effectively validates the stale-while-revalidate semantics:

  • Immediate stale token return with background refresh
  • Graceful degradation on network failures
  • Retry behavior after failures
  • Successful refresh propagation

The use of vi.advanceTimersByTime(46 * 1000) correctly positions the token in the leeway window (14s remaining < 15s threshold).

packages/clerk-js/src/core/__tests__/tokenCache.test.ts (4)

540-688: Thorough SWR leeway behavior tests with clear boundary conditions.

The tests effectively validate:

  • Fresh tokens return needsRefresh=false
  • Tokens within leeway return needsRefresh=true
  • Custom leeway values are honored when larger than the 15s minimum
  • The 15s minimum threshold is enforced even with leeway=0

The time-based assertions (e.g., 44s elapsed = 16s remaining vs. 46s elapsed = 14s remaining) clearly demonstrate the boundary behavior.


806-832: Critical: Hard cutoff test validates token expiration safety.

This test ensures tokens with less than the poller interval remaining (5s) are not returned, preventing race conditions where a "valid" token expires before the next refresh opportunity. The progression from 6s → 4s → 0s remaining with expected results (token → undefined → undefined) is well-designed.


1010-1063: Good coverage for resolvedToken synchronous access pattern.

The tests validate both scenarios:

  1. Token resolution timing: resolvedToken is undefined while pending, then populated after resolution
  2. Pre-resolved tokens: resolvedToken can be supplied upfront for hydration scenarios (e.g., from lastActiveToken)

This enables synchronous reads post-resolution, supporting the SWR pattern.


1065-1176: Multi-session isolation tests correctly updated for new result shape.

The access pattern changes (result.entry.tokenResolver, result.entry.tokenId) are consistent with the TokenCacheGetResult interface. The tests continue to validate that tokens from different sessions are properly isolated and broadcast synchronization works correctly.

packages/clerk-js/src/core/resources/Session.ts (4)

371-390: SWR implementation looks correct.

The logic correctly implements stale-while-revalidate semantics:

  • When needsRefresh is true but refreshIfStale is false (default), callers get the stale token immediately without blocking
  • The poller (using refreshIfStale: true) handles background refresh
  • Synchronous read via resolvedToken avoids microtask overhead for already-resolved tokens

This addresses the past review concerns about concurrent calls since normal getToken() calls no longer await a potentially in-flight background refresh.


392-400: Clean helper extraction.

The method properly encapsulates token creation logic. The explicit return type annotation aligns with coding guidelines.


402-413: Event dispatch logic is well-structured.

The conditional update of lastActiveToken only when token.jwt exists correctly handles the signed-out case where the token has an empty raw string. The TokenUpdate event is still emitted to notify listeners of the state.


415-433: Token fetch flow handles deduplication correctly.

Caching the promise immediately before awaiting prevents duplicate concurrent requests. Errors correctly propagate to the retry wrapper in getToken.

packages/clerk-js/src/core/tokenCache.ts (3)

51-58: Well-defined interface for the new return type.

The TokenCacheGetResult interface cleanly encapsulates the SWR semantics with the needsRefresh flag allowing callers to decide whether to trigger a background refresh.


355-358: Synchronous read optimization implemented correctly.

Storing resolvedToken after the promise resolves allows callers to bypass the microtask queue when reading already-resolved tokens. This is referenced in Session.ts where it's used with nullish coalescing: cacheResult.entry.resolvedToken ?? (await cacheResult.entry.tokenResolver).


276-288: Broadcast handler correctly adapted to new interface.

The comparison logic properly accesses result.entry.tokenResolver after the interface change.

Copy link
Member

@brkalow brkalow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good, left a few small comments!

Comment on lines 373 to 376
if (cacheResult.needsRefresh && refreshIfStale) {
debugLogger.debug('Token is stale, refreshing as requested', { tokenId }, 'session');
return this.#fetchToken(template, organizationId, tokenId, shouldDispatchTokenUpdate);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you think about firing off a this.#fetchToken() call without awaiting it if cacheResult.needsRefresh is true but refreshIfStale is falsy? This way we guarantee the cache is revalidated in the background without implicitly relying on the poller.

}

return value.entry;
const effectiveLeeway = Math.max(leeway, MIN_REMAINING_TTL_IN_SECONDS);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 In agreement here, this effectively forces leeway to always be equal to or greater than MIN_REMAINING_TTL_IN_SECONDS, do we want that value to be 5 or 15 going forward?

- Trigger background refresh when needsRefresh is true, without
  requiring refreshIfStale option. Guarantees cache revalidation
  without relying solely on the poller.

- Add #refreshTokenInBackground() that doesn't cache pending promise,
  allowing concurrent getToken() calls to return stale token while
  refresh is in progress.

- Track in-flight background refreshes to prevent duplicate requests.

- Rename DEFAULT_LEEWAY to BACKGROUND_REFRESH_THRESHOLD_IN_SECONDS
  with clear documentation about 15s minimum and rate limiting warning.

- Add comprehensive JSDoc for leewayInSeconds option explaining
  minimum value, default, and rate limiting considerations.
Add upgrade guide entries for:
- getToken `leewayInSeconds` minimum of 15 seconds
- stale-while-revalidate pattern for session tokens
- Test refreshIfStale: true forces synchronous refresh when token is stale
- Test refreshIfStale: true with fresh token returns cached value
- Test leewayInSeconds triggers earlier background refresh
- Test minimum 15s leeway enforcement
- Test no background refresh when token has sufficient TTL
@jacekradko
Copy link
Member Author

!snapshot

@clerk-cookie
Copy link
Collaborator

Hey @jacekradko - the snapshot version command generated the following package versions:

Package Version
@clerk/agent-toolkit 0.2.9-snapshot.v20260113023037
@clerk/astro 3.0.0-snapshot.v20260113023037
@clerk/backend 3.0.0-snapshot.v20260113023037
@clerk/chrome-extension 3.0.0-snapshot.v20260113023037
@clerk/clerk-js 6.0.0-snapshot.v20260113023037
@clerk/dev-cli 1.0.0-snapshot.v20260113023037
@clerk/expo 3.0.0-snapshot.v20260113023037
@clerk/expo-passkeys 1.0.0-snapshot.v20260113023037
@clerk/express 2.0.0-snapshot.v20260113023037
@clerk/fastify 2.6.9-snapshot.v20260113023037
@clerk/localizations 4.0.0-snapshot.v20260113023037
@clerk/msw 0.0.1-snapshot.v20260113023037
@clerk/nextjs 7.0.0-snapshot.v20260113023037
@clerk/nuxt 2.0.0-snapshot.v20260113023037
@clerk/react 6.0.0-snapshot.v20260113023037
@clerk/react-router 3.0.0-snapshot.v20260113023037
@clerk/shared 4.0.0-snapshot.v20260113023037
@clerk/tanstack-react-start 1.0.0-snapshot.v20260113023037
@clerk/testing 2.0.0-snapshot.v20260113023037
@clerk/ui 1.0.0-snapshot.v20260113023037
@clerk/upgrade 2.0.0-snapshot.v20260113023037
@clerk/vue 2.0.0-snapshot.v20260113023037

Tip: Use the snippet copy button below to quickly install the required packages.
@clerk/agent-toolkit

npm i @clerk/[email protected] --save-exact

@clerk/astro

npm i @clerk/[email protected] --save-exact

@clerk/backend

npm i @clerk/[email protected] --save-exact

@clerk/chrome-extension

npm i @clerk/[email protected] --save-exact

@clerk/clerk-js

npm i @clerk/[email protected] --save-exact

@clerk/dev-cli

npm i @clerk/[email protected] --save-exact

@clerk/expo

npm i @clerk/[email protected] --save-exact

@clerk/expo-passkeys

npm i @clerk/[email protected] --save-exact

@clerk/express

npm i @clerk/[email protected] --save-exact

@clerk/fastify

npm i @clerk/[email protected] --save-exact

@clerk/localizations

npm i @clerk/[email protected] --save-exact

@clerk/msw

npm i @clerk/[email protected] --save-exact

@clerk/nextjs

npm i @clerk/[email protected] --save-exact

@clerk/nuxt

npm i @clerk/[email protected] --save-exact

@clerk/react

npm i @clerk/[email protected] --save-exact

@clerk/react-router

npm i @clerk/[email protected] --save-exact

@clerk/shared

npm i @clerk/[email protected] --save-exact

@clerk/tanstack-react-start

npm i @clerk/[email protected] --save-exact

@clerk/testing

npm i @clerk/[email protected] --save-exact

@clerk/ui

npm i @clerk/[email protected] --save-exact

@clerk/upgrade

npm i @clerk/[email protected] --save-exact

@clerk/vue

npm i @clerk/[email protected] --save-exact

- Rename option from leewayInSeconds to backgroundRefreshThreshold for clarity
- Lower minimum threshold from 15s to 5s (poller interval)
- Remove explicit refreshIfStale: false in AuthCookieService (default behavior)
- Update tests and upgrade documentation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants