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

Offen
#10,538 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
57/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Aktiv
Bereich
authentication

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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
Vorherrschende Sprache
TypeScript
Sterne
1.8k
Forks
492
Ø Merge
1 T. 8 Std.
Gemergte PRs (30 T.)
374

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus clerk/javascript

Alle Issues in clerk/javascript

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.