Skip to content

chore(types,clerk-js,clerk-react): Drop Clerk.isReady() in favor of Clerk.loaded #2294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 8, 2023
Merged
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
7 changes: 7 additions & 0 deletions .changeset/khaki-buttons-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@clerk/clerk-js': major
'@clerk/clerk-react': major
'@clerk/types': major
---

Drop `Clerk.isReady(). Use `Clerk.loaded` instead.`
2 changes: 1 addition & 1 deletion integration/testUtils/appPageObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const createAppPageObject = (testArgs: { page: Page }, app: Application)
},
waitForClerkJsLoaded: async () => {
return page.waitForFunction(() => {
return window.Clerk?.isReady();
return window.Clerk?.loaded;
});
},
waitForClerkComponentMounted: async () => {
Expand Down
16 changes: 7 additions & 9 deletions packages/clerk-js/src/core/clerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export class Clerk implements ClerkInterface {
//@ts-expect-error with being undefined even though it's not possible - related to issue with ts and error thrower
#fapiClient: FapiClient;
#instanceType?: InstanceType;
#isReady = false;
#loaded = false;

#listeners: Array<(emission: Resources) => void> = [];
#options: ClerkOptions = {};
Expand All @@ -189,7 +189,7 @@ export class Clerk implements ClerkInterface {
}

get loaded(): boolean {
return this.#isReady;
return this.#loaded;
}

get isSatellite(): boolean {
Expand Down Expand Up @@ -264,10 +264,8 @@ export class Clerk implements ClerkInterface {

public getFapiClient = (): FapiClient => this.#fapiClient;

public isReady = (): boolean => this.#isReady;

public load = async (options?: ClerkOptions): Promise<void> => {
if (this.#isReady) {
if (this.loaded) {
return;
}

Expand Down Expand Up @@ -295,9 +293,9 @@ export class Clerk implements ClerkInterface {
);

if (this.#options.standardBrowser) {
this.#isReady = await this.#loadInStandardBrowser();
this.#loaded = await this.#loadInStandardBrowser();
} else {
this.#isReady = await this.#loadInNonStandardBrowser();
this.#loaded = await this.#loadInNonStandardBrowser();
}
};

Expand Down Expand Up @@ -869,7 +867,7 @@ export class Clerk implements ClerkInterface {
params: HandleOAuthCallbackParams = {},
customNavigate?: (to: string) => Promise<unknown>,
): Promise<unknown> => {
if (!this.#isReady || !this.#environment || !this.client) {
if (!this.loaded || !this.#environment || !this.client) {
return;
}
const { signIn, signUp } = this.client;
Expand Down Expand Up @@ -1500,7 +1498,7 @@ export class Clerk implements ClerkInterface {
};

#buildUrl = (key: 'signInUrl' | 'signUpUrl', options?: SignInRedirectOptions | SignUpRedirectOptions): string => {
if (!this.#isReady || !this.#environment || !this.#environment.displayConfig) {
if (!this.loaded || !this.#environment || !this.#environment.displayConfig) {
return '';
}

Expand Down
6 changes: 2 additions & 4 deletions packages/react/src/isomorphicClerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,6 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk {
return false;
}

isReady = (): boolean => Boolean(this.clerkjs?.isReady());

buildSignInUrl = (opts?: RedirectOptions): string | void => {
const callback = () => this.clerkjs?.buildSignInUrl(opts) || '';
if (this.clerkjs && this.#loaded) {
Expand Down Expand Up @@ -363,7 +361,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk {
// Otherwise use the instantiated Clerk object
c = this.Clerk;

if (!c.isReady()) {
if (!c.loaded) {
await c.load(this.options);
}
}
Expand All @@ -387,7 +385,7 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk {
await global.Clerk.load(this.options);
}

if (global.Clerk?.loaded || global.Clerk?.isReady()) {
if (global.Clerk?.loaded) {
return this.hydrateClerkJS(global.Clerk);
}
return;
Expand Down
5 changes: 0 additions & 5 deletions packages/types/src/clerk.retheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,11 +424,6 @@ export interface Clerk {
* Handles a 401 response from Frontend API by refreshing the client and session object accordingly
*/
handleUnauthenticated: () => Promise<unknown>;

/**
* Returns true if bootstrapping with Clerk.load has completed successfully. Otherwise, returns false.
*/
isReady: () => boolean;
}

export type HandleOAuthCallbackParams = {
Expand Down
5 changes: 0 additions & 5 deletions packages/types/src/clerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,11 +424,6 @@ export interface Clerk {
* Handles a 401 response from Frontend API by refreshing the client and session object accordingly
*/
handleUnauthenticated: () => Promise<unknown>;

/**
* Returns true if bootstrapping with Clerk.load has completed successfully. Otherwise, returns false.
*/
isReady: () => boolean;
}

export type HandleOAuthCallbackParams = {
Expand Down