Skip to content

Commit 6d1abce

Browse files
committed
fix: Refined fix
1 parent 55641a5 commit 6d1abce

2 files changed

Lines changed: 36 additions & 2 deletions

File tree

packages/react/src/__tests__/isomorphicClerk.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,5 +252,37 @@ describe('isomorphicClerk', () => {
252252
// Should not attempt to load UI from CDN
253253
expect(loadClerkUIScript).not.toHaveBeenCalled();
254254
});
255+
256+
it('passes ui.ClerkUI to clerk.load even when standardBrowser is false', async () => {
257+
const mockClerkUI = vi.fn();
258+
const mockLoad = vi.fn().mockResolvedValue(undefined);
259+
const mockClerkInstance = {
260+
load: mockLoad,
261+
loaded: false,
262+
};
263+
264+
// Simulate chrome-extension with syncHost: Clerk instance + ui prop + standardBrowser: false
265+
const clerk = new IsomorphicClerk({
266+
publishableKey: 'pk_test_XXX',
267+
Clerk: mockClerkInstance as any,
268+
ui: { ClerkUI: mockClerkUI } as any,
269+
standardBrowser: false,
270+
});
271+
272+
(global as any).Clerk = mockClerkInstance;
273+
274+
await (clerk as any).getEntryChunks();
275+
276+
// clerk.load should have been called with ui.ClerkUI preserved
277+
expect(mockLoad).toHaveBeenCalledWith(
278+
expect.objectContaining({
279+
ui: expect.objectContaining({
280+
ClerkUI: mockClerkUI,
281+
}),
282+
}),
283+
);
284+
// Should not attempt to load UI from CDN
285+
expect(loadClerkUIScript).not.toHaveBeenCalled();
286+
});
255287
});
256288
});

packages/react/src/isomorphicClerk.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,9 +472,11 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk {
472472

473473
if (!clerk.loaded) {
474474
this.beforeLoad(clerk);
475-
// Load UI in standard browser environments, or when a bundled ClerkUI is provided via the ui prop
475+
// Load UI when:
476+
// - standard browser and no pre-created Clerk instance (normal CDN path), OR
477+
// - a bundled ClerkUI was provided via the ui prop (e.g. chrome-extension, even with standardBrowser: false)
476478
const shouldLoadUi =
477-
this.options.standardBrowser !== false && (!this.options.Clerk || this.options.ui?.ClerkUI);
479+
(this.options.standardBrowser !== false && !this.options.Clerk) || !!this.options.ui?.ClerkUI;
478480
const ClerkUI = shouldLoadUi ? await this.getClerkUIEntryChunk() : undefined;
479481
await clerk.load({ ...this.options, ui: { ...this.options.ui, ClerkUI } });
480482
}

0 commit comments

Comments
 (0)