Skip to content

Conversation

@wobsoriano
Copy link
Member

@wobsoriano wobsoriano commented Dec 1, 2025

Description

Starting from @clerk/shared@3.36.0, non-React applications (e.g., Vue/Nuxt/Astro) fail to start in development mode due to it loading swr which is specific to React. This PR moves the useAttemptToEnableOrganizations hook to @clerk/shared/react.

Discord thread: https://discord.com/channels/856971667393609759/1443954348479746048

Resolves USER-4119

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Summary by CodeRabbit

  • Refactor
    • Reorganized internal code structure for organizations feature enablement by moving a helper function to a dedicated React-specific module for improved maintainability.

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

@changeset-bot
Copy link

changeset-bot bot commented Dec 1, 2025

🦋 Changeset detected

Latest commit: db159cc

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

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

@vercel
Copy link

vercel bot commented Dec 1, 2025

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

Project Deployment Preview Comments Updated (UTC)
clerk-js-sandbox Ready Ready Preview Comment Dec 1, 2025 6:28pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 1, 2025

Walkthrough

Removed useAttemptToEnableOrganizations from the top-level organization module and reimplemented it as a React hook in a dedicated hooks file; updated imports and added a re-export in the hooks index. No other behavior changes to organization membership logic.

Changes

Cohort / File(s) Summary
Hook removal & new implementation
packages/shared/src/organization.ts, packages/shared/src/react/hooks/useAttemptToEnableOrganizations.ts
Removed public export from organization.ts; added new React hook implementation useAttemptToEnableOrganizations in react/hooks
Hooks index re-export
packages/shared/src/react/hooks/index.ts
Added re-export of useAttemptToEnableOrganizations from ./useAttemptToEnableOrganizations
Import updates
packages/shared/src/react/hooks/useOrganization.tsx, packages/shared/src/react/hooks/useOrganizationList.tsx
Updated imports to consume the hook from the new ./useAttemptToEnableOrganizations module
Changeset
.changeset/proud-ads-repeat.md
Added changeset noting the move and patch release for @clerk/shared

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Check that the new hook's implementation matches previous behavior (including effect guard and clerk call).
  • Verify all updated import paths compile and tests (if any) cover use sites.
  • Confirm the re-export in react/hooks/index.ts exposes the hook as intended.
  • Review .changeset for correct package/version implications.

Poem

🐰 I hopped a path from root to hooks,
A tidy burrow where logic looks,
One small move, the garden neat,
Re-exported steps with nimble feet,
🌿✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: moving the useAttemptToEnableOrganizations helper from the main shared package to the React-specific shared path to fix non-React environment failures.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch rob/user-4419-fix-react-code-leak

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • USER-4419: Entity not found: Issue - Could not find referenced Issue.

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

🧹 Nitpick comments (2)
packages/shared/src/react/hooks/index.ts (1)

5-5: Confirm intended visibility of useAttemptToEnableOrganizations in the public hooks barrel

Re‑exporting useAttemptToEnableOrganizations here exposes it alongside public hooks like useOrganization and useUser, while the implementation is marked @internal. If this is meant to stay internal, consider either:

  • Exporting it under an internal/underscored name (similar to the __internal_* exports below), or
  • Keeping it as a local import only where needed instead of re‑exporting it from this index.

If external consumption is desired, the current export is fine; just be aware it effectively becomes part of the public React hooks surface.

packages/shared/src/react/hooks/useAttemptToEnableOrganizations.ts (1)

10-27: Hook logic correctly migrated; consider explicit return type

The hook cleanly encapsulates the environment‑enabling behavior, with:

  • Proper use of useRef to ensure the effect runs only once even if clerk changes.
  • Optional chaining to remain compatible with older Clerk versions that lack __internal_attemptToEnableEnvironmentSetting.
  • A narrowed caller union that aligns with the current hook callers.

To better follow the TypeScript guideline of explicit return types for exported functions, you could annotate the signature as:

export function useAttemptToEnableOrganizations(
  caller: 'useOrganization' | 'useOrganizationList',
): void {
  // ...
}

Functionality-wise, this migration looks correct and non‑breaking.

📜 Review details

Configuration used: Path: .coderabbit.yaml

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 eccc430 and eba661b.

📒 Files selected for processing (5)
  • packages/shared/src/organization.ts (0 hunks)
  • packages/shared/src/react/hooks/index.ts (1 hunks)
  • packages/shared/src/react/hooks/useAttemptToEnableOrganizations.ts (1 hunks)
  • packages/shared/src/react/hooks/useOrganization.tsx (2 hunks)
  • packages/shared/src/react/hooks/useOrganizationList.tsx (1 hunks)
💤 Files with no reviewable changes (1)
  • packages/shared/src/organization.ts
🧰 Additional context used
📓 Path-based instructions (11)
**/*.{js,jsx,ts,tsx}

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

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

Files:

  • packages/shared/src/react/hooks/index.ts
  • packages/shared/src/react/hooks/useAttemptToEnableOrganizations.ts
  • packages/shared/src/react/hooks/useOrganization.tsx
  • packages/shared/src/react/hooks/useOrganizationList.tsx
**/*.{js,jsx,ts,tsx,json,md,yml,yaml}

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

Use Prettier for consistent code formatting

Files:

  • packages/shared/src/react/hooks/index.ts
  • packages/shared/src/react/hooks/useAttemptToEnableOrganizations.ts
  • packages/shared/src/react/hooks/useOrganization.tsx
  • packages/shared/src/react/hooks/useOrganizationList.tsx
packages/**/src/**/*.{ts,tsx}

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

TypeScript is required for all packages

Files:

  • packages/shared/src/react/hooks/index.ts
  • packages/shared/src/react/hooks/useAttemptToEnableOrganizations.ts
  • packages/shared/src/react/hooks/useOrganization.tsx
  • packages/shared/src/react/hooks/useOrganizationList.tsx
**/*.{ts,tsx,js,jsx}

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

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

Prefer importing types from @clerk/shared/types instead of the deprecated @clerk/types alias

Files:

  • packages/shared/src/react/hooks/index.ts
  • packages/shared/src/react/hooks/useAttemptToEnableOrganizations.ts
  • packages/shared/src/react/hooks/useOrganization.tsx
  • packages/shared/src/react/hooks/useOrganizationList.tsx
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/shared/src/react/hooks/index.ts
  • packages/shared/src/react/hooks/useAttemptToEnableOrganizations.ts
  • packages/shared/src/react/hooks/useOrganization.tsx
  • packages/shared/src/react/hooks/useOrganizationList.tsx
**/*.ts?(x)

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

Use proper TypeScript error types

Files:

  • packages/shared/src/react/hooks/index.ts
  • packages/shared/src/react/hooks/useAttemptToEnableOrganizations.ts
  • packages/shared/src/react/hooks/useOrganization.tsx
  • packages/shared/src/react/hooks/useOrganizationList.tsx
**/*.{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/shared/src/react/hooks/index.ts
  • packages/shared/src/react/hooks/useAttemptToEnableOrganizations.ts
  • packages/shared/src/react/hooks/useOrganization.tsx
  • packages/shared/src/react/hooks/useOrganizationList.tsx
**/index.ts

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

Avoid barrel files (index.ts re-exports) as they can cause circular dependencies

Files:

  • packages/shared/src/react/hooks/index.ts
**/*.tsx

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

**/*.tsx: Use error boundaries in React components
Minimize re-renders in React components

**/*.tsx: Use proper type definitions for props and state in React components
Leverage TypeScript's type inference where possible in React components
Use proper event types for handlers in React components
Implement proper generic types for reusable React components
Use proper type guards for conditional rendering in React components

Files:

  • packages/shared/src/react/hooks/useOrganization.tsx
  • packages/shared/src/react/hooks/useOrganizationList.tsx
**/*.{md,tsx}

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

Update documentation for API changes

Files:

  • packages/shared/src/react/hooks/useOrganization.tsx
  • packages/shared/src/react/hooks/useOrganizationList.tsx
**/*.{jsx,tsx}

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

**/*.{jsx,tsx}: Always use functional components with hooks instead of class components
Follow PascalCase naming for components (e.g., UserProfile, NavigationMenu)
Keep components focused on a single responsibility - split large components
Limit component size to 150-200 lines; extract logic into custom hooks
Use composition over inheritance - prefer smaller, composable components
Export components as named exports for better tree-shaking
One component per file with matching filename and component name
Separate UI components from business logic components
Use useState for simple state management in React components
Use useReducer for complex state logic in React components
Implement proper state initialization in React components
Use proper state updates with callbacks in React components
Implement proper state cleanup in React components
Use Context API for theme/authentication state management
Implement proper state persistence in React applications
Use React.memo for expensive components
Implement proper useCallback for handlers in React components
Use proper useMemo for expensive computations in React components
Implement proper virtualization for lists in React components
Use proper code splitting with React.lazy in React applications
Implement proper cleanup in useEffect hooks
Use proper refs for DOM access in React components
Implement proper event listener cleanup in React components
Use proper abort controllers for fetch in React components
Implement proper subscription cleanup in React components
Use proper HTML elements for semantic HTML in React components
Implement proper ARIA attributes for accessibility in React components
Use proper heading hierarchy in React components
Implement proper form labels in React components
Use proper button types in React components
Implement proper focus management for keyboard navigation in React components
Use proper keyboard shortcuts in React components
Implement proper tab order in React components
Use proper ...

Files:

  • packages/shared/src/react/hooks/useOrganization.tsx
  • packages/shared/src/react/hooks/useOrganizationList.tsx
🧬 Code graph analysis (1)
packages/shared/src/react/hooks/useAttemptToEnableOrganizations.ts (2)
packages/shared/src/react/hooks/index.ts (2)
  • useAttemptToEnableOrganizations (5-5)
  • useClerk (10-10)
packages/shared/src/organization.ts (1)
  • useAttemptToEnableOrganizations (27-44)
⏰ 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). (5)
  • GitHub Check: Formatting | Dedupe | Changeset
  • GitHub Check: Build Packages
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (2)
packages/shared/src/react/hooks/useOrganization.tsx (1)

23-25: Localized hook import looks good

Switching useAttemptToEnableOrganizations to the local ./useAttemptToEnableOrganizations module keeps the organization‑environment logic within the React hooks layer and avoids reaching into the broader organization module. No behavior change, and this is consistent with the new dedicated hook file.

packages/shared/src/react/hooks/useOrganizationList.tsx (1)

17-18: Consistent local import for organization environment helper

Importing useAttemptToEnableOrganizations from ./useAttemptToEnableOrganizations aligns this hook with the new shared React hook location and mirrors useOrganization.tsx. This keeps the environment‑enabling logic localized to the React hooks layer without altering behavior.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 1, 2025

Open in StackBlitz

@clerk/agent-toolkit

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

@clerk/astro

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

@clerk/backend

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

@clerk/chrome-extension

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

@clerk/clerk-js

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

@clerk/dev-cli

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

@clerk/elements

npm i https://pkg.pr.new/@clerk/elements@7334

@clerk/clerk-expo

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

@clerk/expo-passkeys

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

@clerk/express

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

@clerk/fastify

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

@clerk/localizations

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

@clerk/nextjs

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

@clerk/nuxt

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

@clerk/clerk-react

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

@clerk/react-router

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

@clerk/remix

npm i https://pkg.pr.new/@clerk/remix@7334

@clerk/shared

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

@clerk/tanstack-react-start

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

@clerk/testing

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

@clerk/themes

npm i https://pkg.pr.new/@clerk/themes@7334

@clerk/types

npm i https://pkg.pr.new/@clerk/types@7334

@clerk/upgrade

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

@clerk/vue

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

commit: db159cc

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

🧹 Nitpick comments (1)
.changeset/proud-ads-repeat.md (1)

5-5: Consider a more explicit changelog message for clarity.

The current message is concise but doesn't clearly communicate the bug being fixed or the root cause. Since non-React applications (Vue/Nuxt/Astro) were failing to start, consider expanding the message to better reflect the fix:

-Moved helper to enable Organizations feature to React-specific shared path
+Fix: Prevent React dependencies from loading in non-React environments by moving organization helper to React-specific shared path

Or alternatively:

-Moved helper to enable Organizations feature to React-specific shared path
+Fix: Moved useAttemptToEnableOrganizations to @clerk/shared/react to prevent swr (React-specific) from loading in non-React apps
📜 Review details

Configuration used: Path: .coderabbit.yaml

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 eba661b and db159cc.

📒 Files selected for processing (1)
  • .changeset/proud-ads-repeat.md (1 hunks)
⏰ 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). (30)
  • GitHub Check: Integration Tests (nextjs, chrome, 15)
  • GitHub Check: Integration Tests (nextjs, chrome, 14)
  • GitHub Check: Integration Tests (machine, chrome, RQ)
  • GitHub Check: Integration Tests (nextjs, chrome, 15, RQ)
  • GitHub Check: Integration Tests (react-router, chrome)
  • GitHub Check: Integration Tests (nextjs, chrome, 16)
  • GitHub Check: Integration Tests (quickstart, chrome, 16)
  • GitHub Check: Integration Tests (quickstart, chrome, 15)
  • GitHub Check: Integration Tests (billing, chrome, RQ)
  • GitHub Check: Integration Tests (handshake:staging, chrome)
  • GitHub Check: Integration Tests (handshake, chrome)
  • GitHub Check: Integration Tests (custom, chrome)
  • GitHub Check: Integration Tests (nuxt, chrome)
  • GitHub Check: Integration Tests (machine, chrome)
  • GitHub Check: Integration Tests (expo-web, chrome)
  • GitHub Check: Integration Tests (vue, chrome)
  • GitHub Check: Integration Tests (billing, chrome)
  • GitHub Check: Integration Tests (astro, chrome)
  • GitHub Check: Integration Tests (sessions, chrome)
  • GitHub Check: Integration Tests (localhost, chrome)
  • GitHub Check: Integration Tests (tanstack-react-start, chrome)
  • GitHub Check: Integration Tests (express, chrome)
  • GitHub Check: Integration Tests (sessions:staging, chrome)
  • GitHub Check: Integration Tests (elements, chrome)
  • GitHub Check: Integration Tests (ap-flows, chrome)
  • GitHub Check: Integration Tests (generic, chrome)
  • GitHub Check: Publish with pkg-pr-new
  • GitHub Check: Unit Tests (22, **)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan

@wobsoriano wobsoriano merged commit 02798f5 into main Dec 1, 2025
76 of 79 checks passed
@wobsoriano wobsoriano deleted the rob/user-4419-fix-react-code-leak branch December 1, 2025 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants