clerk-js ignores new `ClerkProvider` options after the first load, so `afterSignOutUrl` keeps its first value

Ouverte
#10,538 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é
4/5
Temps estimé
3-5 jours
Accessibilité débutants
57/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
Active
Stack technique
next.js, react, typescript
Domaine
authentication

Piste de recherche

Start with packages/clerk-js/src/core/clerk.ts and the __internal_updateProps and URL-builder methods; then read the options-update effect in packages/react/src/contexts/ClerkProvider.tsx. Run the linked reproduction using its listed setup steps and compare the sign-out destination before and after navigating from /en to /sk. Done means the updated provider options are respected in both the changing-provider and mounted-provider cases.

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

Description

needs-triage
Preliminary Checks
Reproduction

https://github.com/Joozty/clerk-nextjs-activity-repro

Publishable key

Not shared. The reproduction works with any development instance: put your own key in .env.local (see .env.example).

Description

clerk-js keeps the options from its first load(). If a prop of <ClerkProvider> changes later, clerk-js ignores the new value. For example, an app with two languages passes afterSignOutUrl="/en" or afterSignOutUrl="/sk". A user opens /en, clicks a link to /sk, and signs out. Clerk sends the user to /en, not to /sk.

This happens with or without cacheComponents. #5935 had the same cause for signInUrl. Its author closed it without a fix, and it is now locked.

Steps to reproduce:

  1. Clone the reproduction and run pnpm install.
  2. Copy .env.example to .env.local. Set the publishable key of your own development instance there.
  3. Run pnpm dev and open http://localhost:3000/en.
  4. Click the /sk link. The layout now renders <ClerkProvider afterSignOutUrl="/sk">.
  5. Click Read Clerk.buildAfterSignOutUrl().

Expected behavior:

http://localhost:3000/sk.

Actual behavior:

http://localhost:3000/en. <UserButton> signs out to the URL from clerk.buildAfterSignOutUrl() (see packages/ui/src/contexts/components/UserButton.ts). I tested this with a real account: after I click /sk and sign out, I land on /en.

Why it happens:

  • When you click /sk, the new ClerkProvider sends its options to clerk-js. Its effect calls __internal_updateProps({ options }), and the options include afterSignOutUrl: "/sk". I checked this in the browser.
  • Clerk.__internal_updateProps() in packages/clerk-js/src/core/clerk.ts merges the new options with this.#options. But it gives the result only to Clerk's UI. It never saves it in this.#options. Only load() sets this.#options.
  • buildAfterSignOutUrl(), buildSignInUrl(), buildSignUpUrl(), buildAfterSignInUrl() and buildAfterSignUpUrl() read this.#options. So they keep the first values.
  • There is a second, smaller problem in @clerk/react. The effect in packages/react/src/contexts/ClerkProvider.tsx that calls __internal_updateProps({ options }) depends only on [mergedOptions.localization]. So if one ClerkProvider stays mounted and only afterSignOutUrl changes, the new value is not even sent.

#4498 added the merge in __internal_updateProps. Its changeset says "Re-init window.Clerk options when ClerkProvider props change", but the code only gives the merged options to the UI.

Possible fix:

  1. In __internal_updateProps, save the merged options in this.#options. This alone should fix the reproduction.
  2. In @clerk/react, send the options again when any option changes, not only localization. This is for apps where one ClerkProvider stays mounted.

Workaround: custom code can call signOut({ redirectUrl }). But <UserButton> has no prop for the sign-out URL. By default, clerk-js loads from the Frontend API, not from node_modules, so a pnpm patch in the app can't fix it.

Related:

  • #372 added the @clerk/react effect that sends options only when localization changes.
  • #3455 also merged the options of a new ClerkProvider only into the UI state.
  • #7243 removed <UserButton afterSignOutUrl> in Core 3, so <UserButton> has no prop for the sign-out URL.
Environment
System:
    OS: macOS 27.2
    CPU: (10) arm64 Apple M4
    Memory: 73.23 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 24.15.0 - /Users/jozef/.volta/tools/image/node/24.15.0/bin/node
    npm: 11.12.1 - /Users/jozef/.volta/tools/image/node/24.15.0/bin/npm
    pnpm: 12.4.1 - /Users/jozef/.volta/bin/pnpm
  Browsers:
    Chrome: 156.0.8078.48
    Firefox: 159.0
    Safari: 27.2
  npmPackages:
    @clerk/nextjs: 7.9.22 => 7.9.22
    next: 16.4.3 => 16.4.3
    react: 19.3.0 => 19.3.0
    react-dom: 19.3.0 => 19.3.0
  Loaded from the Frontend API:
    @clerk/clerk-js: 6.41.0 (6.42.0 and main have the same code)
    @clerk/ui: 1.42.0
Langage dominant
TypeScript
Étoiles
1.8k
Forks
492
Merge moyen
1 j 8 h
PR mergées (30 j)
374

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.