Skip to content
Open
Show file tree
Hide file tree
Changes from all 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/astro-log-load-errors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/astro': patch
---

Log `Clerk.load()` failures to the console instead of silently swallowing them, making component mount failures diagnosable.
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,33 @@ describe('getClerkUIEntryChunk', () => {
expect(loadCall.ui.ClerkUI).toBeUndefined();
});

it('logs load() rejections to the console and does not mount components', async () => {
const loadError = new Error('ClerkJS failed to load');
mockLoadClerkJSScript.mockImplementation(() => {
(window as any).Clerk = {
load: vi.fn().mockRejectedValue(loadError),
addListener: vi.fn(),
};
return Promise.resolve(null);
});
const consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});

const { createClerkInstance } = await import('../create-clerk-instance');
const { $csrState } = await import('../../stores/internal');
const { mountAllClerkAstroJSComponents } = await import('../mount-clerk-astro-js-components');

await createClerkInstance({
publishableKey: 'pk_test_xxx',
prefetchUI: false,
});

expect(consoleErrorSpy).toHaveBeenCalledWith(loadError.stack);
expect($csrState.setKey).not.toHaveBeenCalledWith('isLoaded', true);
expect(mountAllClerkAstroJSComponents).not.toHaveBeenCalled();

consoleErrorSpy.mockRestore();
});

it('does not pass a ClerkUI promise when ui is a marker object without a constructor', async () => {
const mockLoad = vi.fn().mockResolvedValue(undefined);

Expand Down
4 changes: 3 additions & 1 deletion packages/astro/src/internal/create-clerk-instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ async function createClerkInstanceInternal<TUi extends Ui = Ui>(options?: AstroC
$csrState.setKey('organization', payload.organization);
});
})
.catch(() => {});
.catch((err: Error) => {
console.error(err.stack || err.message || err);
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}

function updateClerkOptions<TUi extends Ui = Ui>(options: AstroClerkUpdateOptions<TUi>) {
Expand Down
Loading