Skip to content

Commit cc2b828

Browse files
authored
fix(shared): use @clerk/ui package version for UI script URL (#7418)
1 parent 7b7c90f commit cc2b828

File tree

5 files changed

+26
-5
lines changed

5 files changed

+26
-5
lines changed

packages/shared/global.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
declare const PACKAGE_NAME: string;
22
declare const PACKAGE_VERSION: string;
33
declare const JS_PACKAGE_VERSION: string;
4+
declare const UI_PACKAGE_VERSION: string;
45
declare const __DEV__: boolean;
56
declare const __BUILD_DISABLE_RHC__: boolean;
67
declare const __CLERK_USE_RQ__: boolean;

packages/shared/src/__tests__/loadClerkJsScript.spec.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ vi.mock('../loadScript');
1919

2020
setClerkJsLoadingErrorPackageName('@clerk/react');
2121
const jsPackageMajorVersion = getMajorVersion(JS_PACKAGE_VERSION);
22+
const uiPackageMajorVersion = getMajorVersion(UI_PACKAGE_VERSION);
2223

2324
const mockClerk = {
2425
status: 'ready',
@@ -318,7 +319,7 @@ describe('loadClerkUiScript(options)', () => {
318319
expect(result).toBeNull();
319320
expect(loadScript).toHaveBeenCalledWith(
320321
expect.stringContaining(
321-
`https://foo-bar-13.clerk.accounts.dev/npm/@clerk/ui@${jsPackageMajorVersion}/dist/ui.browser.js`,
322+
`https://foo-bar-13.clerk.accounts.dev/npm/@clerk/ui@${uiPackageMajorVersion}/dist/ui.browser.js`,
322323
),
323324
expect.objectContaining({
324325
async: true,
@@ -401,13 +402,13 @@ describe('clerkUiScriptUrl()', () => {
401402
test('constructs URL correctly for development key', () => {
402403
const result = clerkUiScriptUrl({ publishableKey: mockDevPublishableKey });
403404
expect(result).toBe(
404-
`https://foo-bar-13.clerk.accounts.dev/npm/@clerk/ui@${jsPackageMajorVersion}/dist/ui.browser.js`,
405+
`https://foo-bar-13.clerk.accounts.dev/npm/@clerk/ui@${uiPackageMajorVersion}/dist/ui.browser.js`,
405406
);
406407
});
407408

408409
test('constructs URL correctly for production key', () => {
409410
const result = clerkUiScriptUrl({ publishableKey: mockProdPublishableKey });
410-
expect(result).toBe(`https://example.clerk.com/npm/@clerk/ui@${jsPackageMajorVersion}/dist/ui.browser.js`);
411+
expect(result).toBe(`https://example.clerk.com/npm/@clerk/ui@${uiPackageMajorVersion}/dist/ui.browser.js`);
411412
});
412413

413414
test('uses provided clerkUiVersion', () => {
@@ -418,7 +419,23 @@ describe('clerkUiScriptUrl()', () => {
418419
test('uses latest as default version when not specified', () => {
419420
const result = clerkUiScriptUrl({ publishableKey: mockDevPublishableKey });
420421
// When no version is specified, versionSelector should return the major version
421-
expect(result).toContain(`/npm/@clerk/ui@${jsPackageMajorVersion}/`);
422+
expect(result).toContain(`/npm/@clerk/ui@${uiPackageMajorVersion}/`);
423+
});
424+
425+
test('uses UI_PACKAGE_VERSION independently from JS_PACKAGE_VERSION', () => {
426+
// Verify that clerkUiScriptUrl uses UI_PACKAGE_VERSION, not JS_PACKAGE_VERSION
427+
const uiResult = clerkUiScriptUrl({ publishableKey: mockDevPublishableKey });
428+
const jsResult = clerkJsScriptUrl({ publishableKey: mockDevPublishableKey });
429+
430+
// UI script should use UI package version
431+
expect(uiResult).toContain(`/npm/@clerk/ui@${uiPackageMajorVersion}/`);
432+
// JS script should use JS package version
433+
expect(jsResult).toContain(`/npm/@clerk/clerk-js@${jsPackageMajorVersion}/`);
434+
435+
// They should be using their respective versions (which may differ)
436+
// This test ensures we don't accidentally use JS version for UI
437+
expect(uiResult).not.toContain('@clerk/clerk-js');
438+
expect(jsResult).not.toContain('@clerk/ui');
422439
});
423440
});
424441

packages/shared/src/loadClerkJsScript.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ export const clerkUiScriptUrl = (opts: LoadClerkUiScriptOptions) => {
236236
}
237237

238238
const scriptHost = buildScriptHost({ publishableKey, proxyUrl, domain });
239-
const version = versionSelector(clerkUiVersion);
239+
const version = versionSelector(clerkUiVersion, UI_PACKAGE_VERSION);
240240
return `https://${scriptHost}/npm/@clerk/ui@${version}/dist/ui.browser.js`;
241241
};
242242

packages/shared/tsdown.config.mts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { Options } from 'tsdown';
55
import { defineConfig } from 'tsdown';
66

77
import clerkJsPackage from '../clerk-js/package.json' with { type: 'json' };
8+
import clerkUiPackage from '../ui/package.json' with { type: 'json' };
89
import sharedPackage from './package.json' with { type: 'json' };
910

1011
export default defineConfig(({ watch }) => {
@@ -21,6 +22,7 @@ export default defineConfig(({ watch }) => {
2122
PACKAGE_NAME: `"${sharedPackage.name}"`,
2223
PACKAGE_VERSION: `"${sharedPackage.version}"`,
2324
JS_PACKAGE_VERSION: `"${clerkJsPackage.version}"`,
25+
UI_PACKAGE_VERSION: `"${clerkUiPackage.version}"`,
2426
__DEV__: `${watch}`,
2527
__BUILD_DISABLE_RHC__: JSON.stringify(false),
2628
__CLERK_USE_RQ__: `${process.env.CLERK_USE_RQ === 'true'}`,

packages/shared/vitest.setup.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ globalThis.__DEV__ = true;
77
globalThis.PACKAGE_NAME = '@clerk/react';
88
globalThis.PACKAGE_VERSION = '0.0.0-test';
99
globalThis.JS_PACKAGE_VERSION = '5.0.0';
10+
globalThis.UI_PACKAGE_VERSION = '1.0.0';
1011
globalThis.__CLERK_USE_RQ__ = process.env.CLERK_USE_RQ === 'true';
1112

1213
// Setup Web Crypto API for tests (Node.js 18+ compatibility)

0 commit comments

Comments
 (0)