Skip to content

Conversation

@panteliselef
Copy link
Member

@panteliselef panteliselef commented Aug 22, 2025

Description

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

  • Documentation

    • Clarified and expanded error messages when an active organization is required, with guidance on obtaining org ID and a link to SSR docs.
  • Chores

    • Patch releases for shared and React packages to roll out the updated messaging.
  • Tests

    • Updated tests to expect the improved, more detailed error messages.

@panteliselef panteliselef requested review from a team and thiskevinwang August 22, 2025 12:10
@panteliselef panteliselef self-assigned this Aug 22, 2025
@changeset-bot
Copy link

changeset-bot bot commented Aug 22, 2025

🦋 Changeset detected

Latest commit: 06f76bf

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

This PR includes changesets to release 19 packages
Name Type
@clerk/shared Patch
@clerk/clerk-react 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/remix Patch
@clerk/tanstack-react-start Patch
@clerk/testing Patch
@clerk/vue 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 Aug 22, 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 Aug 22, 2025 1:13pm

@pkg-pr-new
Copy link

pkg-pr-new bot commented Aug 22, 2025

Open in StackBlitz

@clerk/agent-toolkit

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

@clerk/astro

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

@clerk/backend

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

@clerk/chrome-extension

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

@clerk/clerk-js

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

@clerk/dev-cli

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

@clerk/elements

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

@clerk/clerk-expo

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

@clerk/expo-passkeys

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

@clerk/express

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

@clerk/fastify

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

@clerk/localizations

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

@clerk/nextjs

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

@clerk/nuxt

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

@clerk/clerk-react

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

@clerk/react-router

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

@clerk/remix

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

@clerk/shared

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

@clerk/tanstack-react-start

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

@clerk/testing

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

@clerk/themes

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

@clerk/types

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

@clerk/upgrade

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

@clerk/vue

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

commit: 06f76bf

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 22, 2025

📝 Walkthrough

Walkthrough

Adds a changeset entry bumping patch versions for @clerk/shared and @clerk/clerk-react. Updates in packages/react and packages/shared: CheckoutButton.tsx, SubscriptionDetailsButton.tsx, and useCheckout.ts (and their tests) adjust documentation and runtime error-message text to prefix messages with "Clerk: " and to instruct retrieving orgId from useAuth() and ensuring it is defined; an SSR docs link was also added to messages. No control-flow, logic, or public API/signature changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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 (5)
packages/react/src/components/CheckoutButton.tsx (3)

31-37: Docs example uses outdated prop subscriberType="org"; code uses for="organization".
This mismatch will confuse integrators. Update the example to reflect the current API.

Proposed fix:

- *       <CheckoutButton
- *         planId="plan_123"
- *         planPeriod="month"
- *         subscriberType="org"
- *         onSubscriptionComplete={() => console.log('Subscription completed!')}
- *       >
+ *       <CheckoutButton
+ *         planId="plan_123"
+ *         planPeriod="month"
+ *         for="organization"
+ *         onSubscriptionComplete={() => console.log('Subscription completed!')}
+ *       >

44-46: Throws JSDoc mentions subscriberType="org"; should reflect for="organization".
Keep JSDoc aligned with runtime checks and the new error text.

- * @throws {Error} When `subscriberType="org"` is used without an active organization context
+ * @throws {Error} When `for="organization"` is used without an active organization context

59-66: Widen the orgId guard to catch undefined as well as null
The useAuth() return type (in packages/types/src/hooks.ts) shows orgId may be undefined (initial load) or null (no active organization). The current check only handles null, so an undefined orgId would slip through and lead to unexpected behavior.

Please update in packages/react/src/components/CheckoutButton.tsx (around lines 59–66):

-    if (orgId === null && _for === 'organization') {
+    if (_for === 'organization' && orgId == null) {
       throw new Error(
         'Ensure that `<CheckoutButton />` is rendered inside a `<SignedIn />` component with an active organization.'
       );

Using orgId == null covers both null and undefined.
Alternatively, an explicit check works too:

if (_for === 'organization' && (orgId === null || orgId === undefined)) {  }
packages/react/src/components/SubscriptionDetailsButton.tsx (2)

28-33: Docs example uses for="org"; runtime and other messages use for="organization".
Unify to for="organization" to match the check and guidance.

- *     <SubscriptionDetailsButton
- *       for="org"
- *       onSubscriptionCancel={() => console.log('Subscription canceled')}
- *     >
+ *     <SubscriptionDetailsButton
+ *       for="organization"
+ *       onSubscriptionCancel={() => console.log('Subscription canceled')}
+ *     >

38-40: Throws JSDoc should say for="organization".
Keep the JSDoc aligned with the guard and error text.

- * @throws {Error} When `for="org"` is used without an active organization context
+ * @throws {Error} When `for="organization"` is used without an active organization context
🧹 Nitpick comments (4)
packages/react/src/components/CheckoutButton.tsx (2)

66-68: Prefix error with “Clerk:” for consistency with hook errors.
useCheckout errors are prefixed with Clerk: while this component isn’t. Aligning improves debuggability and log triage.

Apply this minimal diff:

-      throw new Error(
-        'Wrap `<CheckoutButton for="organization" />` with a check for an active organization. Retrieve `orgId` from `useAuth()` and confirm it is defined. For SSR, see: https://clerk.com/docs/references/backend/types/auth-object#how-to-access-the-auth-object',
-      );
+      throw new Error(
+        'Clerk: Wrap `<CheckoutButton for="organization" />` with a check for an active organization. Retrieve `orgId` from `useAuth()` and confirm it is defined. For SSR, see: https://clerk.com/docs/references/backend/types/auth-object#how-to-access-the-auth-object',
+      );

1-101: Add lightweight tests to lock in the improved assertion behavior.
There are no tests in the PR. Add unit tests that verify an error is thrown when _for="organization" and there’s no active org. Also test that no error is thrown when an org is present.

Happy to scaffold tests. For example:

// packages/react/src/components/__tests__/CheckoutButton.org-assertion.test.tsx
// Pseudocode – replace with your test framework/helpers
it('throws when for="organization" and no org is active', () => {
  mockUseAuth({ userId: 'user_1', orgId: null });
  expect(() => render(<CheckoutButton for="organization" planId="plan_123" />)).toThrow(/active organization/i);
});
packages/react/src/components/SubscriptionDetailsButton.tsx (1)

61-62: Prefix error with “Clerk:” for consistency with shared hook messages.
Aligns with useCheckout’s “Clerk:” prefix and aids log scanning.

-        'Wrap `<SubscriptionDetailsButton for="organization" />` with a check for an active organization. Retrieve `orgId` from `useAuth()` and confirm it is defined. For SSR, see: https://clerk.com/docs/references/backend/types/auth-object#how-to-access-the-auth-object',
+        'Clerk: Wrap `<SubscriptionDetailsButton for="organization" />` with a check for an active organization. Retrieve `orgId` from `useAuth()` and confirm it is defined. For SSR, see: https://clerk.com/docs/references/backend/types/auth-object#how-to-access-the-auth-object',
packages/shared/src/react/hooks/useCheckout.ts (1)

86-90: Reduce duplication by centralizing the active-organization assertion text.
The same guidance appears in 3 files. Consider a shared constant (e.g., in @clerk/shared) to avoid drift if the URL or wording changes.

Example (outside this hunk):

// packages/shared/src/errors/messages.ts
export const ACTIVE_ORG_ASSERTION =
  'Clerk: Ensure your flow checks for an active organization. Retrieve `orgId` from `useAuth()` and confirm it is defined. For SSR, see: https://clerk.com/docs/references/backend/types/auth-object#how-to-access-the-auth-object' as const;

Then:

-    throw new Error(
-      'Clerk: Ensure your flow checks for an active organization. Retrieve `orgId` from `useAuth()` and confirm it is defined. For SSR, see: https://clerk.com/docs/references/backend/types/auth-object#how-to-access-the-auth-object',
-    );
+    throw new Error(ACTIVE_ORG_ASSERTION);
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled
  • 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 4e15e06 and b3a9ff6.

📒 Files selected for processing (4)
  • .changeset/plain-bottles-press.md (1 hunks)
  • packages/react/src/components/CheckoutButton.tsx (1 hunks)
  • packages/react/src/components/SubscriptionDetailsButton.tsx (1 hunks)
  • packages/shared/src/react/hooks/useCheckout.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (10)
**/*.{js,jsx,ts,tsx}

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

**/*.{js,jsx,ts,tsx}: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
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
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels

Files:

  • packages/react/src/components/CheckoutButton.tsx
  • packages/shared/src/react/hooks/useCheckout.ts
  • packages/react/src/components/SubscriptionDetailsButton.tsx
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}

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

Use Prettier for consistent code formatting

Files:

  • packages/react/src/components/CheckoutButton.tsx
  • packages/shared/src/react/hooks/useCheckout.ts
  • packages/react/src/components/SubscriptionDetailsButton.tsx
packages/**/*.{ts,tsx}

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

TypeScript is required for all packages

Files:

  • packages/react/src/components/CheckoutButton.tsx
  • packages/shared/src/react/hooks/useCheckout.ts
  • packages/react/src/components/SubscriptionDetailsButton.tsx
packages/**/*.{ts,tsx,d.ts}

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

Packages should export TypeScript types alongside runtime code

Files:

  • packages/react/src/components/CheckoutButton.tsx
  • packages/shared/src/react/hooks/useCheckout.ts
  • packages/react/src/components/SubscriptionDetailsButton.tsx
**/*.{ts,tsx}

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

Use proper TypeScript error types

**/*.{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
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
Use protected for inheritance hierarchies
Use public explicitly for clarity in public APIs
Prefer readonly for properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Use const assertions for literal types: as const
Use satisfies operator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports: import type { ... } from ...
No any types without justification
Proper error handling with typed errors
Consistent use of readonly for immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)

Files:

  • packages/react/src/components/CheckoutButton.tsx
  • packages/shared/src/react/hooks/useCheckout.ts
  • packages/react/src/components/SubscriptionDetailsButton.tsx
**/*.{jsx,tsx}

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

**/*.{jsx,tsx}: Use error boundaries in React components
Minimize re-renders in React components

**/*.{jsx,tsx}: Always use functional components with hooks instead of class components
Follow PascalCase naming for components: 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
Use useState for simple state management
Use useReducer for complex state logic
Implement proper state initialization
Use proper state updates with callbacks
Implement proper state cleanup
Use Context API for theme/authentication
Implement proper state selectors
Use proper state normalization
Implement proper state persistence
Use React.memo for expensive components
Implement proper useCallback for handlers
Use proper useMemo for expensive computations
Implement proper virtualization for lists
Use proper code splitting with React.lazy
Implement proper cleanup in useEffect
Use proper refs for DOM access
Implement proper event listener cleanup
Use proper abort controllers for fetch
Implement proper subscription cleanup
Use proper HTML elements
Implement proper ARIA attributes
Use proper heading hierarchy
Implement proper form labels
Use proper button types
Implement proper focus management
Use proper keyboard shortcuts
Implement proper tab order
Use proper skip links
Implement proper focus traps
Implement proper error boundaries
Use proper error logging
Implement proper error recovery
Use proper error messages
Implement proper error fallbacks
Use proper form validation
Implement proper error states
Use proper error messages
Implement proper form submission
Use proper form reset
Use proper component naming
Implement proper file naming
Use proper prop naming
Implement proper...

Files:

  • packages/react/src/components/CheckoutButton.tsx
  • packages/react/src/components/SubscriptionDetailsButton.tsx
**/*.{js,ts,tsx,jsx}

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

Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.

Files:

  • packages/react/src/components/CheckoutButton.tsx
  • packages/shared/src/react/hooks/useCheckout.ts
  • packages/react/src/components/SubscriptionDetailsButton.tsx
**/*.tsx

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

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

Files:

  • packages/react/src/components/CheckoutButton.tsx
  • packages/react/src/components/SubscriptionDetailsButton.tsx
**/*

⚙️ 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.

Files:

  • packages/react/src/components/CheckoutButton.tsx
  • packages/shared/src/react/hooks/useCheckout.ts
  • packages/react/src/components/SubscriptionDetailsButton.tsx
.changeset/**

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

Automated releases must use Changesets.

Files:

  • .changeset/plain-bottles-press.md
⏰ 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). (6)
  • GitHub Check: Build Packages
  • GitHub Check: Formatting | Dedupe | Changeset
  • GitHub Check: semgrep/ci
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (4)
.changeset/plain-bottles-press.md (1)

1-7: Changeset scope and summary look good; patch bumps are appropriate.
Covers exactly the two packages touched by the messaging changes. No action needed.

packages/react/src/components/SubscriptionDetailsButton.tsx (1)

53-63: Incorrect standardization suggestion for active-organization guard
The SubscriptionDetailsButton (and its sibling CheckoutButton) live in packages/react/src/components, where we’ve consistently used useAuth().orgId to guard “organization”-scoped UI components. The useOrganization() pattern you’re seeing in packages/shared/src/react/hooks/ is part of our shared‐hooks layer, not the React-component layer in packages/react. These layers serve different purposes, so standardizing on useOrganization() in packages/react would break the established pattern. You can ignore this refactor suggestion.

Likely an incorrect or invalid review comment.

packages/shared/src/react/hooks/useCheckout.ts (2)

87-89: LGTM – improved guidance and SSR link add actionable recovery.
Message is clear and consistent with the active-organization precondition.


92-96: Dependency array looks correct; confirm intentional re-instantiation on org switch.
Recreating the checkout manager when organization?.id changes is likely desired. Flagging in case this should be keyed only by forOrganization === 'organization'.

If you want to guard against unnecessary manager churn when forOrganization !== 'organization', consider:

-    [user.id, organization?.id, planId, planPeriod, forOrganization],
+    [user.id, forOrganization === 'organization' ? organization?.id : undefined, planId, planPeriod, forOrganization],

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/components/__tests__/SubscriptionDetailsButton.test.tsx (1)

1-205: Update test assertions to include Clerk: prefix and SSR docs hint

The component implementations throw errors with a standardized Clerk: prefix (and include the SSR docs link for the organization case), but the tests are still asserting the old messages without these additions. Please update the tests accordingly:

• packages/react/src/components/tests/CheckoutButton.test.tsx

  • Change the toThrow assertion to expect the full prefix:
  • expect(() => render()).toThrow(
  • 'Ensure that <CheckoutButton /> is rendered inside a <SignedIn /> component.',
  • );
  • expect(() => render()).toThrow(
  • 'Clerk: Ensure that <CheckoutButton /> is rendered inside a <SignedIn /> component.',
  • );
    ```

• packages/react/src/components/tests/SubscriptionDetailsButton.test.tsx

  • For the unauthenticated user case, prepend Clerk: :
  • expect(() => render()).toThrow(
  • 'Ensure that <SubscriptionDetailsButton /> is rendered inside a <SignedIn /> component.',
  • );
  • expect(() => render()).toThrow(
  • 'Clerk: Ensure that <SubscriptionDetailsButton /> is rendered inside a <SignedIn /> component.',
  • );
    ```
  • For the organization-case error, include the prefix and the SSR docs hint:
  • expect(() => render()).toThrow(
  • 'Wrap <SubscriptionDetailsButton for="organization" /> with a check for an active organization. Retrieve orgId from useAuth() and confirm it is defined.',
  • );

These updates will keep the tests in sync with the component’s standardized error messages.

🧹 Nitpick comments (7)
packages/react/src/components/__tests__/SubscriptionDetailsButton.test.tsx (3)

59-60: Assert the full, standardized error message (prefix + SSR link) or match via regex

Runtime now prefixes with "Clerk:" and appends an SSR docs link. The test currently asserts only the middle sentence. Strengthen it to verify the standardized prefix and guidance to avoid regressions.

Apply one of the following:

Option A — assert the full message via regex (robust to minor whitespace):

-      expect(() => render(<SubscriptionDetailsButton for='organization' />)).toThrow(
-        'Wrap `<SubscriptionDetailsButton for="organization" />` with a check for an active organization. Retrieve `orgId` from `useAuth()` and confirm it is defined.',
-      );
+      expect(() => render(<SubscriptionDetailsButton for='organization' />)).toThrow(
+        /Clerk:\s*Wrap `<SubscriptionDetailsButton for="organization" \/>` .* Retrieve `orgId` from `useAuth\(\)` and confirm it is defined\.\s*For SSR, see:/,
+      );

Option B — if you prefer substring semantics, at least include the "Clerk: " prefix:

-      expect(() => render(<SubscriptionDetailsButton for='organization' />)).toThrow(
-        'Wrap `<SubscriptionDetailsButton for="organization" />` with a check for an active organization. Retrieve `orgId` from `useAuth()` and confirm it is defined.',
-      );
+      expect(() => render(<SubscriptionDetailsButton for='organization' />)).toThrow(
+        'Clerk: Wrap `<SubscriptionDetailsButton for="organization" />` with a check for an active organization. Retrieve `orgId` from `useAuth()` and confirm it is defined.',
+      );

43-51: Align the “missing sign-in” expectation with the new "Clerk:" prefix

The runtime message is now prefixed with "Clerk:". Either assert the prefix explicitly or use a regex.

-      expect(() => render(<SubscriptionDetailsButton />)).toThrow(
-        'Ensure that `<SubscriptionDetailsButton />` is rendered inside a `<SignedIn />` component.',
-      );
+      expect(() => render(<SubscriptionDetailsButton />)).toThrow(
+        /Clerk:\s*Ensure that `<SubscriptionDetailsButton \/>` is rendered inside a `<SignedIn \/>` component\./,
+      );

53-54: Update test name to match public prop naming

Rename to refer to for="organization" instead of “org subscriber type” for clarity and consistency with docs.

-    it('throws error when using org subscriber type without active organization', () => {
+    it('throws error when for="organization" is used without an active organization', () => {
packages/react/src/components/__tests__/CheckoutButton.test.tsx (2)

65-67: Ensure the test matches the standardized message (prefix + SSR link) or use regex

The component now throws a message prefixed by "Clerk:" and ending with an SSR docs link. Tighten the assertion to avoid future drift.

-      ).toThrow(
-        'Wrap `<CheckoutButton for="organization" />` with a check for an active organization. Retrieve `orgId` from `useAuth()` and confirm it is defined.',
-      );
+      ).toThrow(
+        /Clerk:\s*Wrap `<CheckoutButton for="organization" \/>` .* Retrieve `orgId` from `useAuth\(\)` and confirm it is defined\.\s*For SSR, see:/,
+      );

If you deliberately prefer substring semantics, at least include the "Clerk: " prefix:

-      ).toThrow(
-        'Wrap `<CheckoutButton for="organization" />` with a check for an active organization. Retrieve `orgId` from `useAuth()` and confirm it is defined.',
-      );
+      ).toThrow(
+        'Clerk: Wrap `<CheckoutButton for="organization" />` with a check for an active organization. Retrieve `orgId` from `useAuth()` and confirm it is defined.',
+      );

48-51: Align the sign-in error expectation with the "Clerk:" prefix

Runtime message is now prefixed; reflect that in the test or use regex to match the prefix.

-      expect(() => render(<CheckoutButton planId='test_plan' />)).toThrow(
-        'Ensure that `<CheckoutButton />` is rendered inside a `<SignedIn />` component.',
-      );
+      expect(() => render(<CheckoutButton planId='test_plan' />)).toThrow(
+        /Clerk:\s*Ensure that `<CheckoutButton \/>` is rendered inside a `<SignedIn \/>` component\./,
+      );
packages/react/src/components/CheckoutButton.tsx (2)

45-46: Extend @throws JSDoc to mirror runtime guidance

Runtime error includes actionable steps (retrieve orgId via useAuth and an SSR docs link). Consider mirroring that here to keep API docs self-contained.

- * @throws {Error} When `for="organization"` is used without an active organization context
+ * @throws {Error} When `for="organization"` is used without an active organization context.
+ * Retrieve `orgId` from `useAuth()` and confirm it is defined. For SSR, see:
+ * https://clerk.com/docs/references/backend/types/auth-object#how-to-access-the-auth-object

66-68: Deduplicate and centralize this error message to avoid drift across components/hooks

The same organization-required guidance appears here and in other places (e.g., SubscriptionDetailsButton, useCheckout). Consider a shared constant or helper to ensure consistency.

Apply this minimal refactor:

In this file (top-level, near imports), add:

// Keep in sync with other components/hooks
const ORG_REQUIRED_ERROR_MESSAGE =
  'Clerk: Wrap `<CheckoutButton for="organization" />` with a check for an active organization. ' +
  'Retrieve `orgId` from `useAuth()` and confirm it is defined. For SSR, see: ' +
  'https://clerk.com/docs/references/backend/types/auth-object#how-to-access-the-auth-object' as const;

Then replace the inline string:

-      throw new Error(
-        'Clerk: Wrap `<CheckoutButton for="organization" />` with a check for an active organization. Retrieve `orgId` from `useAuth()` and confirm it is defined. For SSR, see: https://clerk.com/docs/references/backend/types/auth-object#how-to-access-the-auth-object',
-      );
+      throw new Error(ORG_REQUIRED_ERROR_MESSAGE);

Optionally, promote this constant to a shared package (e.g., @clerk/shared) so both components and hooks reuse the same source of truth.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled
  • 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 b3a9ff6 and 06f76bf.

📒 Files selected for processing (4)
  • packages/react/src/components/CheckoutButton.tsx (3 hunks)
  • packages/react/src/components/SubscriptionDetailsButton.tsx (3 hunks)
  • packages/react/src/components/__tests__/CheckoutButton.test.tsx (1 hunks)
  • packages/react/src/components/__tests__/SubscriptionDetailsButton.test.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/react/src/components/SubscriptionDetailsButton.tsx
🧰 Additional context used
📓 Path-based instructions (12)
**/*.{js,jsx,ts,tsx}

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

**/*.{js,jsx,ts,tsx}: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
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
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels

Files:

  • packages/react/src/components/__tests__/SubscriptionDetailsButton.test.tsx
  • packages/react/src/components/__tests__/CheckoutButton.test.tsx
  • packages/react/src/components/CheckoutButton.tsx
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}

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

Use Prettier for consistent code formatting

Files:

  • packages/react/src/components/__tests__/SubscriptionDetailsButton.test.tsx
  • packages/react/src/components/__tests__/CheckoutButton.test.tsx
  • packages/react/src/components/CheckoutButton.tsx
packages/**/*.{ts,tsx}

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

TypeScript is required for all packages

Files:

  • packages/react/src/components/__tests__/SubscriptionDetailsButton.test.tsx
  • packages/react/src/components/__tests__/CheckoutButton.test.tsx
  • packages/react/src/components/CheckoutButton.tsx
packages/**/*.{ts,tsx,d.ts}

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

Packages should export TypeScript types alongside runtime code

Files:

  • packages/react/src/components/__tests__/SubscriptionDetailsButton.test.tsx
  • packages/react/src/components/__tests__/CheckoutButton.test.tsx
  • packages/react/src/components/CheckoutButton.tsx
**/*.{ts,tsx}

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

Use proper TypeScript error types

**/*.{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
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
Use protected for inheritance hierarchies
Use public explicitly for clarity in public APIs
Prefer readonly for properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Use const assertions for literal types: as const
Use satisfies operator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports: import type { ... } from ...
No any types without justification
Proper error handling with typed errors
Consistent use of readonly for immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)

Files:

  • packages/react/src/components/__tests__/SubscriptionDetailsButton.test.tsx
  • packages/react/src/components/__tests__/CheckoutButton.test.tsx
  • packages/react/src/components/CheckoutButton.tsx
**/*.{jsx,tsx}

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

**/*.{jsx,tsx}: Use error boundaries in React components
Minimize re-renders in React components

**/*.{jsx,tsx}: Always use functional components with hooks instead of class components
Follow PascalCase naming for components: 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
Use useState for simple state management
Use useReducer for complex state logic
Implement proper state initialization
Use proper state updates with callbacks
Implement proper state cleanup
Use Context API for theme/authentication
Implement proper state selectors
Use proper state normalization
Implement proper state persistence
Use React.memo for expensive components
Implement proper useCallback for handlers
Use proper useMemo for expensive computations
Implement proper virtualization for lists
Use proper code splitting with React.lazy
Implement proper cleanup in useEffect
Use proper refs for DOM access
Implement proper event listener cleanup
Use proper abort controllers for fetch
Implement proper subscription cleanup
Use proper HTML elements
Implement proper ARIA attributes
Use proper heading hierarchy
Implement proper form labels
Use proper button types
Implement proper focus management
Use proper keyboard shortcuts
Implement proper tab order
Use proper skip links
Implement proper focus traps
Implement proper error boundaries
Use proper error logging
Implement proper error recovery
Use proper error messages
Implement proper error fallbacks
Use proper form validation
Implement proper error states
Use proper error messages
Implement proper form submission
Use proper form reset
Use proper component naming
Implement proper file naming
Use proper prop naming
Implement proper...

Files:

  • packages/react/src/components/__tests__/SubscriptionDetailsButton.test.tsx
  • packages/react/src/components/__tests__/CheckoutButton.test.tsx
  • packages/react/src/components/CheckoutButton.tsx
packages/**/*.{test,spec}.{js,jsx,ts,tsx}

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

Unit tests should use Jest or Vitest as the test runner.

Files:

  • packages/react/src/components/__tests__/SubscriptionDetailsButton.test.tsx
  • packages/react/src/components/__tests__/CheckoutButton.test.tsx
**/*.{js,ts,tsx,jsx}

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

Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.

Files:

  • packages/react/src/components/__tests__/SubscriptionDetailsButton.test.tsx
  • packages/react/src/components/__tests__/CheckoutButton.test.tsx
  • packages/react/src/components/CheckoutButton.tsx
**/*.tsx

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

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

Files:

  • packages/react/src/components/__tests__/SubscriptionDetailsButton.test.tsx
  • packages/react/src/components/__tests__/CheckoutButton.test.tsx
  • packages/react/src/components/CheckoutButton.tsx
**/*.test.{jsx,tsx}

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

**/*.test.{jsx,tsx}: Use React Testing Library
Test component behavior, not implementation
Use proper test queries
Implement proper test isolation
Use proper test coverage
Test component interactions
Use proper test data
Implement proper test setup
Use proper test cleanup
Implement proper test assertions
Use proper test structure

Files:

  • packages/react/src/components/__tests__/SubscriptionDetailsButton.test.tsx
  • packages/react/src/components/__tests__/CheckoutButton.test.tsx
**/__tests__/**/*.{ts,tsx}

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

**/__tests__/**/*.{ts,tsx}: Create type-safe test builders/factories
Use branded types for test isolation
Implement proper mock types that match interfaces

Files:

  • packages/react/src/components/__tests__/SubscriptionDetailsButton.test.tsx
  • packages/react/src/components/__tests__/CheckoutButton.test.tsx
**/*

⚙️ 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.

Files:

  • packages/react/src/components/__tests__/SubscriptionDetailsButton.test.tsx
  • packages/react/src/components/__tests__/CheckoutButton.test.tsx
  • packages/react/src/components/CheckoutButton.tsx
⏰ 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). (6)
  • GitHub Check: Build Packages
  • GitHub Check: Formatting | Dedupe | Changeset
  • GitHub Check: semgrep/ci
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (2)
packages/react/src/components/CheckoutButton.tsx (2)

35-35: Docs example update to for="organization" looks good

Switch to for="organization" aligns with current public API and reduces confusion vs. older “org” terminology.


61-63: Good: standardized "Clerk:" prefix for missing sign-in

Consistent prefix improves DX and makes logs easily searchable.

@panteliselef panteliselef merged commit a26ecae into main Aug 22, 2025
39 checks passed
@panteliselef panteliselef deleted the elef/improve-for-orgs-error branch August 22, 2025 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants