-
Notifications
You must be signed in to change notification settings - Fork 327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(clerk-js): Ensure window.Clerk is only ever assigned once #5406
Conversation
🦋 Changeset detectedLatest commit: 01498b7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 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 Git ↗︎
|
}); | ||
// Ensure that if the script has already been injected we don't overwrite the existing Clerk instance. | ||
if (!window.Clerk) { | ||
window.Clerk = new Clerk(publishableKey, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the publishable key changes, would we expect this to get reassigned?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe? I wouldn't necessarily expect the PK to change within the lifecycle of a single session. I don't think it would work correctly today regardless.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we support this for expo ?
!snapshot |
Hey @brkalow - the snapshot version command generated the following package versions:
Tip: Use the snippet copy button below to quickly install the required packages. npm i @clerk/agent-toolkit@0.0.12-snapshot.v20250320214539 --save-exact
npm i @clerk/astro@2.4.1-snapshot.v20250320214539 --save-exact
npm i @clerk/backend@1.25.4-snapshot.v20250320214539 --save-exact
npm i @clerk/chrome-extension@2.2.18-snapshot.v20250320214539 --save-exact
npm i @clerk/clerk-js@5.57.1-snapshot.v20250320214539 --save-exact
npm i @clerk/clerk-expo@2.9.1-snapshot.v20250320214539 --save-exact
npm i @clerk/express@1.3.55-snapshot.v20250320214539 --save-exact
npm i @clerk/fastify@2.1.28-snapshot.v20250320214539 --save-exact
npm i @clerk/nextjs@6.12.7-snapshot.v20250320214539 --save-exact
npm i @clerk/nuxt@1.4.2-snapshot.v20250320214539 --save-exact
npm i @clerk/react-router@1.1.7-snapshot.v20250320214539 --save-exact
npm i @clerk/remix@4.5.7-snapshot.v20250320214539 --save-exact
npm i @clerk/testing@1.4.29-snapshot.v20250320214539 --save-exact |
Description
In scenarios where the clerk-js script is injected multiple times, it's possible that
window.Clerk
can be re-assigned while Clerk is loading, causing Clerk to get stuck in a state where it never gets marked as "loaded". Adding this check ensures that even if the script is re-injected, we don't re-assign the originalwindow.Clerk
.Checklist
pnpm test
runs as expected.pnpm build
runs as expected.Type of change