Skip to content

Commit 8a49ea7

Browse files
authored
feat(ui): build legacy variant (#7472)
1 parent e9be68d commit 8a49ea7

File tree

8 files changed

+82
-21
lines changed

8 files changed

+82
-21
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@clerk/ui": minor
3+
---
4+
5+
Add legacy browser variant build support for older browsers

packages/clerk-js/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,14 @@
6666
"@solana/wallet-adapter-react": "catalog:module-manager",
6767
"@solana/wallet-standard": "catalog:module-manager",
6868
"@stripe/stripe-js": "5.6.0",
69-
"@swc/helpers": "^0.5.17",
69+
"@swc/helpers": "catalog:repo",
7070
"@tanstack/query-core": "5.87.4",
7171
"@wallet-standard/core": "catalog:module-manager",
7272
"@zxcvbn-ts/core": "catalog:module-manager",
7373
"@zxcvbn-ts/language-common": "catalog:module-manager",
7474
"alien-signals": "2.0.6",
7575
"browser-tabs-lock": "1.3.0",
76-
"core-js": "3.41.0",
76+
"core-js": "catalog:repo",
7777
"crypto-js": "^4.2.0",
7878
"dequal": "2.0.3"
7979
},

packages/ui/bundlewatch.config.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
{
22
"files": [
33
{ "path": "./dist/ui.browser.js", "maxSize": "19.5KB" },
4+
{ "path": "./dist/ui.legacy.browser.js", "maxSize": "54KB" },
45
{ "path": "./dist/framework*.js", "maxSize": "44KB" },
5-
{ "path": "./dist/vendors*.js", "maxSize": "69KB" },
6-
{ "path": "./dist/ui-common*.js", "maxSize": "123KB" },
6+
{ "path": "./dist/vendors*.js", "maxSize": "73KB" },
7+
{ "path": "./dist/ui-common*.js", "maxSize": "128KB" },
78
{ "path": "./dist/signin*.js", "maxSize": "16KB" },
89
{ "path": "./dist/signup*.js", "maxSize": "11KB" },
910
{ "path": "./dist/userprofile*.js", "maxSize": "16KB" },
@@ -31,6 +32,6 @@
3132
{ "path": "./dist/op-plans-page*.js", "maxSize": "3KB" },
3233
{ "path": "./dist/statement-page*.js", "maxSize": "5KB" },
3334
{ "path": "./dist/payment-attempt-page*.js", "maxSize": "4KB" },
34-
{ "path": "./dist/web3-solana-wallet-buttons*.js", "maxSize": "78KB" }
35+
{ "path": "./dist/web3-solana-wallet-buttons*.js", "maxSize": "79KB" }
3536
]
3637
}

packages/ui/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@
7878
"@solana/wallet-adapter-base": "catalog:module-manager",
7979
"@solana/wallet-adapter-react": "catalog:module-manager",
8080
"@solana/wallet-standard": "catalog:module-manager",
81+
"@swc/helpers": "catalog:repo",
8182
"copy-to-clipboard": "3.3.3",
83+
"core-js": "catalog:repo",
8284
"csstype": "3.1.3",
8385
"dequal": "2.0.3",
8486
"input-otp": "1.4.2",
@@ -106,5 +108,6 @@
106108
},
107109
"publishConfig": {
108110
"access": "public"
109-
}
111+
},
112+
"browserslistLegacy": "Chrome > 73, Firefox > 66, Safari > 12, iOS > 12, Edge > 18, Opera > 58"
110113
}

packages/ui/rspack.config.js

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ import rspack from '@rspack/core';
33
import packageJSON from './package.json' with { type: 'json' };
44
import path from 'path';
55
import { fileURLToPath } from 'url';
6+
import { createRequire } from 'module';
67
import { merge } from 'webpack-merge';
78
import ReactRefreshPlugin from '@rspack/plugin-react-refresh';
89
import { svgLoader, typescriptLoaderProd, typescriptLoaderDev } from '../../scripts/rspack-common.js';
910

11+
const require = createRequire(import.meta.url);
12+
1013
const __filename = fileURLToPath(import.meta.url);
1114
const __dirname = path.dirname(__filename);
1215

@@ -15,10 +18,12 @@ const isDevelopment = mode => !isProduction(mode);
1518

1619
const variants = {
1720
uiBrowser: 'ui.browser',
21+
uiLegacyBrowser: 'ui.legacy.browser',
1822
};
1923

2024
const variantToSourceFile = {
2125
[variants.uiBrowser]: './src/index.browser.ts',
26+
[variants.uiLegacyBrowser]: './src/index.legacy.browser.ts',
2227
};
2328

2429
/**
@@ -126,9 +131,12 @@ const entryForVariant = variant => {
126131

127132
/**
128133
* Common production configuration for chunked browser builds
134+
* @param {object} [options]
135+
* @param {string} [options.targets] - Browserslist targets
136+
* @param {boolean} [options.useCoreJs] - Whether to use core-js polyfills
129137
* @returns {import('@rspack/core').Configuration}
130138
*/
131-
const commonForProdBrowser = () => {
139+
const commonForProdBrowser = ({ targets = 'last 2 years', useCoreJs = false } = {}) => {
132140
return {
133141
devtool: false,
134142
output: {
@@ -138,7 +146,7 @@ const commonForProdBrowser = () => {
138146
globalObject: 'globalThis',
139147
},
140148
module: {
141-
rules: [svgLoader(), ...typescriptLoaderProd({ targets: 'last 2 years' })],
149+
rules: [svgLoader(), ...typescriptLoaderProd({ targets, useCoreJs })],
142150
},
143151
optimization: {
144152
minimize: true,
@@ -157,13 +165,22 @@ const commonForProdBrowser = () => {
157165
}),
158166
],
159167
},
168+
...(useCoreJs
169+
? {
170+
resolve: {
171+
alias: {
172+
'core-js': path.dirname(require.resolve('core-js/package.json')),
173+
},
174+
},
175+
}
176+
: {}),
160177
};
161178
};
162179

163180
/**
164-
* Production configuration - builds UMD browser variant only
181+
* Production configuration - builds UMD browser variants
165182
* @param {'development'|'production'} mode
166-
* @returns {import('@rspack/core').Configuration}
183+
* @returns {import('@rspack/core').Configuration[]}
167184
*/
168185
const prodConfig = mode => {
169186
// Browser bundle with chunks (UMD)
@@ -173,7 +190,14 @@ const prodConfig = mode => {
173190
commonForProdBrowser(),
174191
);
175192

176-
return uiBrowser;
193+
// Legacy browser bundle with chunks (UMD) for Safari 12 support
194+
const uiLegacyBrowser = merge(
195+
entryForVariant(variants.uiLegacyBrowser),
196+
common({ mode, variant: variants.uiLegacyBrowser }),
197+
commonForProdBrowser({ targets: packageJSON.browserslistLegacy, useCoreJs: true }),
198+
);
199+
200+
return [uiBrowser, uiLegacyBrowser];
177201
};
178202

179203
/**
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// It's crucial this is the first import,
2+
// otherwise chunk loading will not work
3+
// eslint-disable-next-line
4+
import './utils/setWebpackChunkPublicPath';
5+
6+
import { ClerkUi } from './ClerkUi';
7+
8+
if (!window.__internal_ClerkUiCtor) {
9+
window.__internal_ClerkUiCtor = ClerkUi;
10+
}
11+
12+
// Hot module replacement for development
13+
if (module.hot) {
14+
module.hot.accept();
15+
}

pnpm-lock.yaml

Lines changed: 18 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ catalogs:
1111
react: 18.3.1
1212
react-dom: 18.3.1
1313
repo:
14-
tslib: 2.8.1
14+
'@swc/helpers': 0.5.17
15+
core-js: 3.47.0
16+
rolldown: 1.0.0-beta.47
1517
tsdown: 0.15.7
18+
tslib: 2.8.1
1619
tsup: 8.5.0
1720
typescript: 5.8.3
18-
zx: 8.8.5
19-
rolldown: 1.0.0-beta.47
2021
vue: 3.5.24
22+
zx: 8.8.5
2123
module-manager:
2224
'@base-org/account': 2.0.1
2325
'@coinbase/wallet-sdk': 4.3.0

0 commit comments

Comments
 (0)