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

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

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, although they're not differentiated by filename. 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: 1b53f83

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 8, 2025 6:43pm

@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.

],
optimization: {
splitChunks: false,
const clerkEsm = merge(
Copy link
Member Author

Choose a reason for hiding this comment

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

none of this was actually changed, it's just a formatting thing

Copy link
Member

Choose a reason for hiding this comment

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

Where does the formatting change come from then? Your personal prettier settings? If I open the file in my editor ESLint doesn't want to format the file.

Ideally such unintended formatting changes don't make it into the PR as it's quite possible that another PR will undo them later again.

Copy link
Member Author

Choose a reason for hiding this comment

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

Previously Prettier kept everything on one line since it was below our max line length threshold. Since the line is longer (due to the inclusion of the { targets: packageJSON.browserslist } argument), it splits the arguments to merge into separate lines. This confuses the GitHub diff formatter into thinking the lines have changed due to how the final argument to merge is now indented. So this is Prettier working as expected! I just wanted to make sure folks weren't struggling to find the difference between the two :)

Copy link
Member

@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

],
optimization: {
splitChunks: false,
const clerkEsm = merge(
Copy link
Member

Choose a reason for hiding this comment

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

Where does the formatting change come from then? Your personal prettier settings? If I open the file in my editor ESLint doesn't want to format the file.

Ideally such unintended formatting changes don't make it into the PR as it's quite possible that another PR will undo them later again.

@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.

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.

3 participants