@@ -250,12 +250,11 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk {
250250 }
251251
252252 constructor ( options : IsomorphicClerkOptions ) {
253- const { Clerk = null , publishableKey } = options || { } ;
254- this . #publishableKey = publishableKey ;
253+ this . #publishableKey = options ?. publishableKey ;
255254 this . #proxyUrl = options ?. proxyUrl ;
256255 this . #domain = options ?. domain ;
257256 this . options = options ;
258- this . Clerk = Clerk ;
257+ this . Clerk = options ?. Clerk || null ;
259258 this . mode = inBrowser ( ) ? 'browser' : 'server' ;
260259 this . #stateProxy = new StateProxy ( this ) ;
261260
@@ -266,7 +265,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk {
266265 this . #eventBus. prioritizedOn ( clerkEvents . Status , status => ( this . #status = status ) ) ;
267266
268267 if ( this . #publishableKey) {
269- void this . loadClerkEntryChunks ( ) ;
268+ void this . getEntryChunks ( ) ;
270269 }
271270 }
272271
@@ -436,7 +435,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk {
436435 } ) ;
437436 }
438437
439- async loadClerkEntryChunks ( ) : Promise < void > {
438+ async getEntryChunks ( ) : Promise < void > {
440439 if ( this . mode !== 'browser' || this . loaded ) {
441440 return ;
442441 }
@@ -456,10 +455,10 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk {
456455 }
457456
458457 try {
459- const clerkPromise = this . loadClerkJsEntryChunk ( ) ;
460- const clerkUiCtor = this . loadClerkUiEntryChunk ( ) ;
461- await clerkPromise ;
458+ const clerkPromise = this . getClerkJsEntryChunk ( ) ;
459+ const clerkUiCtor = this . getClerkUiEntryChunk ( ) ;
462460
461+ global . Clerk = await clerkPromise ;
463462 if ( ! global . Clerk ) {
464463 // TODO @nikos : somehow throw if clerk ui failed to load but it was not headless
465464 throw new Error ( 'Failed to download latest ClerkJS. Contact [email protected] .' ) ; @@ -480,9 +479,9 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk {
480479 }
481480 }
482481
483- private async loadClerkJsEntryChunk ( ) {
482+ private async getClerkJsEntryChunk ( ) : Promise < HeadlessBrowserClerk | BrowserClerk | undefined > {
484483 // Hotload bundle
485- if ( ! this . Clerk && ! __BUILD_DISABLE_RHC__ ) {
484+ if ( ! this . options . Clerk && ! __BUILD_DISABLE_RHC__ ) {
486485 // the UMD script sets the global.Clerk instance
487486 await loadClerkJsScript ( {
488487 ...this . options ,
@@ -494,25 +493,32 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk {
494493 }
495494
496495 // Otherwise, set global.Clerk to the bundled ctor or instance
497- if ( this . Clerk ) {
498- global . Clerk = isConstructor < BrowserClerkConstructor | HeadlessBrowserClerkConstructor > ( this . Clerk )
499- ? new this . Clerk ( this . #publishableKey, { proxyUrl : this . proxyUrl , domain : this . domain } )
500- : this . Clerk ;
496+ if ( this . options . Clerk ) {
497+ return isConstructor < BrowserClerkConstructor | HeadlessBrowserClerkConstructor > ( this . options . Clerk )
498+ ? new this . options . Clerk ( this . #publishableKey, { proxyUrl : this . proxyUrl , domain : this . domain } )
499+ : this . options . Clerk ;
501500 }
502- return global . Clerk ;
501+
502+ return ;
503503 }
504504
505- private async loadClerkUiEntryChunk ( ) {
505+ private async getClerkUiEntryChunk ( ) : Promise < ClerkUiConstructor > {
506+ if ( this . options . clerkUiCtor ) {
507+ return this . options . clerkUiCtor ;
508+ }
509+
506510 await loadClerkUiScript ( {
507511 ...this . options ,
508512 publishableKey : this . #publishableKey,
509513 proxyUrl : this . proxyUrl ,
510514 domain : this . domain ,
511515 nonce : this . options . nonce ,
512516 } ) ;
517+
513518 if ( ! global . __unstable_ClerkUiCtor ) {
514519 throw new Error ( 'Failed to download latest Clerk UI. Contact [email protected] .' ) ; 515520 }
521+
516522 return global . __unstable_ClerkUiCtor ;
517523 }
518524
0 commit comments