Skip to content

Commit

Permalink
chore(types,clerk-js,clerk-react): Deprecate Clerk.isReady() in fav…
Browse files Browse the repository at this point in the history
…or of `Clerk.loaded`
  • Loading branch information
dimkl committed Dec 8, 2023
1 parent 11e61cc commit 80f55ac
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
7 changes: 7 additions & 0 deletions .changeset/six-carrots-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@clerk/clerk-js': minor
'@clerk/clerk-react': minor
'@clerk/types': minor
---

Deprecate `Clerk.isReady()` in favor of `Clerk.loaded`
21 changes: 12 additions & 9 deletions packages/clerk-js/src/core/clerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import type {
AuthenticateWithMetamaskParams,
BeforeEmitCallback,
BuildUrlWithAuthParams,
Clerk as ClerkInterface,
ClerkAPIError,
Clerk as ClerkInterface,
ClerkOptions,
ClientResource,
CreateOrganizationParams,
Expand Down Expand Up @@ -173,7 +173,7 @@ export default class Clerk implements ClerkInterface {
#environment?: EnvironmentResource | null;
#fapiClient: FapiClient;
#instanceType: InstanceType;
#isReady = false;
#loaded = false;

/**
* @deprecated Although this being a private field, this is a reminder to drop it with the next major release
Expand All @@ -200,7 +200,7 @@ export default class Clerk implements ClerkInterface {
}

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

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

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

public isReady = (): boolean => this.#isReady;
public isReady = (): boolean => {
deprecated('Clerk.isReady()', 'Use `Clerk.loaded` instead.');
return this.#loaded;
};

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

Expand All @@ -332,9 +335,9 @@ export default 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 @@ -949,7 +952,7 @@ export default 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 @@ -1619,7 +1622,7 @@ export default 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
4 changes: 2 additions & 2 deletions packages/react/src/isomorphicClerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ export default 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 @@ -390,7 +390,7 @@ export default class IsomorphicClerk implements IsomorphicLoadedClerk {

global.Clerk.sdkMetadata = this.options.sdkMetadata ?? { name: PACKAGE_NAME, version: PACKAGE_VERSION };

if (global.Clerk?.loaded || global.Clerk?.isReady()) {
if (global.Clerk?.loaded) {
return this.hydrateClerkJS(global.Clerk);
}
return;
Expand Down
3 changes: 2 additions & 1 deletion packages/types/src/clerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ export interface Clerk {
* {@link Clerk.client.signIn.authenticateWithRedirect} or {@link Clerk.client.signUp.authenticateWithRedirect}
*/
handleRedirectCallback: (
params: HandleOAuthCallbackParams | HandleSamlCallbackParams,
params: HandleOAuthCallbackParams,
customNavigate?: (to: string) => Promise<unknown>,
) => Promise<unknown>;

Expand Down Expand Up @@ -459,6 +459,7 @@ export interface Clerk {

/**
* Returns true if bootstrapping with Clerk.load has completed successfully. Otherwise, returns false.
* @deprecated Use `loaded` instead.
*/
isReady: () => boolean;
}
Expand Down

0 comments on commit 80f55ac

Please sign in to comment.