fix(react): Use globalThis instead of bare global in the browser Clerk loader#8909
Conversation
🦋 Changeset detectedLatest commit: 3ab67ad The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 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.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository YAML (base), Repository UI (inherited) Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughThe PR fixes a production ChangesglobalThis migration fix
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Possibly related issues
Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
Comment |
API Changes Report
Summary
No API Changes DetectedAll packages have stable APIs with no detected changes. Report generated by Break Check Last ran on |
…k loader The browser loader in isomorphicClerk read/wrote a bare `global.Clerk` identifier that only resolved because of the `window.global` polyfill side-effect on the package's main entry. The provider runs through `@clerk/react/internal`, which never imports that polyfill, so after the tsup to tsdown migration split the package into separate chunks a downstream production build could reach the loader with `global` undefined and throw `ReferenceError: global is not defined`. Switch the loader to `globalThis` (always defined; equals `window` in the browser, where clerk-js writes `window.Clerk`) and add a `declare global` augmentation so it type-checks. The polyfill is kept for backward-compat. Fixes #8871
27fc09a to
3ab67ad
Compare
Fixes #8871.
<ClerkProvider>crashed in production builds (TanStack Start, React Router) withReferenceError: global is not defined. The loader read a bareglobal.Clerkthat only resolved via thewindow.globalpolyfill on the package's main entry, but the provider comes in through@clerk/react/internal, which never imports that polyfill; since the tsdown migration (#8177) split the package into chunks, a production bundle can reach the loader with the polyfill absent. UsingglobalThisdrops the dependency.The bit worth scrutiny is the type change:
declare const globalonly typed theglobalname, soglobalThis.Clerkneeds adeclare globalaugmentation. It's intentionally not emitted into the public.d.ts, so consumers don't gain an ambientClerkglobal. Thewindow.globalpolyfill is kept for older clerk-js runtimes.Summary by CodeRabbit