Skip to content

Conversation

@jacekradko
Copy link
Member

@jacekradko jacekradko commented Jan 23, 2026

Summary

Refactors the UI loading architecture so users only interact with an opaque ui prop from @clerk/ui. Each SDK internally decides whether to use the bundled UI constructor or load from CDN.

Key Changes

  • Public API: Users pass ui={ui} - the object is opaque
  • Removed clerkUiCtor from public IsomorphicClerkOptions (kept internally in ClerkOptions for SDK use)
  • Added __internal_forceBundledUI escape hatch for SDKs that must bundle the UI
  • Version pinning: CDN loading uses ui.version to pin the UI version

SDK Behavior

SDK Uses Bundled UI? Implementation
Chrome Extension Yes Sets __internal_forceBundledUI: true
React/Next.js No CDN with ui.version pinning
Vue No CDN with ui.version pinning
Astro No CDN with ui.version pinning

Usage

import { ui } from '@clerk/ui';

<ClerkProvider ui={ui}>
  ...
</ClerkProvider>

The ui export is opaque - users just pass it to ClerkProvider without accessing internals. The SDK handles whether to use ui.ctor or load from CDN.

Test plan

  • Build passes
  • Unit tests pass
  • Verify Chrome Extension works with bundled UI
  • Verify React/Next.js loads from CDN with correct version
  • Verify Vue loads from CDN with correct version
  • Verify Astro loads from CDN with correct version

Summary by CodeRabbit

  • New Features

    • Added a ui prop to ClerkProvider to pass the Clerk UI bundle, enabling explicit UI version pinning and bundled/CDN usage.
  • Chores

    • Unified Clerk UI wiring into a single ui option (version, url, ClerkUI) instead of separate fields.
    • Renamed public prop clerkUiUrl to clerkUIUrl across integrations and templates.
  • Tests

    • Added and updated unit tests covering CDN/bundled UI loading and new ui option behaviors.

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel
Copy link

vercel bot commented Jan 23, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
clerk-js-sandbox Ready Ready Preview, Comment Jan 26, 2026 9:09pm

Request Review

@changeset-bot
Copy link

changeset-bot bot commented Jan 23, 2026

🦋 Changeset detected

Latest commit: 08064ce

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

This PR includes changesets to release 20 packages
Name Type
@clerk/ui Minor
@clerk/react Minor
@clerk/vue Minor
@clerk/astro Minor
@clerk/chrome-extension Minor
@clerk/shared Minor
@clerk/expo Patch
@clerk/nextjs Patch
@clerk/react-router Patch
@clerk/tanstack-react-start Patch
@clerk/nuxt Patch
@clerk/agent-toolkit Patch
@clerk/backend Patch
@clerk/clerk-js Patch
@clerk/expo-passkeys Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/localizations Patch
@clerk/msw Patch
@clerk/testing 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

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 23, 2026

Open in StackBlitz

@clerk/agent-toolkit

npm i https://pkg.pr.new/@clerk/agent-toolkit@7664

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@7664

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@7664

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@7664

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@7664

@clerk/dev-cli

npm i https://pkg.pr.new/@clerk/dev-cli@7664

@clerk/expo

npm i https://pkg.pr.new/@clerk/expo@7664

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@7664

@clerk/express

npm i https://pkg.pr.new/@clerk/express@7664

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@7664

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@7664

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@7664

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@7664

@clerk/react

npm i https://pkg.pr.new/@clerk/react@7664

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@7664

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@7664

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@7664

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@7664

@clerk/ui

npm i https://pkg.pr.new/@clerk/ui@7664

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@7664

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@7664

commit: 08064ce

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 23, 2026

📝 Walkthrough

Walkthrough

Renames ClerkUiConstructorClerkUIConstructor and the global hook window.__internal_ClerkUiCtorwindow.__internal_ClerkUICtor. Replaces the top-level clerkUiCtor option with a nested ui object ({ version, url, ClerkUI, __internal_preferCDN }) passed into Clerk.load and exposes ui.ClerkUI from @clerk/ui. Migrates environment/prop keys clerkUiUrl/clerkUiVersionclerkUIUrl/clerkUIVersion. Adds a public ui prop to ClerkProvider and updates many packages, plugins, templates, and tests to use the new naming and loading flow.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 38.89% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: replacing clerkUiCtor prop with ui prop across React, Vue, and Astro packages.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/vue/src/plugin.ts (1)

81-91: Misleading comment on fallback behavior.

The comment states "fall back to clerkUiCtor (deprecated)" but the actual fallback is loading from CDN via loadClerkUiScript, not checking a clerkUiCtor property. Consider updating the comment to accurately reflect the behavior:

-          // Check for ui.ctor first (new API), then fall back to clerkUiCtor (deprecated)
+          // Check for ui.ctor first (bundled UI), then fall back to loading from CDN
🧹 Nitpick comments (1)
packages/astro/src/internal/create-clerk-instance.ts (1)

118-122: Misleading comment: fallback is CDN loading, not clerkUiCtor.

The comment mentions "fall back to clerkUiCtor (deprecated)" but the actual fallback is loading from CDN via loadClerkUiScript. The clerkUiCtor option path was removed from this function.

Suggested fix
-  // Check for ui.ctor first (new API), then fall back to clerkUiCtor (deprecated)
+  // If ui.ctor is provided (bundled UI), use it directly; otherwise load from CDN
   const ctorFromUi = options?.ui?.ctor;
   if (ctorFromUi) {
     return ctorFromUi;
   }

Adds `ui` prop to ClerkProvider for specifying UI metadata.
Each SDK decides whether to use `ui.ctor` based on support level.

- `@clerk/ui` exports only `{ ui }` with version and ctor
- Chrome extension uses `ui.ctor` (verified to work)
- React, Vue, Astro use CDN loading (not verified for bundling yet)
- Omit `clerkUiCtor` from public ClerkProviderProps type
@jacekradko jacekradko force-pushed the jrad/ui-prop-cleanup branch from 431aa50 to c5ff0d1 Compare January 23, 2026 20:05
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/astro/src/internal/create-clerk-instance.ts (1)

111-124: ui.ctor is not being used when provided.

The PR objective states that when ui.ctor is provided, it should be used instead of loading from CDN. However, getClerkUiEntryChunk always loads the UI script from CDN and ignores options.ui?.ctor. This contradicts the JSDoc in packages/astro/src/types.ts (lines 39-43) which states: "When provided with a bundled UI via ui.ctor, it will be used instead of loading from CDN."

Suggested fix to honor ui.ctor when provided
 async function getClerkUiEntryChunk<TUi extends Ui = Ui>(
   options?: AstroClerkCreateInstanceParams<TUi>,
 ): Promise<ClerkUiConstructor> {
+  // Use bundled UI constructor if provided
+  if (options?.ui?.ctor) {
+    return options.ui.ctor;
+  }
+
   await loadClerkUiScript(options);

   if (!window.__internal_ClerkUiCtor) {
     throw new Error('Failed to download latest Clerk UI. Contact support@clerk.com.');
   }

   return window.__internal_ClerkUiCtor;
 }
🤖 Fix all issues with AI agents
In `@packages/vue/src/plugin.ts`:
- Around line 81-87: The code always calls loadClerkUiScript and ignores a
provided bundled constructor; update the clerkUiCtorPromise logic to first check
pluginOptions.ui?.ctor (or options.ui?.ctor) and resolve to that ctor if
present, otherwise call loadClerkUiScript and fall back to
window.__internal_ClerkUiCtor; ensure clerkUiCtorPromise returns the provided
ctor when available, and preserve the existing error throw if neither the
provided ctor nor the downloaded window.__internal_ClerkUiCtor is present.

Comment on lines 81 to 87
const clerkUiCtorPromise = (async () => {
await loadClerkUiScript(options);
if (!window.__internal_ClerkUiCtor) {
throw new Error('Failed to download latest Clerk UI. Contact support@clerk.com.');
}
return window.__internal_ClerkUiCtor;
})();
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

ui.ctor is not being used when provided.

Same issue as in the Astro integration: the code always loads the UI from CDN via loadClerkUiScript and ignores pluginOptions.ui?.ctor. This contradicts the documented behavior that bundled UI via ui.ctor should be used instead of CDN loading.

Suggested fix to honor ui.ctor when provided
          const clerkUiCtorPromise = (async () => {
+            // Use bundled UI constructor if provided
+            if (pluginOptions.ui?.ctor) {
+              return pluginOptions.ui.ctor;
+            }
+
             await loadClerkUiScript(options);
             if (!window.__internal_ClerkUiCtor) {
               throw new Error('Failed to download latest Clerk UI. Contact support@clerk.com.');
             }
             return window.__internal_ClerkUiCtor;
           })();
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const clerkUiCtorPromise = (async () => {
await loadClerkUiScript(options);
if (!window.__internal_ClerkUiCtor) {
throw new Error('Failed to download latest Clerk UI. Contact support@clerk.com.');
}
return window.__internal_ClerkUiCtor;
})();
const clerkUiCtorPromise = (async () => {
// Use bundled UI constructor if provided
if (pluginOptions.ui?.ctor) {
return pluginOptions.ui.ctor;
}
await loadClerkUiScript(options);
if (!window.__internal_ClerkUiCtor) {
throw new Error('Failed to download latest Clerk UI. Contact support@clerk.com.');
}
return window.__internal_ClerkUiCtor;
})();
🤖 Prompt for AI Agents
In `@packages/vue/src/plugin.ts` around lines 81 - 87, The code always calls
loadClerkUiScript and ignores a provided bundled constructor; update the
clerkUiCtorPromise logic to first check pluginOptions.ui?.ctor (or
options.ui?.ctor) and resolve to that ctor if present, otherwise call
loadClerkUiScript and fall back to window.__internal_ClerkUiCtor; ensure
clerkUiCtorPromise returns the provided ctor when available, and preserve the
existing error throw if neither the provided ctor nor the downloaded
window.__internal_ClerkUiCtor is present.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@packages/chrome-extension/src/react/ClerkProvider.tsx`:
- Around line 38-40: The spread uses an unsafe cast ({...(rest as any)}) to
sneak in clerkUiCtor, hiding a type mismatch; replace this by declaring an
internal extended props type (e.g., InternalClerkProviderProps) that extends
ClerkProviderProps and includes clerkUiCtor with the correct type, update the
component signature to use that internal type, remove the as any cast, and pass
clerkUiCtor={ui.ctor} and Clerk={clerkInstance} with proper typing so TypeScript
enforces compatibility (locate symbols: ClerkProvider.tsx, rest, clerkUiCtor,
ui.ctor, ClerkReactProvider, ClerkProviderProps, clerkInstance).
♻️ Duplicate comments (1)
packages/vue/src/plugin.ts (1)

81-87: ui.ctor is not being used when provided.

Same issue as in the Astro integration: the code always loads the UI from CDN via loadClerkUiScript and ignores pluginOptions.ui?.ctor. This contradicts the documented behavior that bundled UI via ui.ctor should be used instead of CDN loading.

🧹 Nitpick comments (1)
.changeset/shiny-owls-dance.md (1)

10-23: Consider adding migration guidance.

The changeset describes the new ui prop but doesn't mention the deprecation or removal of clerkUiCtor. Since the PR objectives state "Omits clerkUiCtor from public ClerkProviderProps," consider adding explicit migration guidance to help users transition from the old API.

📝 Suggested addition for migration guidance
 Usage:
 ```tsx
 import { ui } from '@clerk/ui';
 
 <ClerkProvider ui={ui}>
   ...
 </ClerkProvider>

+Migration note: The clerkUiCtor prop has been removed from public types. Use the ui prop instead by importing the ui object from @clerk/ui.

</details>

</blockquote></details>

</blockquote></details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/react/src/isomorphicClerk.ts (1)

511-535: Add tests for the new bundled ui.ctor path and CDN fallback.

Line 511 introduces a new early-return path for ui.ctor. I don’t see tests in this PR; please add (or point to) coverage that validates the bundled constructor path and the CDN fallback to prevent regressions.

Check for options.ui.ClerkUI before loading from CDN. If a bundled
ClerkUIConstructor is provided, return it directly instead of calling
loadClerkUiScript.
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@packages/astro/src/internal/create-clerk-instance.ts`:
- Around line 127-134: The spread into loadClerkUiScript is being overwritten by
clerkUiUrl: options.ui?.url which sets clerkUiUrl to undefined when
options.ui?.url is absent and breaks custom/self-hosted UIs; change the override
in the call to preserve an existing fallback (e.g., use the existing
options.clerkUiUrl or null-coalescing: clerkUiUrl: options.ui?.url ??
options.clerkUiUrl) or simply omit the clerkUiUrl override when options.ui?.url
is undefined so loadClerkUiScript receives the original clerkUiUrl; update the
call site in create-clerk-instance.ts where loadClerkUiScript is invoked and add
a unit/integration test exercising the custom URL path to ensure a provided
custom/self-hosted UI URL is used.

Use null-coalescing to fall back to options.clerkUiUrl when
options.ui?.url is not provided, preventing custom/self-hosted UI URLs
from being overwritten with undefined.

Also adds vitest setup and tests for the clerkUiUrl fallback behavior.
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@packages/vue/src/plugin.ts`:
- Around line 83-87: The call to loadClerkUiScript is overwriting a valid
options.clerkUIUrl with undefined because pluginOptions.ui?.url may be absent;
update the args so clerkUIUrl is only set when pluginOptions.ui?.url is defined
(e.g., use a conditional or nullish-coalescing to fall back to
options.clerkUIUrl) and keep clerkUIVersion mapping as-is; locate the
loadClerkUiScript invocation and change the clerkUIUrl assignment to use
pluginOptions.ui?.url ?? options.clerkUIUrl or omit the property when undefined.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@packages/vue/src/plugin.ts`:
- Around line 83-87: The call to loadClerkUiScript is referencing nonexistent
properties options.clerkUIVersion and options.clerkUIUrl; update the invocation
so it does not fall back to those fields — either pass only
pluginOptions.ui?.version and pluginOptions.ui?.url (remove the options.*
fallbacks) or, if you intended to reuse the JS values, map
options.clerkJSVersion -> clerkUIVersion and options.clerkJSUrl -> clerkUIUrl
before calling loadClerkUiScript; change the arguments in the loadClerkUiScript
call accordingly (refer to loadClerkUiScript, pluginOptions, and options).
♻️ Duplicate comments (1)
packages/vue/src/plugin.ts (1)

81-92: Bundled UI constructor is ignored; code always loads from CDN.

When pluginOptions.ui?.ClerkUI is provided (bundled UI), the code should use it directly instead of loading from CDN. This was flagged in a previous review and remains unaddressed.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@integration/templates/react-router-library/src/main.tsx`:
- Around line 15-18: The template now uses the renamed ClerkProvider prop
clerkUIUrl; update or add tests to exercise this public API change by asserting
that ClerkProvider is rendered with clerkUIUrl (not the old prop) in
integration/template validation or unit tests—locate usages of ClerkProvider in
main.tsx and update any existing tests referencing the old prop name to pass
clerkUIUrl and verify the provider receives and uses that value (e.g., via
shallow render, snapshot, or template validation).

…opt-out for Next.js

Replaces __internal_forceBundledUI with __internal_preferCDN to fix double-loading issue where importing @clerk/ui would bundle ClerkUI but still load it from CDN.

- Default behavior now uses bundled UI when ui.ClerkUI is provided
- Next.js sets __internal_preferCDN due to bundling issues
- Chrome Extension simplified (no longer needs explicit flag)
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@packages/react/src/isomorphicClerk.ts`:
- Around line 464-477: getClerkUiEntryChunk is async and is being called without
awaiting its Promise, so ClerkUI is a Promise instead of the resolved
constructor; change the call to await this.getClerkUiEntryChunk() so ClerkUI
contains the actual constructor before passing it into clerk.load({... ui: {
..., ClerkUI }}). Locate the usage around getClerkUiEntryChunk,
getClerkJsEntryChunk, beforeLoad, and clerk.load in isomorphicClerk.ts and
ensure ClerkUI is awaited (and handle any needed async context) before calling
clerk.load with the ui.ClerkUI value.

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.

3 participants