Script loader retry rejection is unhandled even after readiness resolves
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 48/100
- Issue-Typ
- Bug
- Klarheit
- Größtenteils klar
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- javascript, node.js, react, typescript
- Bereich
- authentication, backend, testing
Rechercherichtung
Start with packages/shared/src/loadClerkJsScript.ts, especially the JS and UI loader sections cited in the issue, and compare how their readiness and retry promises settle. Run the linked three-file reproduction with pnpm repro js late-success, pnpm repro ui late-success, and pnpm repro js failure. Done means the readiness deadline and late recovery behavior are preserved, terminal failures do not create detached unhandled rejections, and genuine failure causes remain useful.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Preliminary Checks
- Reviewed the SDK source and the documentation for
<ClerkFailed>. - Searched existing issues and pull requests for
failed_to_load_clerk_js,loadClerkJsScript, and script/promise rejection reports. - This investigation has not also been sent to Clerk support or Discord.
- This is a reproducible SDK bug report, not a general support question.
Reproduction
https://gist.github.com/ezhong0/340ae2483c3ccb40cc5865171c2b4858
A standalone three-file reproduction using the real published @clerk/shared package, fake DOM objects, and fake timers. It makes no network requests and requires no real Clerk application, browser, or credentials. The unhandledRejection listener observes the bug; it is not proposed as an application workaround.
Publishable key
pk_test_cHJvYmUuY2xlcmsuYWNjb3VudHMuZGV2JA==
This is a synthetic, parseable key for probe.clerk.accounts.dev, not a real application key. Script events are simulated locally.
Description
loadClerkJSScript / its loadClerkJsScript alias start a readiness promise and a script-load/retry promise, but return only readiness. The retry chain's catch throws into a detached promise. Consequently, a caller that handles both fulfillment and rejection of the returned promise can still receive an unhandled failed_to_load_clerk_js rejection. This also occurs after the returned promise has already resolved when another script makes Clerk available while the original retries remain outstanding.
The same pattern is present in loadClerkUIScript, producing failed_to_load_clerk_ui.
Current source inspected at 6c1b46a403e6883066cad1f9d8da9ef77364c940:
Steps to reproduce:
- Download the three gist files into an empty directory.
- Run
pnpm install --ignore-scripts. - Run
pnpm repro js late-successorpnpm repro ui late-success. - For the no-recovery case, run
pnpm repro js failure.
The late-success scenario simulates the Clerk global becoming available at 100ms while each pending script attempt reports an error at 200ms. Fake time advances far enough to settle the existing retry budget and readiness timeout. Both handlers are attached to the returned operation immediately.
Expected behavior:
Once readiness resolves, the operation stays successful and remaining script failures do not generate unhandled rejections. If Clerk never becomes ready, the returned operation rejects without a second, detached rejection.
Actual behavior with unmodified @clerk/shared 4.43.0:
{"kind":"js","scenario":"late-success","result":"resolved","attempts":6,"unhandled":["failed_to_load_clerk_js"]}
{"kind":"ui","scenario":"late-success","result":"resolved","attempts":6,"unhandled":["failed_to_load_clerk_ui"]}
{"kind":"js","scenario":"failure","result":"failed_to_load_clerk_js","attempts":6,"unhandled":["failed_to_load_clerk_js"]}
The JS case was also reproduced against 3.47.7. This report concerns promise ownership; it does not assert that the SDK causes the underlying network failure.
Follow-up investigation and correction to the proposed fix (2026-10-28):
The detached rejection also reproduces in a real browser with real HTTP 404 responses and real timers, using the published 3.47.7 loader through the actual @clerk/clerk-react 5.61.8 provider. The provider reaches status error and renders ClerkFailed after catching/logging the readiness timeout, but a separate failed_to_load_clerk_js still reaches window.unhandledrejection. This does not require an application-supplied duplicate provider or a fake DOM.
A separate browser case in both 3.47.7 and 4.43.0 used a successful second script response to create the expected Clerk global while the original script requests failed. The returned readiness promise resolved; the original retry chain subsequently produced the unhandled rejection. This proves the loader sequence, not successful real-account authentication or the cause of any external network outage.
I am withdrawing the simple Promise.race([loadPromise, scriptPromise]) proposal as a ready-to-use fix. Further testing exposed a semantic regression: retries can finish before the readiness deadline, while another script can still make Clerk available before that deadline. In an isolated 3.47.7 comparison with readiness at 10 seconds and a 15-second deadline, the original loader resolved at 10 seconds, but the race patch rejected at approximately 6.5 seconds and could not recover. The earlier checks covered readiness before retry exhaustion and missed this ordering.
An upstream fix should preserve the readiness deadline/recovery contract, own the retry rejection, and retain useful error/cause reporting for genuine terminal failures. Simply consuming the global rejection can also affect observability because the React provider handles the returned rejection with console.error; consumers may monitor runtime errors separately from console logs.
Opening this for maintainer guidance on those semantics before contributing a source PR. A compatible shared 3.x backport would also help applications on Next.js SDK 6.x. The issue remains the detached rejection, not a claim that the SDK causes underlying network delivery failures.
Environment
- Ubuntu 24.04.4 LTS, x86_64
- Node 24.22.0
- pnpm 10.33.0
@clerk/shared4.43.0 (standalone reproduction)@sinonjs/fake-timers15.4.0- No browser: synthetic DOM and timers, invoking the published SDK export
- Vorherrschende Sprache
- TypeScript
- Sterne
- 1.8k
- Forks
- 492
- Ø Merge
- 1 T. 7 Std.
- Gemergte PRs (30 T.)
- 357
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus clerk/javascript
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
clerk/javascript#10708 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Built-in reverification dialog lacks an accessible name (aria-dialog-name)Evtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
clerk/javascript#10548 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
clerk/javascript#10547 ·
Maintainer antworten meist innerhalb von 1 Tag
-
<SignIn />: first "Use email" click switches back to phone when `initialValues.phoneNumber` is setEvtl. vergeben @twicestruck hat das vor 20 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
clerk/javascript#10487 ·
Maintainer antworten meist innerhalb von 1 Tag
-
useLoadedIsomorphicClerk misses "ready" when a ClerkProvider remounts after clerk-js has loaded — <ClerkLoading> never resolvesEvtl. wieder frei Ein Pull Request dazu wurde ohne Merge geschlossen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
clerk/javascript#10462 ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in clerk/javascript
Ähnliche Issues
-
bot:ai-assisted component:platform-js status:untriaged
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 74/100
midnightntwrk/platform-js#38 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
ranxianglei/billion-context#7068 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
mybigday/whisper.rn#348 ·
-
enhancement severity:low
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
Battle-Cattle/BCUK-Bot-4#1075 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 67/100
ilan-pinto/roaring-lions#1552 ·
Maintainer antworten meist innerhalb von 1 Tag