Skip to content
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

Merged
merged 1 commit into from
Mar 21, 2025

Conversation

brkalow
Copy link
Member

@brkalow brkalow commented Mar 20, 2025

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 original window.Clerk.

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Copy link

changeset-bot bot commented Mar 20, 2025

🦋 Changeset detected

Latest commit: 01498b7

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

This PR includes changesets to release 3 packages
Name Type
@clerk/clerk-js Patch
@clerk/chrome-extension Patch
@clerk/clerk-expo 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

Copy link

vercel bot commented Mar 20, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
clerk-js-sandbox ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 20, 2025 8:19pm

});
// 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, {
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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 ?

@brkalow
Copy link
Member Author

brkalow commented Mar 20, 2025

!snapshot

@clerk-cookie
Copy link
Collaborator

Hey @brkalow - the snapshot version command generated the following package versions:

Package Version
@clerk/agent-toolkit 0.0.12-snapshot.v20250320214539
@clerk/astro 2.4.1-snapshot.v20250320214539
@clerk/backend 1.25.4-snapshot.v20250320214539
@clerk/chrome-extension 2.2.18-snapshot.v20250320214539
@clerk/clerk-js 5.57.1-snapshot.v20250320214539
@clerk/clerk-expo 2.9.1-snapshot.v20250320214539
@clerk/express 1.3.55-snapshot.v20250320214539
@clerk/fastify 2.1.28-snapshot.v20250320214539
@clerk/nextjs 6.12.7-snapshot.v20250320214539
@clerk/nuxt 1.4.2-snapshot.v20250320214539
@clerk/react-router 1.1.7-snapshot.v20250320214539
@clerk/remix 4.5.7-snapshot.v20250320214539
@clerk/testing 1.4.29-snapshot.v20250320214539

Tip: Use the snippet copy button below to quickly install the required packages.
@clerk/agent-toolkit

npm i @clerk/agent-toolkit@0.0.12-snapshot.v20250320214539 --save-exact

@clerk/astro

npm i @clerk/astro@2.4.1-snapshot.v20250320214539 --save-exact

@clerk/backend

npm i @clerk/backend@1.25.4-snapshot.v20250320214539 --save-exact

@clerk/chrome-extension

npm i @clerk/chrome-extension@2.2.18-snapshot.v20250320214539 --save-exact

@clerk/clerk-js

npm i @clerk/clerk-js@5.57.1-snapshot.v20250320214539 --save-exact

@clerk/clerk-expo

npm i @clerk/clerk-expo@2.9.1-snapshot.v20250320214539 --save-exact

@clerk/express

npm i @clerk/express@1.3.55-snapshot.v20250320214539 --save-exact

@clerk/fastify

npm i @clerk/fastify@2.1.28-snapshot.v20250320214539 --save-exact

@clerk/nextjs

npm i @clerk/nextjs@6.12.7-snapshot.v20250320214539 --save-exact

@clerk/nuxt

npm i @clerk/nuxt@1.4.2-snapshot.v20250320214539 --save-exact

@clerk/react-router

npm i @clerk/react-router@1.1.7-snapshot.v20250320214539 --save-exact

@clerk/remix

npm i @clerk/remix@4.5.7-snapshot.v20250320214539 --save-exact

@clerk/testing

npm i @clerk/testing@1.4.29-snapshot.v20250320214539 --save-exact

@brkalow brkalow merged commit 598d1ce into main Mar 21, 2025
31 checks passed
@brkalow brkalow deleted the brk.fix/clerk-js-re-assign branch March 21, 2025 03:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants