@clerk/react: with a preloaded Clerk instance, hooks are not loaded on the first render and <ClerkLoaded> never renders

Ouverte
#10,532 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
3/5
Temps estimé
1-2 jours
Accessibilité débutants
58/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
Active
Stack technique
react, typescript

Piste de recherche

Start by locating ClerkProvider, useAuth(), and ClerkLoaded in the React package, then trace how a preloaded Clerk instance initializes provider state and notifies subscribers. Reproduce with the listed package versions and the three steps in the issue. Done means the first render reflects the loaded instance and ClerkLoaded renders; the issue does not name a test file.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

Related: #8569 (a preloaded instance passed to <ClerkProvider Clerk={clerk}> skips the UI load). We work around that by passing the UI at our own clerk.load({ ui: { ClerkUI } }). That leaves this gap.

Problem

With a preloaded instance passed as <ClerkProvider Clerk={clerk}>:

  • On the first render, useAuth() returns isLoaded: false and useOrganization() has no membership, although the instance is already loaded. They become loaded one tick later, when the provider takes the instance over.
  • <ClerkLoaded> does not re-render when that happens, so it cannot be used to wait for it.

A page that reads the role on its first render (for example, an admin-only route on a full page load) sees "not an admin" and redirects away.

Repro

@clerk/clerk-js 6.42, @clerk/react 6.18, @clerk/ui 1.42.

  1. const clerk = new Clerk(pk); await clerk.load({ ui: { ClerkUI: ui.ClerkUI } }); before createRoot.
  2. Render <ClerkProvider Clerk={clerk}><Probe /></ClerkProvider>.
  3. In Probe, log useAuth().isLoaded: the first render logs false. Wrap Probe in <ClerkLoaded> and it never renders.

Proposal

With a loaded instance, the provider starts with isLoaded: true and the session, user and organization already set. Or <ClerkLoaded> re-renders when the provider becomes loaded.

Our workaround

One wrapper at the root renders the app only when useAuth().isLoaded is true.

(issue generated with AI assistance)

Langage dominant
TypeScript
Étoiles
1.8k
Forks
492
Merge moyen
1 j 7 h
PR mergées (30 j)
357

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de clerk/javascript

Toutes les issues de clerk/javascript

Issues similaires

Plus d'issues TypeScript

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.