fix(react): attach UI for preloaded Clerk instances#8594
Conversation
🦋 Changeset detectedLatest commit: 0fdc348 The changes in this PR will be included in the next version bump. This PR includes changesets to release 7 packages
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 latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughThis PR fixes a bug where React applications that load Clerk outside the React provider (e.g., in client-side loaders) fail to mount UI components. The fix refactors Clerk.load() to support deferred UI initialization via a new Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/dev-cli
@clerk/expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/hono
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/react
@clerk/react-router
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/ui
@clerk/upgrade
@clerk/vue
commit: |
| const nextOptions = this.#initOptions({ ...this.#options, ...options }); | ||
| this.#options = nextOptions; |
There was a problem hiding this comment.
This part worries me a bit. After the initial load, the options have always been immutable before, now they can theoretically change, but they aren't reactive so if we've read them anywhere already, those values might now be stale (imagine clerk-js loads -> components in the host app rely on some options via the hooks -> ui loads with other options).
Supporting options updating for real with reactivity would be a huge pain for no real gain.
I think a clean alternative is to lift this to an __internal_attachUi(ui) function that's only callable after the initial load?
Internal only to avoid increasing the API surface needlessly for an advanced feature only we are likely to use, could make it public if there is demand.
Fixes #8569.
When React's
IsomorphicClerkreused an already-loaded global Clerk instance, it skipped the UI chunk load and immediately replayed premounted UI invocations, so sign-in/sign-up etc. never rendered. Now we load the UI chunk and callclerk.loadagain on the existing instance, which short-circuits the resource fetch but attachesClerkUIvia the new#initClerkUIpath.Includes regression tests for both packages and a patch changeset.
Before:
After: