Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tricky-apples-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
***

## '@clerk/react': minor
Comment thread
royanger marked this conversation as resolved.
Outdated

The `ui` prop is now respected if a Clerk instance is passed via the `Clerk` prop to `IsomorphicClerk`. This fixes the 'Clerk was not loaded with Ui components' error in the Chrome Extension SDK.
53 changes: 53 additions & 0 deletions packages/react/src/__tests__/isomorphicClerk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,57 @@ describe('isomorphicClerk', () => {
expect(result).toBe(mockClerkUI);
});
});

describe('ui.ClerkUI with pre-created Clerk instance', () => {
it('passes ui.ClerkUI to clerk.load when Clerk instance is provided', async () => {
const mockClerkUI = vi.fn();
const mockLoad = vi.fn().mockResolvedValue(undefined);
const mockClerkInstance = {
load: mockLoad,
loaded: false,
};

// Simulate the chrome-extension flow: pre-created Clerk instance + ui prop
const clerk = new IsomorphicClerk({
publishableKey: 'pk_test_XXX',
Clerk: mockClerkInstance as any,
ui: { ClerkUI: mockClerkUI } as any,
});

// Set the global Clerk so getClerkJsEntryChunk resolves
(global as any).Clerk = mockClerkInstance;

await (clerk as any).getEntryChunks();

// clerk.load should have been called with ui.ClerkUI preserved
expect(mockLoad).toHaveBeenCalledWith(
expect.objectContaining({
ui: expect.objectContaining({
ClerkUI: mockClerkUI,
}),
}),
);
});

it('does not load UI scripts from CDN when Clerk instance is provided', async () => {
const mockClerkUI = vi.fn();
const mockClerkInstance = {
load: vi.fn().mockResolvedValue(undefined),
loaded: false,
};

const clerk = new IsomorphicClerk({
publishableKey: 'pk_test_XXX',
Clerk: mockClerkInstance as any,
ui: { ClerkUI: mockClerkUI } as any,
});

(global as any).Clerk = mockClerkInstance;

await (clerk as any).getEntryChunks();

// Should not attempt to load UI from CDN
expect(loadClerkUIScript).not.toHaveBeenCalled();
});
});
});
2 changes: 1 addition & 1 deletion packages/react/src/isomorphicClerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk {
this.beforeLoad(clerk);
// Only load UI scripts in standard browser environments (not native/headless)
const shouldLoadUi = !this.options.Clerk && this.options.standardBrowser !== false;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do you think shouldLoadUi should be false if this.options.ui?.ClerkUI exists? or is that already handled elsewhere?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Nope. I was mostly starting with a draft PR so I could get snapshots, since this issue wasn't showing up in local testing. The updated change in 2dc46ff should be a better approach, but I still need to test it.

const ClerkUI = shouldLoadUi ? await this.getClerkUIEntryChunk() : undefined;
const ClerkUI = shouldLoadUi ? await this.getClerkUIEntryChunk() : this.options.ui?.ClerkUI;
await clerk.load({ ...this.options, ui: { ...this.options.ui, ClerkUI } });
}
if (clerk.loaded) {
Expand Down
Loading
Loading