Skip to content

fix(clerk-js): backport fail-fast slow-origin load for Core 2#9123

Open
nikosdouvlis wants to merge 1 commit into
release/core-2from
backport/9065-fail-fast-slow-origin-core-2
Open

fix(clerk-js): backport fail-fast slow-origin load for Core 2#9123
nikosdouvlis wants to merge 1 commit into
release/core-2from
backport/9065-fail-fast-slow-origin-core-2

Conversation

@nikosdouvlis

Copy link
Copy Markdown
Member

Backports the fail-fast slow-origin load fix from #9065 to the release/core-2 line.

When Clerk's Frontend API is slow or unreachable during load, a cold Clerk.load() could hang for a long time. The /client request had no timeout, and on a 5xx or network error the recovery path burned the full retry budget before Clerk was marked loaded, so during an origin outage the app sat unresponsive instead of degrading and rendering.

What changed
The /client fetch and the load-recovery token mint are now bounded by a 7s timeout, and the timed-out /client request is aborted instead of being left in flight (via a new optional abortSignal threaded through Client.fetch down to the native fetch signal). On a slow or failed /client, recovery renders identity from the __session cookie, clears the session's token cache so the mint bypasses the cache, and keeps the cookie identity if the mint times out. After a degraded load, the client is re-fetched in the background without a time limit so a slow-but-healthy origin recovers full client data without a reload. Also adds a timeLimit utility to @clerk/shared/utils.

As-is backport
This matches main's current behavior, including the known gaps documented on #9065: the /environment request is not yet bounded, and the recovery mint stops waiting but isn't cancellable. Those are intentionally carried over so core-2 tracks main, and will be backported once they're addressed there.

Adapted to core-2
release/core-2 diverged from main about 7 months ago, so this is an adaptation rather than a cherry-pick. Core-2 already had createClientFromJwt and the tokenFreshness guard (backported in #9090), so only the initClient recovery body in load() was swapped; the abortSignal plumbing and the timeLimit util are net-new. No #clientUpdateGeneration guard exists on core-2 and none was added.

Verification
On the core-2 branch: timeLimit 6/6, clerk.test.ts 109/109 (including 7 new degraded-load tests), jwt-client.test.ts 3/3, fapiClient.test.ts 26 passing, and the clerk-js declarations typecheck is clean.

Backports the fail-fast slow-origin load fix (#9065) to the release/core-2
line. When FAPI is slow or unreachable during load, a cold Clerk.load()
could hang for minutes. The /client request and the load-recovery token mint
are now bounded by a 7s timeout, the timed-out request is aborted, and
recovery renders identity from the session cookie while an unbounded
background refetch restores full client data. Adds a timeLimit util to
@clerk/shared/utils.
@changeset-bot

changeset-bot Bot commented Jul 10, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7853518

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

This PR includes changesets to release 22 packages
Name Type
@clerk/clerk-js Patch
@clerk/shared Patch
@clerk/chrome-extension Patch
@clerk/clerk-expo Patch
@clerk/agent-toolkit Patch
@clerk/astro Patch
@clerk/backend Patch
@clerk/elements Patch
@clerk/expo-passkeys Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/nextjs Patch
@clerk/nuxt Patch
@clerk/react-router Patch
@clerk/clerk-react Patch
@clerk/remix Patch
@clerk/tanstack-react-start Patch
@clerk/testing Patch
@clerk/themes Patch
@clerk/types Patch
@clerk/vue Patch
@clerk/localizations 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

@vercel

vercel Bot commented Jul 10, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
clerk-js-sandbox Ready Ready Preview, Comment Jul 10, 2026 11:00am
swingset Error Error Jul 10, 2026 11:00am

Request Review

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 1f286482-13b4-4559-b25b-8572594962ba

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch backport/9065-fail-fast-slow-origin-core-2

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

@pkg-pr-new

pkg-pr-new Bot commented Jul 10, 2026

Copy link
Copy Markdown

Open in StackBlitz

@clerk/agent-toolkit

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

@clerk/astro

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

@clerk/backend

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

@clerk/chrome-extension

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

@clerk/clerk-js

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

@clerk/dev-cli

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

@clerk/elements

npm i https://pkg.pr.new/@clerk/elements@9123

@clerk/clerk-expo

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

@clerk/expo-passkeys

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

@clerk/express

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

@clerk/fastify

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

@clerk/localizations

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

@clerk/nextjs

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

@clerk/nuxt

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

@clerk/clerk-react

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

@clerk/react-router

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

@clerk/remix

npm i https://pkg.pr.new/@clerk/remix@9123

@clerk/shared

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

@clerk/tanstack-react-start

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

@clerk/testing

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

@clerk/themes

npm i https://pkg.pr.new/@clerk/themes@9123

@clerk/types

npm i https://pkg.pr.new/@clerk/types@9123

@clerk/upgrade

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

@clerk/vue

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

commit: 7853518

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant