Skip to content

feat(clerk-react,clerk-js, types,shared): Introduce Clerk.status #5476

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

Conversation

panteliselef
Copy link
Member

@panteliselef panteliselef commented Mar 28, 2025

Description

Introduce useClerk().status, Clerk.status alongside <ClerkFailed/> and <ClerkDegraded/>.

useClerk().status

Possible values are:

  • loading (initial state)
  • error set when hotloading clerk-js failed or Clerk.load() failed
  • ready set when Clerk is fully operational
  • degraded set when Clerk is partially operational

useClerk().loaded is true when useClerk().status is either "ready" or "degraded".
useClerk().loaded is false when useClerk().status is "loading" or "error".

Important

🚨🚨 Clerk.status becomes loading upon instantiation not upon calling .load()

New APIs

const handler = (status)=> {}
window.Clerk.on('status', handler)
window.Clerk.off('status', handler)

on()

Calls handler on every status event with the new status as parameter

window.Clerk.on('status',(status)=>{})

Calls handler immediately with the last payload of the event.

window.Clerk.on('status',(status)=>{}, {notify:true})

off()

Accepts a handler to unregister from the specified event.

window.Clerk.off('status',handler)

Removes all handlers for the specified event.

window.Clerk.off('status')

New Components

<ClerkFailed/>

<ClerkLoaded>
  <MyCustomSignInForm/>
</ClerkLoaded>
<ClerkFailed>
  <ContactSupportBanner/>
</ClerkFailed>

<ClerkDegraded/>

<ClerkLoaded>
  <MyCustomPasskeyRegistration/>
  <ClerkDegraded>
    We are experiencing issues, registering a passkey might fail. 
  </ClerkDegraded>
</ClerkLoaded>

Clerk.status values

image

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Copy link

vercel bot commented Mar 28, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
clerk-js-sandbox ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 18, 2025 0:08am

…clerk-has-failed-to-load-from

# Conflicts:
#	packages/react/src/isomorphicClerk.ts
Copy link

changeset-bot bot commented Mar 31, 2025

🦋 Changeset detected

Latest commit: b04005d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 22 packages
Name Type
@clerk/nextjs Minor
@clerk/clerk-react Minor
@clerk/clerk-js Minor
@clerk/types Minor
@clerk/chrome-extension Patch
@clerk/elements Patch
@clerk/clerk-expo Patch
@clerk/react-router Patch
@clerk/remix Patch
@clerk/tanstack-react-start Patch
@clerk/agent-toolkit Patch
@clerk/astro Patch
@clerk/backend Patch
@clerk/expo-passkeys Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/localizations Patch
@clerk/nuxt Patch
@clerk/shared Patch
@clerk/testing Patch
@clerk/themes Patch
@clerk/vue Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

The inline script might fail before the event listeners are attached which causes an infinite pending state. Instead, we would like to retry fetching the script and/or throw an error.
This reverts commit 129d423.
…clerk-has-failed-to-load-from

# Conflicts:
#	packages/clerk-js/src/core/auth/AuthCookieService.ts
…clerk-has-failed-to-load-from

# Conflicts:
#	packages/clerk-js/bundlewatch.config.json
@jacekradko
Copy link
Member

!snapshot

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new status tracking property for Clerk, allowing developers to distinguish between different operational states ("loading", "error", "ready", and "degraded"). It updates the core Clerk implementation, React hooks, context providers, and UI components to leverage the new Clerk.status and adjust the computed loaded flag accordingly.

  • Adds a new Clerk.status property with corresponding event handling.
  • Refactors many loading checks across the SDK to use Clerk.status.
  • Introduces new React components ( and ) and updates tests/documentation to support the new status logic.

Reviewed Changes

Copilot reviewed 20 out of 24 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/react/src/isomorphicClerk.ts Introduces Clerk.status, replaces internal loaded checks
packages/react/src/hooks/utils.ts Updates event listener to use Clerk.status
packages/react/src/contexts/ClerkContextProvider.tsx Refactors context to derive state from Clerk.status
packages/react/src/components/* Adjusts control components to render based on the new status
packages/nextjs/* Updates Next.js integrations similarly
packages/clerk-js/src/core/* Revises the core Clerk logic and error handling to emit proper status
integration/tests/* Adds tests to verify correct status transitions
.changeset/* Updates changesets to document the new status feature
Files not reviewed (4)
  • .typedoc/tests/snapshots/file-structure.test.ts.snap: Language not supported
  • packages/chrome-extension/src/tests/snapshots/exports.test.ts.snap: Language not supported
  • packages/clerk-js/bundlewatch.config.json: Language not supported
  • packages/react-router/src/tests/snapshots/exports.test.ts.snap: Language not supported

…clerk-has-failed-to-load-from

# Conflicts:
#	integration/testUtils/index.ts
@panteliselef panteliselef merged commit 4334598 into main Apr 18, 2025
30 checks passed
@panteliselef panteliselef deleted the elef/sdki-730-introduce-way-to-determine-if-clerk-has-failed-to-load-from branch April 18, 2025 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants