Skip to content

Commit 7e46402

Browse files
fix(clerk-js): Restore backwards compat for legacy clerkUICtor option (#7802)
Co-authored-by: Nikos Douvlis <nikosdouvlis@gmail.com>
1 parent 8969fa0 commit 7e46402

4 files changed

Lines changed: 41 additions & 1 deletion

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/clerk-js': patch
3+
---
4+
5+
Fix backwards compatibility for legacy `clerkUICtor` option removed in the `ui` prop PR

packages/clerk-js/bundlewatch.config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"files": [
3-
{ "path": "./dist/clerk.js", "maxSize": "538KB" },
3+
{ "path": "./dist/clerk.js", "maxSize": "539KB" },
44
{ "path": "./dist/clerk.browser.js", "maxSize": "66KB" },
55
{ "path": "./dist/clerk.chips.browser.js", "maxSize": "66KB" },
66
{ "path": "./dist/clerk.legacy.browser.js", "maxSize": "106KB" },

packages/clerk-js/src/core/__tests__/clerk.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2830,5 +2830,31 @@ describe('Clerk singleton', () => {
28302830

28312831
expect(mockClerkUICtor).toHaveBeenCalled();
28322832
});
2833+
2834+
it('supports legacy clerkUICtor option for backwards compatibility', async () => {
2835+
const mockClerkUIInstance = { mount: vi.fn() };
2836+
const mockClerkUICtor = vi.fn(() => mockClerkUIInstance);
2837+
2838+
const sut = new Clerk(productionPublishableKey);
2839+
await sut.load({
2840+
...mockedLoadOptions,
2841+
clerkUICtor: mockClerkUICtor,
2842+
} as any);
2843+
2844+
expect(mockClerkUICtor).toHaveBeenCalled();
2845+
});
2846+
2847+
it('supports legacy clerkUiCtor option for backwards compatibility', async () => {
2848+
const mockClerkUIInstance = { mount: vi.fn() };
2849+
const mockClerkUICtor = vi.fn(() => mockClerkUIInstance);
2850+
2851+
const sut = new Clerk(productionPublishableKey);
2852+
await sut.load({
2853+
...mockedLoadOptions,
2854+
clerkUiCtor: mockClerkUICtor,
2855+
} as any);
2856+
2857+
expect(mockClerkUICtor).toHaveBeenCalled();
2858+
});
28332859
});
28342860
});

packages/clerk-js/src/core/clerk.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3277,9 +3277,18 @@ export class Clerk implements ClerkInterface {
32773277
};
32783278

32793279
#initOptions = (options?: ClerkOptions): ClerkOptions => {
3280+
// Support legacy clerkUICtor / clerkUiCtor options from older SDK versions.
3281+
// Convert to the new ui.ClerkUI format so the rest of the codebase only checks one path.
3282+
const legacy = options as Record<string, unknown> | undefined;
3283+
const legacyCtor = legacy?.clerkUICtor ?? legacy?.clerkUiCtor;
3284+
const ui = legacyCtor
3285+
? { ...options?.ui, ClerkUI: legacyCtor as NonNullable<ClerkOptions['ui']>['ClerkUI'] }
3286+
: options?.ui;
3287+
32803288
return {
32813289
...defaultOptions,
32823290
...options,
3291+
ui,
32833292
allowedRedirectOrigins: createAllowedRedirectOrigins(
32843293
options?.allowedRedirectOrigins,
32853294
this.frontendApi,

0 commit comments

Comments
 (0)