Skip to content

Conversation

@panteliselef
Copy link
Member

@panteliselef panteliselef commented Nov 11, 2025

Description

We now support useSubscription({ enabled: false}) to control whether a request will fire or not.

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

  • Bug Fixes

    • Fixed a 403 error when fetching billing info for organization members without sufficient permissions.
  • New Features

    • Billing hooks accept an optional enabled flag to control whether billing requests run automatically.
  • Refactor

    • Centralized billing parameter orchestration so billing-related hooks share consistent enablement and paging behavior.
  • Tests

    • Added and updated tests to cover permission-based access, enabled gating, and to ensure unnecessary billing fetches are skipped; updated fixtures to richer membership data.

@panteliselef panteliselef self-assigned this Nov 11, 2025
@changeset-bot
Copy link

changeset-bot bot commented Nov 11, 2025

🦋 Changeset detected

Latest commit: 2e06d78

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

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

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Nov 11, 2025

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

Project Deployment Preview Comments Updated (UTC)
clerk-js-sandbox Ready Ready Preview Comment Nov 13, 2025 10:42am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 11, 2025

Walkthrough

Adds per-hook optional enabled flags and permission-based gating for billing hooks; centralizes billing parameter construction via a shared builder; updates tests and changesets to reflect skipped billing requests when permissions or enabled: false prevent fetches. (≈38 words)

Changes

Cohort / File(s) Summary
Changesets
.changeset/heavy-suns-divide.md, .changeset/thin-swans-punch.md
Adds two changeset entries: a patch for @clerk/clerk-js documenting a billing-hooks 403 fix and a minor update for @clerk/shared introducing conditional execution support.
Plans & Billing params builder
packages/clerk-js/src/ui/contexts/components/Plans.tsx
Introduces useBillingHookParams to centralize billing parameters and permission gating; refactors usePaymentMethods, usePaymentAttempts, useStatements, useSubscription, and usePlans to use the builder and updated param flow.
Paginated Hook Core
packages/shared/src/react/hooks/createBillingPaginatedHook.tsx
Extends internal HookParams to accept enabled?: boolean and gates mounting-time fetches using the external enabled flag alongside existing conditions.
Subscription Hook (RQ & SWR) + Types
packages/shared/src/react/hooks/useSubscription.rq.tsx, packages/shared/src/react/hooks/useSubscription.swr.tsx, packages/shared/src/react/hooks/useSubscription.types.ts
Adds enabled?: boolean to UseSubscriptionParams; RQ and SWR variants now combine billingEnabled with explicit params.enabled to control query enablement; introduces a HOOK_NAME constant and centralizes enablement logic.
Tests — OrganizationProfile & Paginated Hook
packages/clerk-js/src/ui/components/OrganizationProfile/__tests__/OrganizationProfile.test.tsx, packages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsx, packages/clerk-js/src/ui/components/PricingTable/__tests__/PricingTable.test.tsx
Updates tests to expect billing API calls are skipped when permissions/flags disable fetching; adds tests verifying createBillingPaginatedHook respects enabled: true/false; updates fixtures to richer organization membership objects.

Sequence Diagram(s)

sequenceDiagram
    participant Component as React Component
    participant Hook as Billing Hook (useX)
    participant Builder as useBillingHookParams
    participant Query as RQ / SWR
    participant API as Billing API

    rect rgb(240,248,255)
    Note over Component,API: Permission + explicit enabled gating for billing requests
    end

    Component->>Hook: mount (params? { enabled?: boolean })
    Hook->>Builder: build params (org, memberships, merge external params)
    Builder->>Builder: check org:sys_billing permissions & evaluate enabled flag
    alt permitted && enabled
        Builder-->>Hook: params.enabled = true
        Hook->>Query: subscribe (enabled=true)
        Query->>API: fetch billing data
        API-->>Query: return data
        Query-->>Component: deliver data
    else denied || disabled
        Builder-->>Hook: params.enabled = false
        Hook->>Query: subscribe (enabled=false)
        Query-->>Component: skip fetch / no data
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Files warranting extra attention:
    • packages/clerk-js/src/ui/contexts/components/Plans.tsx — permission-check logic, param merging, and refactor correctness.
    • packages/shared/src/react/hooks/createBillingPaginatedHook.tsx — ensure enabled gating preserves pagination behavior.
    • packages/shared/src/react/hooks/useSubscription.* — confirm RQ and SWR enablement parity and telemetry naming change.
    • Updated tests — validate fixtures and expected call/no-call assertions match new gating.

Poem

🐰
I code a quiet little gate,
So queries wait and bunnies sate,
A gentle flag that says "not now" —
Permissions hum, the network bows,
Hops saved, the meadow sings somehow.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically summarizes the main change: adding an enabled option to billing hooks across shared and clerk-js packages.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch elef/billing-hooks-should-accept-enabled-option

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between bc2415a and 2e06d78.

📒 Files selected for processing (1)
  • packages/clerk-js/src/ui/components/PricingTable/__tests__/PricingTable.test.tsx (3 hunks)
🧰 Additional context used
📓 Path-based instructions (10)
packages/clerk-js/src/ui/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/clerk-js-ui.mdc)

packages/clerk-js/src/ui/**/*.{ts,tsx}: Element descriptors should always be camelCase
Use element descriptors in UI components to enable consistent theming and styling via appearance.elements
Element descriptors should generate unique, stable CSS classes for theming
Element descriptors should handle state classes (e.g., cl-loading, cl-active, cl-error, cl-open) automatically based on component state
Do not render hard-coded values; all user-facing strings must be localized using provided localization methods
Use the useLocalizations hook and localizationKeys utility for all text and error messages
Use the styled system (sx prop, theme tokens, responsive values) for custom component styling
Use useCardState for card-level state, useFormState for form-level state, and useLoadingStatus for loading states
Always use handleError utility for API errors and use translateError for localized error messages
Use useFormControl for form field state, implement proper validation, and handle loading and error states in forms
Use localization keys for all form labels and placeholders
Use element descriptors for consistent styling and follow the theme token system
Use the Card and FormContainer patterns for consistent UI structure

Files:

  • packages/clerk-js/src/ui/components/PricingTable/__tests__/PricingTable.test.tsx
**/*.{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/clerk-js/src/ui/components/PricingTable/__tests__/PricingTable.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/clerk-js/src/ui/components/PricingTable/__tests__/PricingTable.test.tsx
packages/**/*.{ts,tsx}

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

TypeScript is required for all packages

Files:

  • packages/clerk-js/src/ui/components/PricingTable/__tests__/PricingTable.test.tsx
packages/**/*.{ts,tsx,d.ts}

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

Packages should export TypeScript types alongside runtime code

Files:

  • packages/clerk-js/src/ui/components/PricingTable/__tests__/PricingTable.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/clerk-js/src/ui/components/PricingTable/__tests__/PricingTable.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/clerk-js/src/ui/components/PricingTable/__tests__/PricingTable.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/clerk-js/src/ui/components/PricingTable/__tests__/PricingTable.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/clerk-js/src/ui/components/PricingTable/__tests__/PricingTable.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/clerk-js/src/ui/components/PricingTable/__tests__/PricingTable.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: Formatting | Dedupe | Changeset
  • GitHub Check: Build Packages
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (3)
packages/clerk-js/src/ui/components/PricingTable/__tests__/PricingTable.test.tsx (3)

401-405: LGTM! Assertions correctly verify signed-out user behavior.

The new assertions properly validate that signed-out users trigger getPlans with user context and do not fetch subscriptions. The comments accurately describe the expected behavior.


525-533: LGTM! Updated fixture structure supports permission-based testing.

The object-based organization_memberships structure with name and permissions fields correctly models organization membership with billing permissions. The org:sys_billing:manage permission appropriately allows the test to validate full billing access including subscription fetching (line 580).


588-596: LGTM! Read permission fixture correctly validates billing data access.

The updated fixture structure properly tests organization billing with read-only permissions (org:sys_billing:read). The test correctly expects getSubscription to succeed at line 643, validating that read permission suffices for viewing billing data. This addresses the past review comment concern where this assertion was previously commented out.


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

@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 11, 2025

Open in StackBlitz

@clerk/agent-toolkit

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

@clerk/astro

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

@clerk/backend

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

@clerk/chrome-extension

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

@clerk/clerk-js

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

@clerk/dev-cli

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

@clerk/elements

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

@clerk/clerk-expo

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

@clerk/expo-passkeys

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

@clerk/express

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

@clerk/fastify

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

@clerk/localizations

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

@clerk/nextjs

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

@clerk/nuxt

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

@clerk/clerk-react

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

@clerk/react-router

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

@clerk/remix

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

@clerk/shared

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

@clerk/tanstack-react-start

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

@clerk/testing

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

@clerk/themes

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

@clerk/types

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

@clerk/upgrade

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

@clerk/vue

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

commit: 2e06d78

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

🧹 Nitpick comments (1)
.changeset/thin-swans-punch.md (1)

5-5: Grammar improvement: simplify "whether or not" to "whether".

The phrase "whether or not" is redundant in this context.

Apply this diff:

-Billing hooks now accept a `{ enabled: boolean }` option, that controls the whether or not a request will fire.
+Billing hooks now accept a `{ enabled: boolean }` option, that controls whether a request will fire.
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 4011c5e and 89771a5.

📒 Files selected for processing (9)
  • .changeset/heavy-suns-divide.md (1 hunks)
  • .changeset/thin-swans-punch.md (1 hunks)
  • packages/clerk-js/src/ui/components/OrganizationProfile/__tests__/OrganizationProfile.test.tsx (2 hunks)
  • packages/clerk-js/src/ui/contexts/components/Plans.tsx (3 hunks)
  • packages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsx (1 hunks)
  • packages/shared/src/react/hooks/createBillingPaginatedHook.tsx (2 hunks)
  • packages/shared/src/react/hooks/useSubscription.rq.tsx (4 hunks)
  • packages/shared/src/react/hooks/useSubscription.swr.tsx (1 hunks)
  • packages/shared/src/react/hooks/useSubscription.types.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (10)
packages/clerk-js/src/ui/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/clerk-js-ui.mdc)

packages/clerk-js/src/ui/**/*.{ts,tsx}: Element descriptors should always be camelCase
Use element descriptors in UI components to enable consistent theming and styling via appearance.elements
Element descriptors should generate unique, stable CSS classes for theming
Element descriptors should handle state classes (e.g., cl-loading, cl-active, cl-error, cl-open) automatically based on component state
Do not render hard-coded values; all user-facing strings must be localized using provided localization methods
Use the useLocalizations hook and localizationKeys utility for all text and error messages
Use the styled system (sx prop, theme tokens, responsive values) for custom component styling
Use useCardState for card-level state, useFormState for form-level state, and useLoadingStatus for loading states
Always use handleError utility for API errors and use translateError for localized error messages
Use useFormControl for form field state, implement proper validation, and handle loading and error states in forms
Use localization keys for all form labels and placeholders
Use element descriptors for consistent styling and follow the theme token system
Use the Card and FormContainer patterns for consistent UI structure

Files:

  • packages/clerk-js/src/ui/components/OrganizationProfile/__tests__/OrganizationProfile.test.tsx
  • packages/clerk-js/src/ui/contexts/components/Plans.tsx
**/*.{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/clerk-js/src/ui/components/OrganizationProfile/__tests__/OrganizationProfile.test.tsx
  • packages/shared/src/react/hooks/useSubscription.rq.tsx
  • packages/shared/src/react/hooks/useSubscription.types.ts
  • packages/shared/src/react/hooks/createBillingPaginatedHook.tsx
  • packages/shared/src/react/hooks/useSubscription.swr.tsx
  • packages/clerk-js/src/ui/contexts/components/Plans.tsx
  • packages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.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/clerk-js/src/ui/components/OrganizationProfile/__tests__/OrganizationProfile.test.tsx
  • packages/shared/src/react/hooks/useSubscription.rq.tsx
  • packages/shared/src/react/hooks/useSubscription.types.ts
  • packages/shared/src/react/hooks/createBillingPaginatedHook.tsx
  • packages/shared/src/react/hooks/useSubscription.swr.tsx
  • packages/clerk-js/src/ui/contexts/components/Plans.tsx
  • packages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsx
packages/**/*.{ts,tsx}

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

TypeScript is required for all packages

Files:

  • packages/clerk-js/src/ui/components/OrganizationProfile/__tests__/OrganizationProfile.test.tsx
  • packages/shared/src/react/hooks/useSubscription.rq.tsx
  • packages/shared/src/react/hooks/useSubscription.types.ts
  • packages/shared/src/react/hooks/createBillingPaginatedHook.tsx
  • packages/shared/src/react/hooks/useSubscription.swr.tsx
  • packages/clerk-js/src/ui/contexts/components/Plans.tsx
  • packages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsx
packages/**/*.{ts,tsx,d.ts}

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

Packages should export TypeScript types alongside runtime code

Files:

  • packages/clerk-js/src/ui/components/OrganizationProfile/__tests__/OrganizationProfile.test.tsx
  • packages/shared/src/react/hooks/useSubscription.rq.tsx
  • packages/shared/src/react/hooks/useSubscription.types.ts
  • packages/shared/src/react/hooks/createBillingPaginatedHook.tsx
  • packages/shared/src/react/hooks/useSubscription.swr.tsx
  • packages/clerk-js/src/ui/contexts/components/Plans.tsx
  • packages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.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/clerk-js/src/ui/components/OrganizationProfile/__tests__/OrganizationProfile.test.tsx
  • packages/shared/src/react/hooks/useSubscription.rq.tsx
  • packages/shared/src/react/hooks/useSubscription.types.ts
  • packages/shared/src/react/hooks/createBillingPaginatedHook.tsx
  • packages/shared/src/react/hooks/useSubscription.swr.tsx
  • packages/clerk-js/src/ui/contexts/components/Plans.tsx
  • packages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.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/clerk-js/src/ui/components/OrganizationProfile/__tests__/OrganizationProfile.test.tsx
  • packages/shared/src/react/hooks/useSubscription.rq.tsx
  • packages/shared/src/react/hooks/createBillingPaginatedHook.tsx
  • packages/shared/src/react/hooks/useSubscription.swr.tsx
  • packages/clerk-js/src/ui/contexts/components/Plans.tsx
  • packages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.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/clerk-js/src/ui/components/OrganizationProfile/__tests__/OrganizationProfile.test.tsx
  • packages/shared/src/react/hooks/useSubscription.rq.tsx
  • packages/shared/src/react/hooks/createBillingPaginatedHook.tsx
  • packages/shared/src/react/hooks/useSubscription.swr.tsx
  • packages/clerk-js/src/ui/contexts/components/Plans.tsx
  • packages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.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/clerk-js/src/ui/components/OrganizationProfile/__tests__/OrganizationProfile.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/clerk-js/src/ui/components/OrganizationProfile/__tests__/OrganizationProfile.test.tsx
  • packages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsx
🧬 Code graph analysis (3)
packages/shared/src/react/hooks/useSubscription.rq.tsx (2)
packages/shared/src/telemetry/events/method-called.ts (1)
  • eventMethodCalled (13-25)
packages/shared/src/react/clerk-rq/useQuery.ts (1)
  • useClerkQuery (40-42)
packages/shared/src/react/hooks/createBillingPaginatedHook.tsx (2)
packages/shared/src/react/types.ts (3)
  • PaginatedHookConfig (89-102)
  • PagesOrInfiniteOptions (133-156)
  • PaginatedResources (13-79)
packages/shared/src/types/billing.ts (1)
  • ForPayerType (69-69)
packages/clerk-js/src/ui/contexts/components/Plans.tsx (5)
packages/clerk-js/src/ui/contexts/components/SubscriberType.ts (1)
  • useSubscriberTypeContext (7-7)
packages/shared/src/react/hooks/useOrganization.tsx (1)
  • useOrganization (273-472)
packages/shared/src/react/hooks/usePaymentMethods.tsx (1)
  • usePaymentMethods (8-20)
packages/shared/src/react/hooks/usePaymentAttempts.tsx (1)
  • usePaymentAttempts (8-18)
packages/shared/src/react/hooks/useStatements.tsx (1)
  • useStatements (8-18)
🪛 LanguageTool
.changeset/thin-swans-punch.md

[style] ~5-~5: Consider shortening this phrase to just ‘whether’, unless you mean ‘regardless of whether’.
Context: ...d: boolean }` option, that controls the whether or not a request will fire.

(WHETHER)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: pr-title-lint
  • GitHub Check: Formatting | Dedupe | Changeset
  • GitHub Check: Build Packages
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (11)
.changeset/heavy-suns-divide.md (1)

1-5: LGTM!

The changeset clearly documents the bug fix for permission-based gating in billing hooks.

packages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsx (1)

101-119: LGTM! Excellent test coverage for the new enabled flag.

The two new test cases comprehensively verify the gating behavior:

  • When enabled is false, the fetcher is not invoked and loading states remain idle
  • When enabled is true, the fetcher is called with the expected parameters
packages/shared/src/react/hooks/useSubscription.types.ts (1)

10-15: LGTM! Well-documented type addition.

The enabled parameter is properly typed and documented, with a sensible default of true that maintains backward compatibility.

packages/shared/src/react/hooks/useSubscription.swr.tsx (1)

38-41: LGTM! Clean integration of the enabled flag.

The isEnabled variable correctly combines the new enabled parameter (defaulting to true) with the existing billingEnabled check, maintaining backward compatibility while adding the new gating capability.

packages/shared/src/react/hooks/useSubscription.rq.tsx (2)

15-15: Minor improvement: constant naming convention.

The rename from hookName to HOOK_NAME follows a more conventional constant naming pattern.


52-61: LGTM! Centralized and comprehensive enablement logic.

The queriesEnabled variable properly combines user presence, billing settings, and the new enabled parameter (defaulting to true), ensuring queries only run when all conditions are met.

packages/clerk-js/src/ui/components/OrganizationProfile/__tests__/OrganizationProfile.test.tsx (2)

88-89: LGTM! Correct verification of permission-based gating.

The updated assertions properly verify that billing APIs are not invoked when the user lacks the necessary permissions, even with a non-free subscription.


112-113: LGTM! Consistent verification across permission scenarios.

The assertions correctly validate that billing APIs are not called when permissions are insufficient, regardless of whether paid plans exist.

packages/shared/src/react/hooks/createBillingPaginatedHook.tsx (3)

46-57: LGTM! Well-documented type extension.

The enabled parameter is properly added to the HookParams type with clear JSDoc documentation and a sensible default value.


62-62: Good practice: separating enabled from pagination params.

Destructuring enabled as externalEnabled prevents potential conflicts and clearly distinguishes it from internal enablement logic.


102-102: LGTM! Correct integration of external enablement flag.

The isEnabled logic properly incorporates the externalEnabled parameter (defaulting to true) alongside existing gating conditions, ensuring backward compatibility while adding the new control mechanism.

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

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 89771a5 and bc2415a.

📒 Files selected for processing (2)
  • packages/clerk-js/src/ui/components/PricingTable/__tests__/PricingTable.test.tsx (4 hunks)
  • packages/clerk-js/src/ui/contexts/components/Plans.tsx (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/clerk-js/src/ui/contexts/components/Plans.tsx
🧰 Additional context used
📓 Path-based instructions (10)
packages/clerk-js/src/ui/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/clerk-js-ui.mdc)

packages/clerk-js/src/ui/**/*.{ts,tsx}: Element descriptors should always be camelCase
Use element descriptors in UI components to enable consistent theming and styling via appearance.elements
Element descriptors should generate unique, stable CSS classes for theming
Element descriptors should handle state classes (e.g., cl-loading, cl-active, cl-error, cl-open) automatically based on component state
Do not render hard-coded values; all user-facing strings must be localized using provided localization methods
Use the useLocalizations hook and localizationKeys utility for all text and error messages
Use the styled system (sx prop, theme tokens, responsive values) for custom component styling
Use useCardState for card-level state, useFormState for form-level state, and useLoadingStatus for loading states
Always use handleError utility for API errors and use translateError for localized error messages
Use useFormControl for form field state, implement proper validation, and handle loading and error states in forms
Use localization keys for all form labels and placeholders
Use element descriptors for consistent styling and follow the theme token system
Use the Card and FormContainer patterns for consistent UI structure

Files:

  • packages/clerk-js/src/ui/components/PricingTable/__tests__/PricingTable.test.tsx
**/*.{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/clerk-js/src/ui/components/PricingTable/__tests__/PricingTable.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/clerk-js/src/ui/components/PricingTable/__tests__/PricingTable.test.tsx
packages/**/*.{ts,tsx}

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

TypeScript is required for all packages

Files:

  • packages/clerk-js/src/ui/components/PricingTable/__tests__/PricingTable.test.tsx
packages/**/*.{ts,tsx,d.ts}

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

Packages should export TypeScript types alongside runtime code

Files:

  • packages/clerk-js/src/ui/components/PricingTable/__tests__/PricingTable.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/clerk-js/src/ui/components/PricingTable/__tests__/PricingTable.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/clerk-js/src/ui/components/PricingTable/__tests__/PricingTable.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/clerk-js/src/ui/components/PricingTable/__tests__/PricingTable.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/clerk-js/src/ui/components/PricingTable/__tests__/PricingTable.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/clerk-js/src/ui/components/PricingTable/__tests__/PricingTable.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: Analyze (javascript-typescript)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (2)
packages/clerk-js/src/ui/components/PricingTable/__tests__/PricingTable.test.tsx (2)

525-533: LGTM! Enhanced fixture structure for permission-based testing.

The organization membership structure now includes explicit permissions, which aligns with the permission-based gating introduced in this PR. Using org:sys_billing:manage for the legacy forOrganizations: true test scenario is appropriate.


588-596: Now I need to search the codebase directly to verify the implementation and the test file:

Based on my research, I have gathered information about Clerk's permission system and billing architecture. However, I cannot fully verify the specific implementation details and the commented-out assertion in the test without direct access to the codebase implementation.

Manual verification required: Confirm permission-based authorization for subscription fetching.

Member role offers limited access with "Read members" and "Read billing" permissions only, by default—they cannot manage billing. This test correctly uses org:sys_billing:read (read-only) while a previous test uses org:sys_billing:manage.

Permission-based authorization checks link with feature-based authorization: if an organization is not subscribed to a plan with the feature, the authorization check returns false, even if the user has the custom permission.

Verify that:

  1. The getSubscription assertion on line 643 is intentionally commented because users with read-only billing permissions cannot fetch subscription data (permission gating working as designed).
  2. This test structure (comparing read vs. manage permissions) properly covers the permission-gating logic introduced in this PR.
  3. If read-only permissions should prevent getSubscription calls, the commented assertion should either be activated with a negation check (similar to line 405) or documented explaining why subscription fetching differs between permission levels.

@panteliselef panteliselef enabled auto-merge (squash) November 13, 2025 10:41
@panteliselef panteliselef merged commit c63cc8e into main Nov 13, 2025
44 of 45 checks passed
@panteliselef panteliselef deleted the elef/billing-hooks-should-accept-enabled-option branch November 13, 2025 10:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants