Skip to content
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

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

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/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`
2 changes: 1 addition & 1 deletion integration/testUtils/appPageObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const createAppPageObject = (testArgs: { page: Page }, app: Application)
waitForClerkJsLoaded: async () => {
return page.waitForFunction(() => {
// @ts-ignore
return window.Clerk?.isReady();
return window.Clerk?.loaded;
});
},
waitForClerkComponentMounted: async () => {
Expand Down
19 changes: 11 additions & 8 deletions packages/clerk-js/src/core/clerk.ts
Original file line number Diff line number Diff line change
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
1 change: 1 addition & 0 deletions packages/types/src/clerk.ts
Original file line number Diff line number Diff line change
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
Loading