Skip to content

feat(clerk-react, nextjs): Introduce commerce buttons #6365

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

Merged
merged 12 commits into from
Jul 23, 2025

Conversation

panteliselef
Copy link
Member

@panteliselef panteliselef commented Jul 21, 2025

Description

This PR introduces the /experimental submodule, and exports <CheckoutButton/>, <SubscriptionDetailsButton/>, <PlanDetailsButton/> from it.

For react

import {
    CheckoutButton,
    SubscriptionDetailsButton,
    PlanDetailsButton,
} from "@clerk/clerk-react/experimental";

For Next.js

import {
    CheckoutButton,
    SubscriptionDetailsButton,
    PlanDetailsButton,
} from "@clerk/nextjs/experimental";

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

  • New Features

    • Introduced three new components—CheckoutButton, SubscriptionDetailsButton, and PlanDetailsButton—available in both @clerk/clerk-react and @clerk/nextjs packages.
    • These components enhance subscription management and checkout experiences within your applications.
  • Chores

    • Updated package exports and build configurations to support the new components and ensure proper module resolution.
  • Tests

    • Added comprehensive test suites for CheckoutButton, SubscriptionDetailsButton, and PlanDetailsButton components to ensure reliable behavior across authentication states and user interactions.

Copy link

vercel bot commented Jul 21, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
clerk-js-sandbox ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 23, 2025 4:20pm

Copy link

changeset-bot bot commented Jul 21, 2025

🦋 Changeset detected

Latest commit: 25e58e9

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

This PR includes changesets to release 8 packages
Name Type
@clerk/clerk-react Minor
@clerk/nextjs Minor
@clerk/chrome-extension Patch
@clerk/elements Patch
@clerk/clerk-expo Patch
@clerk/react-router Patch
@clerk/remix Patch
@clerk/tanstack-react-start 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

@panteliselef
Copy link
Member Author

!snapshot

@clerk-cookie
Copy link
Collaborator

Hey @panteliselef - the snapshot version command generated the following package versions:

Package Version
@clerk/agent-toolkit 0.1.12-snapshot.v20250722091530
@clerk/astro 2.10.9-snapshot.v20250722091530
@clerk/backend 2.5.1-snapshot.v20250722091530
@clerk/chrome-extension 2.5.11-snapshot.v20250722091530
@clerk/clerk-js 5.75.0-snapshot.v20250722091530
@clerk/elements 0.23.44-snapshot.v20250722091530
@clerk/clerk-expo 2.14.10-snapshot.v20250722091530
@clerk/expo-passkeys 0.3.21-snapshot.v20250722091530
@clerk/express 1.7.11-snapshot.v20250722091530
@clerk/fastify 2.4.11-snapshot.v20250722091530
@clerk/localizations 3.20.2-snapshot.v20250722091530
@clerk/nextjs 6.25.5-snapshot.v20250722091530
@clerk/nuxt 1.7.12-snapshot.v20250722091530
@clerk/clerk-react 5.35.4-snapshot.v20250722091530
@clerk/react-router 1.8.5-snapshot.v20250722091530
@clerk/remix 4.10.5-snapshot.v20250722091530
@clerk/shared 3.13.1-snapshot.v20250722091530
@clerk/tanstack-react-start 0.21.1-snapshot.v20250722091530
@clerk/testing 1.10.5-snapshot.v20250722091530
@clerk/themes 2.3.4-snapshot.v20250722091530
@clerk/types 4.69.0-snapshot.v20250722091530
@clerk/vue 1.8.19-snapshot.v20250722091530

Tip: Use the snippet copy button below to quickly install the required packages.
@clerk/agent-toolkit

npm i @clerk/agent-toolkit@0.1.12-snapshot.v20250722091530 --save-exact

@clerk/astro

npm i @clerk/astro@2.10.9-snapshot.v20250722091530 --save-exact

@clerk/backend

npm i @clerk/backend@2.5.1-snapshot.v20250722091530 --save-exact

@clerk/chrome-extension

npm i @clerk/chrome-extension@2.5.11-snapshot.v20250722091530 --save-exact

@clerk/clerk-js

npm i @clerk/clerk-js@5.75.0-snapshot.v20250722091530 --save-exact

@clerk/elements

npm i @clerk/elements@0.23.44-snapshot.v20250722091530 --save-exact

@clerk/clerk-expo

npm i @clerk/clerk-expo@2.14.10-snapshot.v20250722091530 --save-exact

@clerk/expo-passkeys

npm i @clerk/expo-passkeys@0.3.21-snapshot.v20250722091530 --save-exact

@clerk/express

npm i @clerk/express@1.7.11-snapshot.v20250722091530 --save-exact

@clerk/fastify

npm i @clerk/fastify@2.4.11-snapshot.v20250722091530 --save-exact

@clerk/localizations

npm i @clerk/localizations@3.20.2-snapshot.v20250722091530 --save-exact

@clerk/nextjs

npm i @clerk/nextjs@6.25.5-snapshot.v20250722091530 --save-exact

@clerk/nuxt

npm i @clerk/nuxt@1.7.12-snapshot.v20250722091530 --save-exact

@clerk/clerk-react

npm i @clerk/clerk-react@5.35.4-snapshot.v20250722091530 --save-exact

@clerk/react-router

npm i @clerk/react-router@1.8.5-snapshot.v20250722091530 --save-exact

@clerk/remix

npm i @clerk/remix@4.10.5-snapshot.v20250722091530 --save-exact

@clerk/shared

npm i @clerk/shared@3.13.1-snapshot.v20250722091530 --save-exact

@clerk/tanstack-react-start

npm i @clerk/tanstack-react-start@0.21.1-snapshot.v20250722091530 --save-exact

@clerk/testing

npm i @clerk/testing@1.10.5-snapshot.v20250722091530 --save-exact

@clerk/themes

npm i @clerk/themes@2.3.4-snapshot.v20250722091530 --save-exact

@clerk/types

npm i @clerk/types@4.69.0-snapshot.v20250722091530 --save-exact

@clerk/vue

npm i @clerk/vue@1.8.19-snapshot.v20250722091530 --save-exact

@panteliselef panteliselef marked this pull request as ready for review July 22, 2025 10:38
Copy link
Contributor

coderabbitai bot commented Jul 22, 2025

📝 Walkthrough

Walkthrough

This change introduces three new React components—CheckoutButton, SubscriptionDetailsButton, and PlanDetailsButton—to the @clerk/clerk-react package, each implementing authentication validation, event handling, and single-child element enforcement. These components are re-exported via a new experimental module in both @clerk/clerk-react and @clerk/nextjs packages. Corresponding updates to the package.json files add new export subpaths for these experimental modules, including type declarations and module entry points. The React package build configuration is extended with an "experimental" entry point. The utility function assertSingleChild is updated to recognize the new component names. Comprehensive test suites are added for all three components, covering rendering, authentication checks, event handling, and portal-related props. Additionally, new experimental TypeScript types for these billing UI components are added in the types package, along with a minor JSDoc formatting correction.

Estimated code review effort

3 (~45 minutes)


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 25e58e9 and 8f29cb4.

📒 Files selected for processing (2)
  • 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 (2)
  • packages/react/src/components/tests/CheckoutButton.test.tsx
  • packages/react/src/components/tests/SubscriptionDetailsButton.test.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). (2)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: Analyze (javascript-typescript)

🪧 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.
    • Explain this complex logic.
    • 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. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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

Documentation and Community

  • 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: 2

🧹 Nitpick comments (7)
packages/nextjs/src/experimental.ts (1)

1-4: Consider re-exporting the component types as well

Down-stream TypeScript users often reach for the prop types:

import type { CheckoutButtonProps } from '@clerk/nextjs/experimental';

At the moment only the runtime values are re-exported, so the above import fails.
If the underlying React components already export type …Props, surface them here:

-'use client';

-export { CheckoutButton, PlanDetailsButton, SubscriptionDetailsButton } from '@clerk/clerk-react/experimental';
+'use client';
+
+export {
+  CheckoutButton,
+  PlanDetailsButton,
+  SubscriptionDetailsButton,
+} from '@clerk/clerk-react/experimental';
+
+export type {
+  CheckoutButtonProps,
+  PlanDetailsButtonProps,
+  SubscriptionDetailsButtonProps,
+} from '@clerk/clerk-react/experimental';
packages/react/src/experimental.ts (1)

1-4: Add 'use client'; for Next.js friendliness

Although this file only re-exports, Next.js treats the presence of the directive as a signal that the module is client-safe, avoiding “Server Component” warnings when users import directly.

+// Re-export experimental client-side components
+'use client';
 export { CheckoutButton } from './components/CheckoutButton';
 export { PlanDetailsButton } from './components/PlanDetailsButton';
 export { SubscriptionDetailsButton } from './components/SubscriptionDetailsButton';
packages/react/src/components/PlanDetailsButton.tsx (2)

1-42: Implementation follows established Clerk button patterns.

The component correctly implements the standard Clerk button pattern with:

  • Proper TypeScript typing using __internal_PlanDetailsProps
  • Single-child validation via assertSingleChild
  • Safe event handler composition with safeExecute
  • Consistent prop destructuring and spreading
  • Appropriate HOC configuration

Consider security review for commerce functionality.

Since this introduces commerce-related functionality that calls internal Clerk methods for plan management, please consider tagging the clerk security team to review these changes for any security implications.

Add tests for the new component.

Per the coding guidelines, tests should be added to cover the new functionality.

Would you like me to generate unit tests for this component or open an issue to track this task?


39-39: Improve type safety of React element clone.

The type assertion as React.ReactElement<unknown> could be more precise.

-    return React.cloneElement(child as React.ReactElement<unknown>, childProps);
+    return React.cloneElement(child as React.ReactElement, childProps);
packages/react/src/components/SubscriptionDetailsButton.tsx (2)

11-54: Implementation follows established patterns with proper auth validation.

The component correctly implements the Clerk button pattern with additional auth validation. The structure is consistent with PlanDetailsButton and other Clerk components.

Consider security review for commerce functionality.

This component manages subscription details and includes cancellation functionality. Please consider tagging the clerk security team to review these commerce-related changes.

Add tests for the new component.

Tests should be added to cover the auth validation logic and component functionality per coding guidelines.

Would you like me to generate unit tests including the auth validation scenarios?


51-51: Improve type safety of React element clone.

The type assertion could be more precise, consistent with TypeScript best practices.

-    return React.cloneElement(child as React.ReactElement<unknown>, childProps);
+    return React.cloneElement(child as React.ReactElement, childProps);
packages/react/src/components/CheckoutButton.tsx (1)

1-10: Add JSDoc documentation for the re-exported type.

The imports and type structure look good, but the re-exported __internal_CheckoutProps type should have JSDoc documentation to explain its purpose for external consumers.

+/**
+ * Props for configuring checkout behavior and callbacks.
+ * @internal This is an internal type that may change without notice.
+ */
 export type { __internal_CheckoutProps };
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e5ba060 and 216b929.

📒 Files selected for processing (11)
  • .changeset/curly-jeans-sleep.md (1 hunks)
  • .changeset/dark-coins-shake.md (1 hunks)
  • packages/nextjs/package.json (1 hunks)
  • packages/nextjs/src/experimental.ts (1 hunks)
  • packages/react/package.json (1 hunks)
  • packages/react/src/components/CheckoutButton.tsx (1 hunks)
  • packages/react/src/components/PlanDetailsButton.tsx (1 hunks)
  • packages/react/src/components/SubscriptionDetailsButton.tsx (1 hunks)
  • packages/react/src/experimental.ts (1 hunks)
  • packages/react/src/utils/childrenUtils.tsx (1 hunks)
  • packages/react/tsup.config.ts (1 hunks)
📓 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/tsup.config.ts
  • packages/nextjs/src/experimental.ts
  • packages/react/src/experimental.ts
  • packages/react/src/utils/childrenUtils.tsx
  • packages/react/src/components/PlanDetailsButton.tsx
  • packages/react/src/components/SubscriptionDetailsButton.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/tsup.config.ts
  • packages/nextjs/src/experimental.ts
  • packages/react/src/experimental.ts
  • packages/nextjs/package.json
  • packages/react/src/utils/childrenUtils.tsx
  • packages/react/package.json
  • packages/react/src/components/PlanDetailsButton.tsx
  • packages/react/src/components/SubscriptionDetailsButton.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/tsup.config.ts
  • packages/nextjs/src/experimental.ts
  • packages/react/src/experimental.ts
  • packages/react/src/utils/childrenUtils.tsx
  • packages/react/src/components/PlanDetailsButton.tsx
  • packages/react/src/components/SubscriptionDetailsButton.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/tsup.config.ts
  • packages/nextjs/src/experimental.ts
  • packages/react/src/experimental.ts
  • packages/react/src/utils/childrenUtils.tsx
  • packages/react/src/components/PlanDetailsButton.tsx
  • packages/react/src/components/SubscriptionDetailsButton.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/tsup.config.ts
  • packages/nextjs/src/experimental.ts
  • packages/react/src/experimental.ts
  • packages/react/src/utils/childrenUtils.tsx
  • packages/react/src/components/PlanDetailsButton.tsx
  • packages/react/src/components/SubscriptionDetailsButton.tsx
  • packages/react/src/components/CheckoutButton.tsx
packages/*/tsup.config.{js,ts}

📄 CodeRabbit Inference Engine (.cursor/rules/monorepo.mdc)

TypeScript compilation and bundling must use tsup.

Files:

  • packages/react/tsup.config.ts
**/*.{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/tsup.config.ts
  • packages/nextjs/src/experimental.ts
  • packages/react/src/experimental.ts
  • packages/react/src/utils/childrenUtils.tsx
  • packages/react/src/components/PlanDetailsButton.tsx
  • packages/react/src/components/SubscriptionDetailsButton.tsx
  • packages/react/src/components/CheckoutButton.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.

Whenever reviewing a pull request, if there are any changes that could impact security, always tag clerk/security in the PR.

Security-impacting changes include, but are not limited to:

  • Changes to authentication logic or mechanisms (e.g. login, session handling, token issuance)
  • Any modification to access control, authorization checks, or role-based permissions
  • Introduction or modification of hashing algorithms, signature verification, or cryptographic primitives
  • Handling of sensitive data (e.g. passwords, tokens, secrets, PII)
  • Integration with external identity providers (e.g. SSO, OAuth, OpenID Connect)
  • Modifications to security headers, cookie flags, CORS policies, or CSRF protections
  • Bypass mechanisms (e.g. feature flags, testing overrides) that could weaken protections
  • Changes to rate limiting, abuse prevention, or input validation

If you're unsure whether a change is security-relevant, err on the side of caution and tag clerk/security.

Any time that you tag clerk/security, please do so explicitly in a code comment, rather than within a collapsed section in a coderabbit comment, such as the "recent review details" section. If you do use the team name in any thinking or non-direct-code-comment content, it can be referred to as "clerk security team" to avoid accidentally printing the tag which sends a notification to the team.

Files:

  • packages/react/tsup.config.ts
  • packages/nextjs/src/experimental.ts
  • packages/react/src/experimental.ts
  • packages/nextjs/package.json
  • packages/react/src/utils/childrenUtils.tsx
  • packages/react/package.json
  • packages/react/src/components/PlanDetailsButton.tsx
  • packages/react/src/components/SubscriptionDetailsButton.tsx
  • packages/react/src/components/CheckoutButton.tsx
.changeset/**

📄 CodeRabbit Inference Engine (.cursor/rules/monorepo.mdc)

Automated releases must use Changesets.

Files:

  • .changeset/curly-jeans-sleep.md
  • .changeset/dark-coins-shake.md
packages/*/package.json

📄 CodeRabbit Inference Engine (.cursor/rules/global.mdc)

All publishable packages should be placed under the packages/ directory

packages/*/package.json: All publishable packages must be located in the 'packages/' directory.
All packages must be published under the @clerk namespace on npm.
Semantic versioning must be used across all packages.

Files:

  • packages/nextjs/package.json
  • packages/react/package.json
**/*.{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/utils/childrenUtils.tsx
  • packages/react/src/components/PlanDetailsButton.tsx
  • packages/react/src/components/SubscriptionDetailsButton.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/utils/childrenUtils.tsx
  • packages/react/src/components/PlanDetailsButton.tsx
  • packages/react/src/components/SubscriptionDetailsButton.tsx
  • packages/react/src/components/CheckoutButton.tsx
🧬 Code Graph Analysis (3)
packages/react/src/components/PlanDetailsButton.tsx (3)
packages/react/src/components/withClerk.tsx (1)
  • withClerk (7-37)
packages/react/src/types.ts (1)
  • WithClerkProp (73-73)
packages/react/src/utils/childrenUtils.tsx (3)
  • normalizeWithDefaultValue (25-33)
  • assertSingleChild (6-23)
  • safeExecute (35-41)
packages/react/src/components/SubscriptionDetailsButton.tsx (3)
packages/react/src/components/withClerk.tsx (1)
  • withClerk (7-37)
packages/react/src/types.ts (1)
  • WithClerkProp (73-73)
packages/react/src/utils/childrenUtils.tsx (3)
  • normalizeWithDefaultValue (25-33)
  • assertSingleChild (6-23)
  • safeExecute (35-41)
packages/react/src/components/CheckoutButton.tsx (3)
packages/react/src/components/withClerk.tsx (1)
  • withClerk (7-37)
packages/react/src/types.ts (1)
  • WithClerkProp (73-73)
packages/react/src/utils/childrenUtils.tsx (3)
  • normalizeWithDefaultValue (25-33)
  • assertSingleChild (6-23)
  • safeExecute (35-41)
🧰 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/tsup.config.ts
  • packages/nextjs/src/experimental.ts
  • packages/react/src/experimental.ts
  • packages/react/src/utils/childrenUtils.tsx
  • packages/react/src/components/PlanDetailsButton.tsx
  • packages/react/src/components/SubscriptionDetailsButton.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/tsup.config.ts
  • packages/nextjs/src/experimental.ts
  • packages/react/src/experimental.ts
  • packages/nextjs/package.json
  • packages/react/src/utils/childrenUtils.tsx
  • packages/react/package.json
  • packages/react/src/components/PlanDetailsButton.tsx
  • packages/react/src/components/SubscriptionDetailsButton.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/tsup.config.ts
  • packages/nextjs/src/experimental.ts
  • packages/react/src/experimental.ts
  • packages/react/src/utils/childrenUtils.tsx
  • packages/react/src/components/PlanDetailsButton.tsx
  • packages/react/src/components/SubscriptionDetailsButton.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/tsup.config.ts
  • packages/nextjs/src/experimental.ts
  • packages/react/src/experimental.ts
  • packages/react/src/utils/childrenUtils.tsx
  • packages/react/src/components/PlanDetailsButton.tsx
  • packages/react/src/components/SubscriptionDetailsButton.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/tsup.config.ts
  • packages/nextjs/src/experimental.ts
  • packages/react/src/experimental.ts
  • packages/react/src/utils/childrenUtils.tsx
  • packages/react/src/components/PlanDetailsButton.tsx
  • packages/react/src/components/SubscriptionDetailsButton.tsx
  • packages/react/src/components/CheckoutButton.tsx
packages/*/tsup.config.{js,ts}

📄 CodeRabbit Inference Engine (.cursor/rules/monorepo.mdc)

TypeScript compilation and bundling must use tsup.

Files:

  • packages/react/tsup.config.ts
**/*.{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/tsup.config.ts
  • packages/nextjs/src/experimental.ts
  • packages/react/src/experimental.ts
  • packages/react/src/utils/childrenUtils.tsx
  • packages/react/src/components/PlanDetailsButton.tsx
  • packages/react/src/components/SubscriptionDetailsButton.tsx
  • packages/react/src/components/CheckoutButton.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.

Whenever reviewing a pull request, if there are any changes that could impact security, always tag clerk/security in the PR.

Security-impacting changes include, but are not limited to:

  • Changes to authentication logic or mechanisms (e.g. login, session handling, token issuance)
  • Any modification to access control, authorization checks, or role-based permissions
  • Introduction or modification of hashing algorithms, signature verification, or cryptographic primitives
  • Handling of sensitive data (e.g. passwords, tokens, secrets, PII)
  • Integration with external identity providers (e.g. SSO, OAuth, OpenID Connect)
  • Modifications to security headers, cookie flags, CORS policies, or CSRF protections
  • Bypass mechanisms (e.g. feature flags, testing overrides) that could weaken protections
  • Changes to rate limiting, abuse prevention, or input validation

If you're unsure whether a change is security-relevant, err on the side of caution and tag clerk/security.

Any time that you tag clerk/security, please do so explicitly in a code comment, rather than within a collapsed section in a coderabbit comment, such as the "recent review details" section. If you do use the team name in any thinking or non-direct-code-comment content, it can be referred to as "clerk security team" to avoid accidentally printing the tag which sends a notification to the team.

Files:

  • packages/react/tsup.config.ts
  • packages/nextjs/src/experimental.ts
  • packages/react/src/experimental.ts
  • packages/nextjs/package.json
  • packages/react/src/utils/childrenUtils.tsx
  • packages/react/package.json
  • packages/react/src/components/PlanDetailsButton.tsx
  • packages/react/src/components/SubscriptionDetailsButton.tsx
  • packages/react/src/components/CheckoutButton.tsx
.changeset/**

📄 CodeRabbit Inference Engine (.cursor/rules/monorepo.mdc)

Automated releases must use Changesets.

Files:

  • .changeset/curly-jeans-sleep.md
  • .changeset/dark-coins-shake.md
packages/*/package.json

📄 CodeRabbit Inference Engine (.cursor/rules/global.mdc)

All publishable packages should be placed under the packages/ directory

packages/*/package.json: All publishable packages must be located in the 'packages/' directory.
All packages must be published under the @clerk namespace on npm.
Semantic versioning must be used across all packages.

Files:

  • packages/nextjs/package.json
  • packages/react/package.json
**/*.{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/utils/childrenUtils.tsx
  • packages/react/src/components/PlanDetailsButton.tsx
  • packages/react/src/components/SubscriptionDetailsButton.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/utils/childrenUtils.tsx
  • packages/react/src/components/PlanDetailsButton.tsx
  • packages/react/src/components/SubscriptionDetailsButton.tsx
  • packages/react/src/components/CheckoutButton.tsx
🧬 Code Graph Analysis (3)
packages/react/src/components/PlanDetailsButton.tsx (3)
packages/react/src/components/withClerk.tsx (1)
  • withClerk (7-37)
packages/react/src/types.ts (1)
  • WithClerkProp (73-73)
packages/react/src/utils/childrenUtils.tsx (3)
  • normalizeWithDefaultValue (25-33)
  • assertSingleChild (6-23)
  • safeExecute (35-41)
packages/react/src/components/SubscriptionDetailsButton.tsx (3)
packages/react/src/components/withClerk.tsx (1)
  • withClerk (7-37)
packages/react/src/types.ts (1)
  • WithClerkProp (73-73)
packages/react/src/utils/childrenUtils.tsx (3)
  • normalizeWithDefaultValue (25-33)
  • assertSingleChild (6-23)
  • safeExecute (35-41)
packages/react/src/components/CheckoutButton.tsx (3)
packages/react/src/components/withClerk.tsx (1)
  • withClerk (7-37)
packages/react/src/types.ts (1)
  • WithClerkProp (73-73)
packages/react/src/utils/childrenUtils.tsx (3)
  • normalizeWithDefaultValue (25-33)
  • assertSingleChild (6-23)
  • safeExecute (35-41)
⏰ 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). (1)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (14)
.changeset/curly-jeans-sleep.md (1)

1-6: Changeset looks good – no action required

The summary is concise and clearly states the user-facing change; version bump is correctly set to minor.

packages/react/tsup.config.ts (1)

15-16: Confirm package.json export & publish-files include the new build artefact

The new experimental entry will emit dist/experimental.{cjs,js}.js (plus types).
Please double-check that:

  1. packages/react/package.json has
    "./experimental": { "types": "./dist/experimental.d.ts", "import": "./dist/experimental.js", "require": "./dist/experimental.cjs" }
  2. The "files" array (or .npmignore) includes dist/experimental.*

Without both, consumers won’t be able to import '@clerk/clerk-react/experimental'.

.changeset/dark-coins-shake.md (1)

1-6: Parallel changeset keeps versions in sync – good

Next.js package gets its own minor bump and release note; no issues spotted.

packages/react/src/utils/childrenUtils.tsx (1)

8-17: LGTM! Type extension properly supports new commerce components.

The addition of 'CheckoutButton', 'SubscriptionDetailsButton', and 'PlanDetailsButton' to the union type correctly extends the assertSingleChild utility to support the new experimental components while maintaining type safety and consistent error messaging.

packages/react/package.json (2)

72-73: Correct addition to files array.

Adding "experimental" to the files array ensures the built experimental module is included in the published npm package.


56-66: Approved: Experimental export and build entry configured correctly

The new ./experimental export path follows existing patterns, and tsup.config already includes an experimental: 'src/experimental.ts' entry. No further changes required.

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

17-27: Excellent auth validation with clear error messages.

The component properly validates authentication context with:

  • Clear check for signed-in user with helpful error message
  • Conditional organization validation when for="org"
  • Descriptive error messages that guide proper component usage
packages/react/src/components/CheckoutButton.tsx (7)

11-25: Component definition follows established patterns.

The component structure is well-designed, using the withClerk HOC appropriately and maintaining clean prop destructuring with proper TypeScript types.


26-35: Excellent security validation with clear error messages.

The authentication and organization context validation is thorough and provides helpful error messages that guide developers on proper component usage. This prevents security issues by ensuring proper authentication state.


36-38: Consistent children handling pattern.

The children normalization and validation follows the established pattern used by other button components in the codebase, ensuring consistency and reliability.


39-55: Clean click handler implementation with proper safety checks.

The click handler properly validates the Clerk instance and cleanly passes all relevant props to the internal checkout method.


57-63: Excellent event handler composition that preserves original behavior.

The wrapped click handler properly preserves any existing onClick behavior from the child element while adding the checkout functionality. The use of safeExecute and proper type checking shows good defensive programming practices.


64-66: Proper React element cloning pattern.

The element cloning approach correctly preserves the child component structure while injecting the necessary event handler and props.


67-68: Appropriate HOC configuration.

The withClerk configuration correctly sets the component name and enables rendering while loading, which is appropriate for a button component.

@panteliselef panteliselef self-assigned this Jul 22, 2025
Copy link

pkg-pr-new bot commented Jul 22, 2025

Open in StackBlitz

@clerk/agent-toolkit

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

@clerk/astro

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

@clerk/backend

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

@clerk/chrome-extension

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

@clerk/clerk-js

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

@clerk/dev-cli

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

@clerk/elements

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

@clerk/clerk-expo

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

@clerk/expo-passkeys

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

@clerk/express

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

@clerk/fastify

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

@clerk/localizations

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

@clerk/nextjs

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

@clerk/nuxt

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

@clerk/clerk-react

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

@clerk/react-router

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

@clerk/remix

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

@clerk/shared

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

@clerk/tanstack-react-start

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

@clerk/testing

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

@clerk/themes

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

@clerk/types

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

@clerk/upgrade

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

@clerk/vue

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

commit: 8f29cb4

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: 2

🧹 Nitpick comments (1)
packages/react/src/components/SubscriptionDetailsButton.tsx (1)

59-63: Fix inconsistency in error message

The error message references for="organization" but the actual prop value being checked is 'org'. This inconsistency could confuse developers.

      throw new Error(
-        'Wrap `<SubscriptionDetailsButton for="organization" />` with a check for an active organization.',
+        'Wrap `<SubscriptionDetailsButton for="org" />` with a check for an active organization.',
      );
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 30e5d33 and 748f635.

📒 Files selected for processing (9)
  • packages/nextjs/package.json (1 hunks)
  • packages/react/package.json (1 hunks)
  • packages/react/src/components/CheckoutButton.tsx (1 hunks)
  • packages/react/src/components/PlanDetailsButton.tsx (1 hunks)
  • packages/react/src/components/SubscriptionDetailsButton.tsx (1 hunks)
  • packages/react/src/components/__tests__/CheckoutButton.test.tsx (1 hunks)
  • packages/react/src/components/__tests__/PlanDetailsButton.test.tsx (1 hunks)
  • packages/react/src/components/__tests__/SubscriptionDetailsButton.test.tsx (1 hunks)
  • packages/types/src/clerk.ts (4 hunks)
📓 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/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/__tests__/SubscriptionDetailsButton.test.tsx
  • 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/__tests__/SubscriptionDetailsButton.test.tsx
  • 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/__tests__/SubscriptionDetailsButton.test.tsx
  • 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/__tests__/SubscriptionDetailsButton.test.tsx
  • 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/__tests__/SubscriptionDetailsButton.test.tsx
  • packages/react/src/components/SubscriptionDetailsButton.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
**/*.{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/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/__tests__/SubscriptionDetailsButton.test.tsx
  • packages/react/src/components/SubscriptionDetailsButton.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
**/__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
**/*

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

Whenever reviewing a pull request, if there are any changes that could impact security, always tag clerk/security in the PR.

Security-impacting changes include, but are not limited to:

  • Changes to authentication logic or mechanisms (e.g. login, session handling, token issuance)
  • Any modification to access control, authorization checks, or role-based permissions
  • Introduction or modification of hashing algorithms, signature verification, or cryptographic primitives
  • Handling of sensitive data (e.g. passwords, tokens, secrets, PII)
  • Integration with external identity providers (e.g. SSO, OAuth, OpenID Connect)
  • Modifications to security headers, cookie flags, CORS policies, or CSRF protections
  • Bypass mechanisms (e.g. feature flags, testing overrides) that could weaken protections
  • Changes to rate limiting, abuse prevention, or input validation

If you're unsure whether a change is security-relevant, err on the side of caution and tag clerk/security.

Any time that you tag clerk/security, please do so explicitly in a code comment, rather than within a collapsed section in a coderabbit comment, such as the "recent review details" section. If you do use the team name in any thinking or non-direct-code-comment content, it can be referred to as "clerk security team" to avoid accidentally printing the tag which sends a notification to the team.

Files:

  • packages/react/src/components/__tests__/SubscriptionDetailsButton.test.tsx
  • packages/react/src/components/SubscriptionDetailsButton.tsx
🧬 Code Graph Analysis (1)
packages/react/src/components/SubscriptionDetailsButton.tsx (4)
packages/react/src/components/withClerk.tsx (1)
  • withClerk (7-37)
packages/react/src/types.ts (1)
  • WithClerkProp (73-73)
packages/types/src/clerk.ts (1)
  • __experimental_SubscriptionDetailsButtonProps (1936-1949)
packages/react/src/utils/childrenUtils.tsx (3)
  • normalizeWithDefaultValue (25-33)
  • assertSingleChild (6-23)
  • safeExecute (35-41)
🚧 Files skipped from review as they are similar to previous changes (7)
  • packages/react/src/components/CheckoutButton.tsx
  • packages/react/package.json
  • packages/react/src/components/tests/CheckoutButton.test.tsx
  • packages/nextjs/package.json
  • packages/react/src/components/PlanDetailsButton.tsx
  • packages/react/src/components/tests/PlanDetailsButton.test.tsx
  • packages/types/src/clerk.ts
🧰 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/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/__tests__/SubscriptionDetailsButton.test.tsx
  • 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/__tests__/SubscriptionDetailsButton.test.tsx
  • 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/__tests__/SubscriptionDetailsButton.test.tsx
  • 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/__tests__/SubscriptionDetailsButton.test.tsx
  • 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/__tests__/SubscriptionDetailsButton.test.tsx
  • packages/react/src/components/SubscriptionDetailsButton.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
**/*.{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/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/__tests__/SubscriptionDetailsButton.test.tsx
  • packages/react/src/components/SubscriptionDetailsButton.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
**/__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
**/*

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

Whenever reviewing a pull request, if there are any changes that could impact security, always tag clerk/security in the PR.

Security-impacting changes include, but are not limited to:

  • Changes to authentication logic or mechanisms (e.g. login, session handling, token issuance)
  • Any modification to access control, authorization checks, or role-based permissions
  • Introduction or modification of hashing algorithms, signature verification, or cryptographic primitives
  • Handling of sensitive data (e.g. passwords, tokens, secrets, PII)
  • Integration with external identity providers (e.g. SSO, OAuth, OpenID Connect)
  • Modifications to security headers, cookie flags, CORS policies, or CSRF protections
  • Bypass mechanisms (e.g. feature flags, testing overrides) that could weaken protections
  • Changes to rate limiting, abuse prevention, or input validation

If you're unsure whether a change is security-relevant, err on the side of caution and tag clerk/security.

Any time that you tag clerk/security, please do so explicitly in a code comment, rather than within a collapsed section in a coderabbit comment, such as the "recent review details" section. If you do use the team name in any thinking or non-direct-code-comment content, it can be referred to as "clerk security team" to avoid accidentally printing the tag which sends a notification to the team.

Files:

  • packages/react/src/components/__tests__/SubscriptionDetailsButton.test.tsx
  • packages/react/src/components/SubscriptionDetailsButton.tsx
🧬 Code Graph Analysis (1)
packages/react/src/components/SubscriptionDetailsButton.tsx (4)
packages/react/src/components/withClerk.tsx (1)
  • withClerk (7-37)
packages/react/src/types.ts (1)
  • WithClerkProp (73-73)
packages/types/src/clerk.ts (1)
  • __experimental_SubscriptionDetailsButtonProps (1936-1949)
packages/react/src/utils/childrenUtils.tsx (3)
  • normalizeWithDefaultValue (25-33)
  • assertSingleChild (6-23)
  • safeExecute (35-41)
⏰ 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: semgrep-cloud-platform/scan
  • GitHub Check: Build Packages
  • GitHub Check: Formatting | Dedupe | Changeset
  • GitHub Check: semgrep/ci
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (8)
packages/react/src/components/SubscriptionDetailsButton.tsx (5)

1-7: LGTM: Clean and well-structured imports

The imports follow TypeScript best practices with proper type-only imports and organized internal module imports.


9-42: Excellent JSDoc documentation

The documentation is comprehensive with clear examples, error conditions, and proper experimental marking. This follows the coding guidelines for public API documentation perfectly.


44-51: Well-structured component setup

The component setup follows good patterns with proper HOC usage and utility function integration. The prop destructuring and children handling are implemented correctly.


65-82: Solid click handler implementation

The click handler properly guards against missing clerk instance, safely executes child click handlers first, and correctly calls the internal Clerk API. The async handling and use of safeExecute utility follow best practices.


84-88: Proper React rendering pattern

The component uses React.cloneElement correctly to pass props to the child element, and the withClerk configuration with renderWhileLoading: true is appropriate for a button component.

packages/react/src/components/__tests__/SubscriptionDetailsButton.test.tsx (3)

1-36: Well-structured test setup

The test setup properly mocks dependencies using Vitest, creates appropriate mock objects, and follows React Testing Library best practices.


42-78: Comprehensive authentication validation tests

The tests properly cover all authentication scenarios including error cases and successful authentication states. The mock setup and assertions are correct.


80-111: Good coverage of rendering scenarios

The rendering tests cover default content, custom children, and prop passing scenarios with appropriate assertions and proper test setup.

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

♻️ Duplicate comments (2)
packages/react/src/components/__tests__/SubscriptionDetailsButton.test.tsx (2)

119-142: Past review comment has been properly addressed.

The test now correctly uses subscriptionDetailsButton prop instead of the previously incorrect planDetailsProps. The test validates that the internal subscription details method is called with the correct parameters.


184-203: Portal configuration test has been corrected.

The test now properly uses subscriptionDetailsButton instead of the previously incorrect planDetailsProps, addressing the past review comment. The portal configuration is tested correctly.

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

1-206: Consider adding edge case tests for better coverage.

While the current test suite is comprehensive, consider adding tests for:

  • Multiple children (should throw error based on assertSingleChild usage)
  • Invalid for prop values
  • Error boundary behavior when subscription details opening fails
// Additional test cases to consider:
it('throws error when multiple children are provided', () => {
  (useAuth as any).mockReturnValue({ userId: 'user_123', orgId: null });
  
  expect(() => 
    render(
      <SubscriptionDetailsButton>
        <button>Button 1</button>
        <button>Button 2</button>
      </SubscriptionDetailsButton>
    )
  ).toThrow();
});

it('handles subscription details opening errors gracefully', async () => {
  (useAuth as any).mockReturnValue({ userId: 'user_123', orgId: null });
  mockOpenSubscriptionDetails.mockRejectedValue(new Error('Network error'));
  
  render(<SubscriptionDetailsButton />);
  
  await userEvent.click(screen.getByText('Subscription details'));
  
  // Add assertions for error handling behavior
});
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 748f635 and 25e58e9.

📒 Files selected for processing (1)
  • packages/react/src/components/__tests__/SubscriptionDetailsButton.test.tsx (1 hunks)
📓 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
**/*.{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/**/*.{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/**/*.{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
**/*.{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
**/*.{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/**/*.{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
**/*.{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
**/*.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
**/*.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
**/__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
**/*

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

Whenever reviewing a pull request, if there are any changes that could impact security, always tag clerk/security in the PR.

Security-impacting changes include, but are not limited to:

  • Changes to authentication logic or mechanisms (e.g. login, session handling, token issuance)
  • Any modification to access control, authorization checks, or role-based permissions
  • Introduction or modification of hashing algorithms, signature verification, or cryptographic primitives
  • Handling of sensitive data (e.g. passwords, tokens, secrets, PII)
  • Integration with external identity providers (e.g. SSO, OAuth, OpenID Connect)
  • Modifications to security headers, cookie flags, CORS policies, or CSRF protections
  • Bypass mechanisms (e.g. feature flags, testing overrides) that could weaken protections
  • Changes to rate limiting, abuse prevention, or input validation

If you're unsure whether a change is security-relevant, err on the side of caution and tag clerk/security.

Any time that you tag clerk/security, please do so explicitly in a code comment, rather than within a collapsed section in a coderabbit comment, such as the "recent review details" section. If you do use the team name in any thinking or non-direct-code-comment content, it can be referred to as "clerk security team" to avoid accidentally printing the tag which sends a notification to the team.

Files:

  • packages/react/src/components/__tests__/SubscriptionDetailsButton.test.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
**/*.{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/**/*.{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/**/*.{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
**/*.{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
**/*.{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/**/*.{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
**/*.{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
**/*.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
**/*.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
**/__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
**/*

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

Whenever reviewing a pull request, if there are any changes that could impact security, always tag clerk/security in the PR.

Security-impacting changes include, but are not limited to:

  • Changes to authentication logic or mechanisms (e.g. login, session handling, token issuance)
  • Any modification to access control, authorization checks, or role-based permissions
  • Introduction or modification of hashing algorithms, signature verification, or cryptographic primitives
  • Handling of sensitive data (e.g. passwords, tokens, secrets, PII)
  • Integration with external identity providers (e.g. SSO, OAuth, OpenID Connect)
  • Modifications to security headers, cookie flags, CORS policies, or CSRF protections
  • Bypass mechanisms (e.g. feature flags, testing overrides) that could weaken protections
  • Changes to rate limiting, abuse prevention, or input validation

If you're unsure whether a change is security-relevant, err on the side of caution and tag clerk/security.

Any time that you tag clerk/security, please do so explicitly in a code comment, rather than within a collapsed section in a coderabbit comment, such as the "recent review details" section. If you do use the team name in any thinking or non-direct-code-comment content, it can be referred to as "clerk security team" to avoid accidentally printing the tag which sends a notification to the team.

Files:

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

1-36: Test setup and mocking implementation looks good.

The imports, mock setup, and beforeEach configuration follow testing best practices. The mocking of useAuth and withClerk HOC is properly implemented for component isolation.


42-78: Authentication validation tests are comprehensive.

The test cases properly cover all authentication scenarios:

  • Unauthenticated users
  • Users without organization when for="org" is specified
  • Successful authentication for both user and organization contexts

The error messages are descriptive and helpful for developers.


80-111: Rendering tests cover essential component behavior.

The tests verify default content rendering, custom children, and prop forwarding. The test structure is clean and follows React Testing Library best practices.


144-175: Event handling tests validate proper interaction flow.

The tests ensure that child onClick handlers execute before the subscription details modal opens, and that the onSubscriptionCancel callback is properly passed through. This validates the component's event handling behavior correctly.

@panteliselef panteliselef enabled auto-merge (squash) July 23, 2025 16:00
@panteliselef panteliselef force-pushed the elef/com-961-dx-guide-introduce-prebuilt-components branch from 25e58e9 to 8f29cb4 Compare July 23, 2025 16:19
@panteliselef panteliselef merged commit 8feb59b into main Jul 23, 2025
59 of 60 checks passed
@panteliselef panteliselef deleted the elef/com-961-dx-guide-introduce-prebuilt-components branch July 23, 2025 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants