Skip to content

Commit ac04f66

Browse files
author
Jacek
committed
fix(clerk-js,ui): Add preloadHint to open* methods and catch preload errors
1 parent 77ded72 commit ac04f66

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,9 @@ export class Clerk implements ClerkInterface {
691691
}
692692
this.assertComponentsReady(this.#clerkUI);
693693
const component = 'SignIn';
694-
void this.#clerkUI.then(ui => ui.ensureMounted()).then(controls => controls.openModal('signIn', props || {}));
694+
void this.#clerkUI
695+
.then(ui => ui.ensureMounted({ preloadHint: component }))
696+
.then(controls => controls.openModal('signIn', props || {}));
695697

696698
const additionalData = { withSignUp: props?.withSignUp ?? this.#isCombinedSignInOrUpFlow() };
697699
this.telemetry?.record(eventPrebuiltComponentOpened(component, props, additionalData));
@@ -865,7 +867,9 @@ export class Clerk implements ClerkInterface {
865867
return;
866868
}
867869
this.assertComponentsReady(this.#clerkUI);
868-
void this.#clerkUI.then(ui => ui.ensureMounted()).then(controls => controls.openModal('signUp', props || {}));
870+
void this.#clerkUI
871+
.then(ui => ui.ensureMounted({ preloadHint: 'SignUp' }))
872+
.then(controls => controls.openModal('signUp', props || {}));
869873

870874
this.telemetry?.record(eventPrebuiltComponentOpened('SignUp', props));
871875
};
@@ -884,7 +888,9 @@ export class Clerk implements ClerkInterface {
884888
return;
885889
}
886890
this.assertComponentsReady(this.#clerkUI);
887-
void this.#clerkUI.then(ui => ui.ensureMounted()).then(controls => controls.openModal('userProfile', props || {}));
891+
void this.#clerkUI
892+
.then(ui => ui.ensureMounted({ preloadHint: 'UserProfile' }))
893+
.then(controls => controls.openModal('userProfile', props || {}));
888894

889895
const additionalData = (props?.customPages?.length || 0) > 0 ? { customPages: true } : undefined;
890896
this.telemetry?.record(eventPrebuiltComponentOpened('UserProfile', props, additionalData));
@@ -920,7 +926,7 @@ export class Clerk implements ClerkInterface {
920926

921927
this.assertComponentsReady(this.#clerkUI);
922928
void this.#clerkUI
923-
.then(ui => ui.ensureMounted())
929+
.then(ui => ui.ensureMounted({ preloadHint: 'OrganizationProfile' }))
924930
.then(controls => controls.openModal('organizationProfile', props || {}));
925931

926932
this.telemetry?.record(eventPrebuiltComponentOpened('OrganizationProfile', props));
@@ -947,7 +953,7 @@ export class Clerk implements ClerkInterface {
947953

948954
this.assertComponentsReady(this.#clerkUI);
949955
void this.#clerkUI
950-
.then(ui => ui.ensureMounted())
956+
.then(ui => ui.ensureMounted({ preloadHint: 'CreateOrganization' }))
951957
.then(controls => controls.openModal('createOrganization', props || {}));
952958

953959
this.telemetry?.record(eventPrebuiltComponentOpened('CreateOrganization', props));
@@ -959,7 +965,9 @@ export class Clerk implements ClerkInterface {
959965

960966
public openWaitlist = (props?: WaitlistProps): void => {
961967
this.assertComponentsReady(this.#clerkUI);
962-
void this.#clerkUI.then(ui => ui.ensureMounted()).then(controls => controls.openModal('waitlist', props || {}));
968+
void this.#clerkUI
969+
.then(ui => ui.ensureMounted({ preloadHint: 'Waitlist' }))
970+
.then(controls => controls.openModal('waitlist', props || {}));
963971

964972
this.telemetry?.record(eventPrebuiltComponentOpened('Waitlist', props));
965973
};

‎packages/ui/src/Components.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ export const mountComponentRenderer = (
224224
// Always preload, even if ensureMounted was already called.
225225
// preloadComponent is idempotent (returns cached promise on subsequent calls).
226226
if (preloadHint) {
227-
void preloadComponent(preloadHint);
227+
void preloadComponent(preloadHint).catch(() => {});
228228
}
229229
// This mechanism ensures that mountComponentControls will only be called once
230230
// and any calls to .mount before mountComponentControls resolves will fire in order.

0 commit comments

Comments
 (0)