Skip to content

feat(clerk-js): Introduce legacy browser variant #5495

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

Merged
merged 16 commits into from
Apr 18, 2025
Merged

Conversation

dstaley
Copy link
Member

@dstaley dstaley commented Mar 31, 2025

Description

This PR introduces a new legacy variant of clerk.browser, intended to be used for instances that require compatibility with browsers released in mid-2019 or newer. This is achieved through the use of core-js, which polyfills modern JavaScript APIs, in addition to the language-level transformations provided by SWC.

We now emit two primary clerk.browser bundles:

  • clerk.browser.js: This is our "modern"/default bundle that adheres to our browser support policy as specified by browserslist in package.json. This bundle includes language-level transformations for supported browsers, but does not include core-js polyfills. This is because core-js will polyfill divergent behaviors between browsers, inflating our bundle size.
  • clerk.legacy.browser.js: This is our legacy bundle that adheres to the browser support policy specified by browserslistLegacy in package.json, which supports browsers released in mid-2019 and later. It includes language-level transformations from SWC in addition to core-js polyfills. It is an additional 35KB gzipped compared to the default clerk.browser.js bundle.

In addition to the bundles, we also emit separate chunks for the legacy variant. clerk.legacy.browser.js will load legacy-compatible chunks, whereas clerk.browser.js will load modern-compatible chunks.

As of writing, it's not intended for customers to be able to manually switch to the legacy bundle since it's outside our official browser support matrix. We will be enabling this at the Cloudflare proxy level only for specific customers who have an agreement with us and a demonstrated need for legacy browser compatibility.

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 31, 2025

🦋 Changeset detected

Latest commit: a01916b

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 Minor
@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 31, 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 Apr 18, 2025 1:52pm

@dstaley
Copy link
Member Author

dstaley commented Mar 31, 2025

!snapshot

@clerk-cookie
Copy link
Collaborator

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

Package Version
@clerk/agent-toolkit 0.0.17-snapshot.v20250331181940
@clerk/astro 2.4.6-snapshot.v20250331181940
@clerk/backend 1.26.0-snapshot.v20250331181940
@clerk/chrome-extension 2.2.24-snapshot.v20250331181940
@clerk/clerk-js 5.59.0-snapshot.v20250331181940
@clerk/elements 0.23.9-snapshot.v20250331181940
@clerk/clerk-expo 2.9.7-snapshot.v20250331181940
@clerk/expo-passkeys 0.2.1-snapshot.v20250331181940
@clerk/express 1.3.60-snapshot.v20250331181940
@clerk/fastify 2.1.33-snapshot.v20250331181940
@clerk/localizations 3.13.5-snapshot.v20250331181940
@clerk/nextjs 6.12.13-snapshot.v20250331181940
@clerk/nuxt 1.4.7-snapshot.v20250331181940
@clerk/clerk-react 5.25.6-snapshot.v20250331181940
@clerk/react-router 1.1.12-snapshot.v20250331181940
@clerk/remix 4.5.12-snapshot.v20250331181940
@clerk/shared 3.3.0-snapshot.v20250331181940
@clerk/tanstack-react-start 0.12.3-snapshot.v20250331181940
@clerk/testing 1.4.34-snapshot.v20250331181940
@clerk/themes 2.2.27-snapshot.v20250331181940
@clerk/types 4.50.2-snapshot.v20250331181940
@clerk/vue 1.4.6-snapshot.v20250331181940

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

npm i @clerk/[email protected] --save-exact

@clerk/astro

npm i @clerk/[email protected] --save-exact

@clerk/backend

npm i @clerk/[email protected] --save-exact

@clerk/chrome-extension

npm i @clerk/[email protected] --save-exact

@clerk/clerk-js

npm i @clerk/[email protected] --save-exact

@clerk/elements

npm i @clerk/[email protected] --save-exact

@clerk/clerk-expo

npm i @clerk/[email protected] --save-exact

@clerk/expo-passkeys

npm i @clerk/[email protected] --save-exact

@clerk/express

npm i @clerk/[email protected] --save-exact

@clerk/fastify

npm i @clerk/[email protected] --save-exact

@clerk/localizations

npm i @clerk/[email protected] --save-exact

@clerk/nextjs

npm i @clerk/[email protected] --save-exact

@clerk/nuxt

npm i @clerk/[email protected] --save-exact

@clerk/clerk-react

npm i @clerk/[email protected] --save-exact

@clerk/react-router

npm i @clerk/[email protected] --save-exact

@clerk/remix

npm i @clerk/[email protected] --save-exact

@clerk/shared

npm i @clerk/[email protected] --save-exact

@clerk/tanstack-react-start

npm i @clerk/[email protected] --save-exact

@clerk/testing

npm i @clerk/[email protected] --save-exact

@clerk/themes

npm i @clerk/[email protected] --save-exact

@clerk/types

npm i @clerk/[email protected] --save-exact

@clerk/vue

npm i @clerk/[email protected] --save-exact

@@ -158,7 +160,13 @@ const typescriptLoaderProd = () => {
loader: 'builtin:swc-loader',
options: {
env: {
targets: packageJSON.browserslist,
targets,
...(useCoreJs
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because core-js will inject polyfills even in our more modern targets, we only enable it when we know we're targeting legacy browsers.

Copy link
Contributor

@LekoArts LekoArts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd argue that with this change we should also change our existing browserslist entry and remove the legacy information (Safari > 12, iOS > 12), write down the exact browsers we support in our docs, and set the browserslist according to that

@dstaley
Copy link
Member Author

dstaley commented Apr 1, 2025

I'd argue that with this change we should also change our existing browserslist entry and remove the legacy information (Safari > 12, iOS > 12)

I absolutely agree with this, but it might break other customers who were relying on the transformations that SWC was applying to fit those targets. We're going to be discussing this more during the SDK Infra meeting this week to determine if we're okay accepting that. The current plan is to opt instances into the legacy bundle via CF worker, so we might be hesitant to suddenly break previously working browsers during a minor update.

@dstaley dstaley marked this pull request as ready for review April 14, 2025 20:25
@@ -65,7 +68,7 @@ const common = ({ mode, disableRHC = false }) => {
}),
].filter(Boolean),
output: {
chunkFilename: `[name]_[fullhash:6]_${packageJSON.version}.js`,
chunkFilename: `[name]_${variant}_[fullhash:6]_${packageJSON.version}.js`,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so that we can distinguish which variant a chunk belongs to, mainly so we could (in the future) target specific variant chunks with specific bundlewatch rules.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 4 out of 7 changed files in this pull request and generated 1 comment.

Files not reviewed (3)
  • packages/clerk-js/bundlewatch.config.json: Language not supported
  • packages/clerk-js/package.json: Language not supported
  • pnpm-lock.yaml: Language not supported

Copy link
Contributor

@LekoArts LekoArts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally speaking LGTM, left one minor comment.

Did you test a current snapshot of the normal browser and legacy bundle to see that old and new behavior is OK?

It would also be good to start a docs PR (if not already done) to update our https://clerk.com/docs/upgrade-guides/long-term-support#library-compatibility page

Copy link
Member

@jacekradko jacekradko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's give it a whirl!

@dstaley dstaley merged commit 6f4cf71 into main Apr 18, 2025
30 checks passed
@dstaley dstaley deleted the ds.feat/core-js branch April 18, 2025 21:57
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.

5 participants