-
Notifications
You must be signed in to change notification settings - Fork 408
chore(clerk-react,shared): Improve assertion error for requiring active organization #6606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest commit: 06f76bf The changes in this PR will be included in the next version bump. This PR includes changesets to release 19 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
@clerk/agent-toolkit
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/dev-cli
@clerk/elements
@clerk/clerk-expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/clerk-react
@clerk/react-router
@clerk/remix
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/themes
@clerk/types
@clerk/upgrade
@clerk/vue
commit: |
📝 WalkthroughWalkthroughAdds 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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 propsubscriberType="org"; code usesfor="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 mentionssubscriberType="org"; should reflectfor="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 theorgIdguard to catchundefinedas well asnull
TheuseAuth()return type (inpackages/types/src/hooks.ts) showsorgIdmay beundefined(initial load) ornull(no active organization). The current check only handlesnull, so anundefinedorgIdwould 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 == nullcovers bothnullandundefined.
Alternatively, an explicit check works too:if (_for === 'organization' && (orgId === null || orgId === undefined)) { … }packages/react/src/components/SubscriptionDetailsButton.tsx (2)
28-33: Docs example usesfor="org"; runtime and other messages usefor="organization".
Unify tofor="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 sayfor="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.
useCheckouterrors are prefixed withClerk: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 withuseCheckout’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.
📒 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.tsxpackages/shared/src/react/hooks/useCheckout.tspackages/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.tsxpackages/shared/src/react/hooks/useCheckout.tspackages/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.tsxpackages/shared/src/react/hooks/useCheckout.tspackages/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.tsxpackages/shared/src/react/hooks/useCheckout.tspackages/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
Avoidanytype - preferunknownwhen type is uncertain, then narrow with type guards
Useinterfacefor object shapes that might be extended
Usetypefor unions, primitives, and computed types
Preferreadonlyproperties for immutable data structures
Useprivatefor internal implementation details
Useprotectedfor inheritance hierarchies
Usepublicexplicitly for clarity in public APIs
Preferreadonlyfor 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
Useconst assertionsfor literal types:as const
Usesatisfiesoperator 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 ...
Noanytypes without justification
Proper error handling with typed errors
Consistent use ofreadonlyfor 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.tsxpackages/shared/src/react/hooks/useCheckout.tspackages/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.tsxpackages/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.tsxpackages/shared/src/react/hooks/useCheckout.tspackages/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.tsxpackages/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.tsxpackages/shared/src/react/hooks/useCheckout.tspackages/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
TheSubscriptionDetailsButton(and its siblingCheckoutButton) live in packages/react/src/components, where we’ve consistently useduseAuth().orgIdto guard “organization”-scoped UI components. TheuseOrganization()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 onuseOrganization()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 whenorganization?.idchanges is likely desired. Flagging in case this should be keyed only byforOrganization === '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],
There was a problem hiding this 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 includeClerk:prefix and SSR docs hintThe 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
toThrowassertion 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. RetrieveorgIdfromuseAuth()and confirm it is defined.',- );
- expect(() => render()).toThrow(
- 'Clerk: Wrap
<SubscriptionDetailsButton for="organization" />with a check for an active organization. RetrieveorgIdfromuseAuth()and confirm it is defined. For SSR, see: https://clerk.com/docs/references/backend/types/auth-object#how-to-access-the-auth-object',- );
```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 regexRuntime 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:" prefixThe 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 namingRename 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 regexThe 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:" prefixRuntime 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 guidanceRuntime 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/hooksThe 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.
📒 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.tsxpackages/react/src/components/__tests__/CheckoutButton.test.tsxpackages/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.tsxpackages/react/src/components/__tests__/CheckoutButton.test.tsxpackages/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.tsxpackages/react/src/components/__tests__/CheckoutButton.test.tsxpackages/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.tsxpackages/react/src/components/__tests__/CheckoutButton.test.tsxpackages/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
Avoidanytype - preferunknownwhen type is uncertain, then narrow with type guards
Useinterfacefor object shapes that might be extended
Usetypefor unions, primitives, and computed types
Preferreadonlyproperties for immutable data structures
Useprivatefor internal implementation details
Useprotectedfor inheritance hierarchies
Usepublicexplicitly for clarity in public APIs
Preferreadonlyfor 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
Useconst assertionsfor literal types:as const
Usesatisfiesoperator 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 ...
Noanytypes without justification
Proper error handling with typed errors
Consistent use ofreadonlyfor 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.tsxpackages/react/src/components/__tests__/CheckoutButton.test.tsxpackages/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.tsxpackages/react/src/components/__tests__/CheckoutButton.test.tsxpackages/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.tsxpackages/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.tsxpackages/react/src/components/__tests__/CheckoutButton.test.tsxpackages/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.tsxpackages/react/src/components/__tests__/CheckoutButton.test.tsxpackages/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.tsxpackages/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.tsxpackages/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.tsxpackages/react/src/components/__tests__/CheckoutButton.test.tsxpackages/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 goodSwitch to for="organization" aligns with current public API and reduces confusion vs. older “org” terminology.
61-63: Good: standardized "Clerk:" prefix for missing sign-inConsistent prefix improves DX and makes logs easily searchable.
Description
Checklist
pnpm testruns as expected.pnpm buildruns as expected.Type of change
Summary by CodeRabbit
Documentation
Chores
Tests