Skip to content

Conversation

@brkalow
Copy link
Member

@brkalowbrkalow commented Jan 15, 2026

Summary

  • Introduces a new ui.shared.browser.js build variant that externalizes React dependencies, allowing the host application's React to be reused instead of bundling a separate copy
  • Adds @clerk/ui/register module to register React on globalThis.__clerkSharedModules for sharing with @clerk/ui
  • Adds clerkUiVariant option to explicitly control which variant to use
  • For @clerk/react users, the shared variant is automatically detected and enabled for compatible React versions
  • Extracts version checking logic into a testable utility with comprehensive unit tests
  • Adds development warnings for configuration fallbacks and React version mismatches

Test plan

  • Unit tests added for version parsing and bounds checking (20 new tests)
  • All existing tests pass (328 total)
  • Build succeeds for @clerk/react package
  • Manual testing: verify bundle size reduction in a sample app using @clerk/react
  • Manual testing: verify fallback to non-shared variant when React version is incompatible

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Shared React variant for @clerk/ui that reduces bundle size by reusing the host app’s React.
    • New register module to register host React for use by the UI bundle.
    • @clerk/react will auto-enable the shared variant when the host React is compatible.
    • New clerkUiVariant: 'shared' option for custom integrations (load the register module before the UI bundle).

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

@changeset-bot
Copy link

changeset-botbot commented Jan 15, 2026

🦋 Changeset detected

Latest commit: 6818b53

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

This PR includes changesets to release 20 packages
NameType
@clerk/uiMinor
@clerk/reactMinor
@clerk/sharedPatch
@clerk/astroPatch
@clerk/chrome-extensionPatch
@clerk/vuePatch
@clerk/expoPatch
@clerk/nextjsPatch
@clerk/react-routerPatch
@clerk/tanstack-react-startPatch
@clerk/agent-toolkitPatch
@clerk/backendPatch
@clerk/clerk-jsPatch
@clerk/expo-passkeysPatch
@clerk/expressPatch
@clerk/fastifyPatch
@clerk/localizationsPatch
@clerk/mswPatch
@clerk/nuxtPatch
@clerk/testingPatch

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

@vercel
Copy link

vercelbot commented Jan 15, 2026

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

ProjectDeploymentReviewUpdated (UTC)
clerk-js-sandboxReadyReadyPreview, CommentJan 16, 2026 5:00am

Review with Vercel Agent

@coderabbitai
Copy link
Contributor

coderabbitaibot commented Jan 15, 2026

📝 Walkthrough

Walkthrough

Adds a shared React variant for @clerk that externalizes React to reduce duplicate bundling and introduces a ui.shared.browser.js build. Adds @clerk/ui/register (CJS and ESM) which populates globalThis.__clerkSharedModules with React, ReactDOM, and JSX runtime. Introduces version utilities (parseVersion, checkVersionAgainstBounds, isVersionCompatible, IS_REACT_SHARED_VARIANT_COMPATIBLE) and makes @clerk/react auto-enable the shared variant when compatible. Exposes a clerkUiVariant option on IsomorphicClerkOptions and loadClerkJsScript. Build configs (rspack/tsup) and package exports are updated to produce and expose the shared variant.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check nameStatusExplanation
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
Title check✅ PassedThe PR title accurately summarizes the main feature: adding a shared React variant to reduce bundle size, which is the core objective of the changeset.
Docstring Coverage✅ PassedDocstring coverage is 83.33% which is sufficient. The required threshold is 80.00%.

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



📜 Recent review details

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between d7c670c and 6818b53.

📒 Files selected for processing (2)
  • packages/react/src/index.ts
  • packages/react/src/utils/versionCheck.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/react/src/index.ts
🧰 Additional context used
📓 Path-based instructions (10)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

All code must pass ESLint checks with the project's configuration

Files:

  • packages/react/src/utils/versionCheck.ts
**/*.{js,jsx,ts,tsx,json,md,yml,yaml}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use Prettier for consistent code formatting

Files:

  • packages/react/src/utils/versionCheck.ts
packages/**/src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

TypeScript is required for all packages

Files:

  • packages/react/src/utils/versionCheck.ts
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Follow established naming conventions (PascalCase for components, camelCase for variables)

Files:

  • packages/react/src/utils/versionCheck.ts
packages/**/src/**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

packages/**/src/**/*.{ts,tsx,js,jsx}: Maintain comprehensive JSDoc comments for public APIs
Use tree-shaking friendly exports
Validate all inputs and sanitize outputs
All public APIs must be documented with JSDoc
Use dynamic imports for optional features
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Implement proper logging with different levels

Files:

  • packages/react/src/utils/versionCheck.ts
**/*.ts?(x)

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use proper TypeScript error types

Files:

  • packages/react/src/utils/versionCheck.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/typescript.mdc)

**/*.{ts,tsx}: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoid any type - prefer unknown when type is uncertain, then narrow with type guards
Implement type guards for unknown types using the pattern function isType(value: unknown): value is Type
Use interface for object shapes that might be extended
Use type for unions, primitives, and computed types
Prefer readonly properties for immutable data structures
Use private for internal implementation details in classes
Use protected for inheritance hierarchies
Use public explicitly for clarity in public APIs
Use mixins for shared behavior across unrelated classes in TypeScript
Use generic constraints with bounded type parameters like <T extends{id: string }>
Use utility types like Omit, Partial, and Pick for data transformation instead of manual type construction
Use discriminated unions instead of boolean flags for state management and API responses
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation at the type level
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Document functions with JSDoc comments including @param, @returns, @throws, and @example tags
Create custom error classes that extend Error for specific error types
Use the Result pattern for error handling instead of throwing exceptions
Use optional chaining (?.) and nullish coalescing (??) operators for safe property access
Let TypeScript infer obvious types to reduce verbosity
Use const assertions with as const for literal types
Use satisfies operator for type checking without widening types
Declare readonly arrays and objects for immutable data structures
Use spread operator and array spread for immutable updates instead of mutations
Use lazy loading for large types...

Files:

  • packages/react/src/utils/versionCheck.ts
**/*.{js,ts,jsx,tsx}

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Use ESLint with custom configurations tailored for different package types

Files:

  • packages/react/src/utils/versionCheck.ts
**/*.{js,ts,jsx,tsx,json,md,yml,yaml}

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Use Prettier for code formatting across all packages

Files:

  • packages/react/src/utils/versionCheck.ts
**/*

⚙️ CodeRabbit configuration file

If there are no tests added or modified as part of the PR, please suggest that tests be added to cover the changes.

**/*: Only comment on issues that would block merging, ignore minor or stylistic concerns.
Restrict feedback to errors, security risks, or functionality-breaking problems.
Do not post comments on code style, formatting, or non-critical improvements.
Keep reviews short: flag only issues that make the PR unsafe to merge.
Group similar issues into a single comment instead of posting multiple notes.
Skip repetition: if a pattern repeats, mention it once at a summary level only.
Do not add general suggestions, focus strictly on merge-blocking concerns.
If there are no critical problems, respond with minimal approval (e.g., 'Looks good'). Do not add additional review.
Avoid line-by-line commentary unless it highlights a critical bug or security hole.
Highlight only issues that could cause runtime errors, data loss, or severe maintainability issues.
Ignore minor optimization opportunities, focus solely on correctness and safety.
Provide a top-level summary of critical blockers rather than detailed per-line notes.
Comment only when the issue must be resolved before merge, otherwise remain silent.
When in doubt, err on the side of fewer comments, brevity and blocking issues only.
Avoid posting any refactoring issues.

Files:

  • packages/react/src/utils/versionCheck.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (27)
  • GitHub Check: Integration Tests (nextjs, chrome, 16, RQ)
  • GitHub Check: Integration Tests (nuxt, chrome)
  • GitHub Check: Integration Tests (tanstack-react-start, chrome)
  • GitHub Check: Integration Tests (custom, chrome)
  • GitHub Check: Integration Tests (express, chrome)
  • GitHub Check: Integration Tests (nextjs, chrome, 16)
  • GitHub Check: Integration Tests (quickstart, chrome, 16)
  • GitHub Check: Integration Tests (machine, chrome, RQ)
  • GitHub Check: Integration Tests (machine, chrome)
  • GitHub Check: Integration Tests (quickstart, chrome, 15)
  • GitHub Check: Integration Tests (nextjs, chrome, 15)
  • GitHub Check: Integration Tests (react-router, chrome)
  • GitHub Check: Integration Tests (billing, chrome)
  • GitHub Check: Integration Tests (handshake, chrome)
  • GitHub Check: Integration Tests (generic, chrome)
  • GitHub Check: Integration Tests (localhost, chrome)
  • GitHub Check: Integration Tests (vue, chrome)
  • GitHub Check: Integration Tests (billing, chrome, RQ)
  • GitHub Check: Integration Tests (astro, chrome)
  • GitHub Check: Integration Tests (handshake:staging, chrome)
  • GitHub Check: Integration Tests (ap-flows, chrome)
  • GitHub Check: Integration Tests (sessions, chrome)
  • GitHub Check: Integration Tests (sessions:staging, chrome)
  • GitHub Check: Build Packages
  • GitHub Check: Formatting | Dedupe | Changeset
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: semgrep-cloud-platform/scan

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


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

@pkg-pr-new
Copy link

pkg-pr-newbot commented Jan 15, 2026

Open in StackBlitz

@clerk/agent-toolkit

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

@clerk/astro

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

@clerk/backend

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

@clerk/chrome-extension

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

@clerk/clerk-js

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

@clerk/dev-cli

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

@clerk/expo

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

@clerk/expo-passkeys

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

@clerk/express

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

@clerk/fastify

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

@clerk/localizations

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

@clerk/nextjs

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

@clerk/nuxt

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

@clerk/react

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

@clerk/react-router

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

@clerk/shared

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

@clerk/tanstack-react-start

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

@clerk/testing

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

@clerk/ui

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

@clerk/upgrade

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

@clerk/vue

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

commit: 6818b53

brkalowand others added 11 commits January 15, 2026 22:54
Introduces a "shared" variant of @clerk/ui that externalizes React dependencies, allowing the host application's React to be reused instead of bundling a separate copy. Changes: - Add @clerk/ui/register module to register React on globalThis - Add ui.shared.browser.js build variant with externalized React - Add React version compatibility checking in @clerk/react - Add clerkUiVariant option to load the appropriate variant - Make dev server React externalization conditional via --env shared Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Extract version checking logic into testable utility (versionCheck.ts) - Add comprehensive unit tests for version parsing and bounds checking - Move version compatibility check to module level for better performance - Add dev warning when pnpm-workspace.yaml fallback is used - Add warning for React version mismatch in register modules - Remove redundant clerkUiVariant assignment in isomorphicClerk.ts Co-Authored-By: Claude Opus 4.5 <[email protected]>
The new exports field in clerk-js/package.json blocked deep imports that expo and chrome-extension packages depended on. This adds: - ./internal/fapi export for FapiRequestInit/FapiResponse types (expo) - ./no-rhc export for the no-RHC variant (chrome-extension) Also updates expo to use the new clean import path. Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Rename register/index.js to register/index.cjs to fix module syntax mismatch (package uses "type": "module" but file was CommonJS) - Add register/index.d.cts for CJS type declarations to fix "Masquerading as ESM" attw error - Update exports to point to correct file extensions - Run pnpm dedupe to clean up lockfile Co-Authored-By: Claude Opus 4.5 <[email protected]>
The new exports field introduces ESM entry points (.mjs) with CJS type declarations (.d.ts), which triggers attw's "Masquerading as CJS" warning. This is expected behavior for this package's build setup, so we ignore the false-cjs rule. Co-Authored-By: Claude Opus 4.5 <[email protected]>
Add required curly braces after if conditions in versionCheck.ts and fix import sorting in index.ts. Co-Authored-By: Claude Opus 4.5 <[email protected]>
Sign up for freeto 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.

2 participants

@brkalow