fix(clerk-js): backport fail-fast slow-origin load for Core 2#9123
fix(clerk-js): backport fail-fast slow-origin load for Core 2#9123nikosdouvlis wants to merge 1 commit into
Conversation
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 detectedLatest commit: 7853518 The changes in this PR will be included in the next version bump. This PR includes changesets to release 22 packages
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 |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
@clerk/agent-toolkit
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/dev-cli
@clerk/elements
@clerk/clerk-expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/clerk-react
@clerk/react-router
@clerk/remix
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/themes
@clerk/types
@clerk/upgrade
@clerk/vue
commit: |
Backports the fail-fast slow-origin load fix from #9065 to the
release/core-2line.When Clerk's Frontend API is slow or unreachable during load, a cold
Clerk.load()could hang for a long time. The/clientrequest 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
/clientfetch and the load-recovery token mint are now bounded by a 7s timeout, and the timed-out/clientrequest is aborted instead of being left in flight (via a new optionalabortSignalthreaded throughClient.fetchdown to the native fetch signal). On a slow or failed/client, recovery renders identity from the__sessioncookie, 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 atimeLimitutility to@clerk/shared/utils.As-is backport
This matches main's current behavior, including the known gaps documented on #9065: the
/environmentrequest 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-2diverged from main about 7 months ago, so this is an adaptation rather than a cherry-pick. Core-2 already hadcreateClientFromJwtand thetokenFreshnessguard (backported in #9090), so only theinitClientrecovery body inload()was swapped; theabortSignalplumbing and thetimeLimitutil are net-new. No#clientUpdateGenerationguard exists on core-2 and none was added.Verification
On the core-2 branch:
timeLimit6/6,clerk.test.ts109/109 (including 7 new degraded-load tests),jwt-client.test.ts3/3,fapiClient.test.ts26 passing, and the clerk-js declarations typecheck is clean.