Skip to content

feat(clerk-js,types): Update logic for showing Billing nav within profiles #6315

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

aeliox
Copy link
Contributor

@aeliox aeliox commented Jul 15, 2025

Description

Updates the logic around showing and hiding the Billing nav in the UserProfile and OrgProfile based on new environment settings. Also now only shows the "Switch Plans" / "Subscribe to a Plan" button on the Billing page if the respective resource has paid visible plans.

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

    • Improved billing controls in user and organization profiles, allowing for more precise display and management of billing-related features based on new settings.
  • Bug Fixes

    • Refined conditional display of billing routes and actions to ensure billing options only appear when appropriate for users and organizations.
  • Refactor

    • Enhanced internal logic for determining billing feature availability, offering more granular checks for user and organization contexts.

Copy link

changeset-bot bot commented Jul 15, 2025

🦋 Changeset detected

Latest commit: d22b94f

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/types Patch
@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/localizations Patch
@clerk/nextjs Patch
@clerk/nuxt Patch
@clerk/react-router Patch
@clerk/clerk-react Patch
@clerk/remix Patch
@clerk/shared Patch
@clerk/tanstack-react-start Patch
@clerk/testing Patch
@clerk/themes Patch
@clerk/vue Patch

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

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

Copy link

vercel bot commented Jul 15, 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 17, 2025 3:57pm

@@ -605,7 +605,7 @@ export class Clerk implements ClerkInterface {

public __internal_openPlanDetails = (props: __internal_PlanDetailsProps): void => {
this.assertComponentsReady(this.#componentControls);
if (disabledBillingFeature(this, this.environment)) {
if (disabledAllBillingFeatures(this, this.environment)) {
Copy link
Contributor Author

@aeliox aeliox Jul 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thought process on these is that since we don't necessarily know the subscriberType in these functions (right?) we will just check if all billing is disabled.

Copy link

pkg-pr-new bot commented Jul 15, 2025

Open in StackBlitz

@clerk/agent-toolkit

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

@clerk/astro

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

@clerk/backend

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

@clerk/chrome-extension

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

@clerk/clerk-js

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

@clerk/dev-cli

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

@clerk/elements

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

@clerk/clerk-expo

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

@clerk/expo-passkeys

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

@clerk/express

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

@clerk/fastify

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

@clerk/localizations

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

@clerk/nextjs

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

@clerk/nuxt

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

@clerk/clerk-react

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

@clerk/react-router

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

@clerk/remix

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

@clerk/shared

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

@clerk/tanstack-react-start

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

@clerk/testing

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

@clerk/themes

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

@clerk/types

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

@clerk/upgrade

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

@clerk/vue

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

commit: d22b94f

Copy link
Contributor

coderabbitai bot commented Jul 15, 2025

📝 Walkthrough

Walkthrough

This change refactors the billing feature logic throughout the codebase by introducing more granular control over user and organization billing settings. The billing property in commerce settings now contains nested organization and user objects, each with their own enabled and hasPaidPlans boolean fields. Component guards and conditional rendering logic were updated to use these new nested properties, replacing previous flat properties. The logic for displaying billing-related UI elements and routes in user and organization profile components was revised to check the appropriate nested flags. No changes were made to public API signatures, but type definitions were updated to reflect the new structure.


📜 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 e84ffff and 1bf510b.

📒 Files selected for processing (1)
  • packages/clerk-js/bundlewatch.config.json (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/clerk-js/bundlewatch.config.json
⏰ 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: Formatting | Dedupe | Changeset
  • GitHub Check: Build Packages
  • GitHub Check: semgrep/ci
  • 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: 1

🔭 Outside diff range comments (3)
packages/clerk-js/src/core/clerk.ts (1)

577-1070: Consider adding tests for the new granular billing feature logic.

The refactoring from disabledBillingFeature to disabledAllBillingFeatures introduces more granular control over billing features. While the changes are straightforward replacements, the new logic should be tested to ensure:

  1. Billing components are properly disabled when all billing features are disabled
  2. Components behave correctly when only user or organization billing is disabled
  3. Error handling works as expected in development mode
#!/bin/bash
# Description: Check if tests exist for the updated billing feature guards

# Search for existing tests related to billing feature guards
rg -A 5 -B 5 "disabledAllBillingFeatures|disabledBillingFeature" --type ts --type js

# Look for test files that might cover these billing methods
fd -e test.ts -e spec.ts -e test.js -e spec.js | xargs grep -l "openCheckout\|openPlanDetails\|mountPricingTable"
packages/clerk-js/src/ui/components/OrganizationProfile/OrganizationProfileRoutes.tsx (2)

86-119: Use optional chaining for nested property access to prevent runtime errors.

The conditional check commerceSettings.billing.organization.enabled accesses nested properties without optional chaining, which could cause runtime errors if the nested structure is undefined. The component guards in componentGuards.ts use optional chaining for similar checks.

Apply this diff to use optional chaining:

-        {commerceSettings.billing.organization.enabled ? (
+        {commerceSettings.billing.organization?.enabled ? (

86-119: Add unit and visual regression tests for OrganizationProfileRoutes billing conditions

No existing tests reference OrganizationProfileRoutes or the new organization-billing routes. Please add:

• Unit tests in packages/clerk-js/src/ui/components/OrganizationProfile/__tests__/OrganizationProfileRoutes.test.tsx (or similar) that verify:
– When commerceSettings.billing.organization.enabled is false, no billing routes render
– When enabled without paid plans, the billing page renders but “plans” route is absent
– When enabled with paid plans, both billing and plans routes render
– The statement (statement/:statementId) and payment-attempt routes render correctly

• Use React Testing Library to assert component behavior (not implementation) with proper queries and setup.

• A visual regression test in the packages/clerk-js suite (e.g. Storybook + Chromatic/Percy) covering each billing state to catch unintended UI changes.

🧹 Nitpick comments (1)
packages/clerk-js/src/ui/components/Subscriptions/SubscriptionsList.tsx (1)

193-211: Consider refactoring complex conditional logic for better readability.

The conditional rendering logic for the ArrowButton is functionally correct but could be more readable with a helper function or extracted variable.

Consider extracting the condition to improve readability:

+  const shouldShowArrowButton = 
+    (subscriberType === 'user' && commerceSettings.billing.user.hasPaidPlans) ||
+    (subscriberType === 'org' && commerceSettings.billing.organization.hasPaidPlans);
+
-      {(commerceSettings.billing.user.hasPaidPlans && subscriberType === 'user') ||
-      (commerceSettings.billing.organization.hasPaidPlans && subscriberType === 'org') ? (
+      {shouldShowArrowButton ? (
         <ProfileSection.ArrowButton
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 53983db and 1b714a7.

📒 Files selected for processing (9)
  • .changeset/public-bags-stay.md (1 hunks)
  • packages/clerk-js/src/core/clerk.ts (4 hunks)
  • packages/clerk-js/src/core/resources/CommerceSettings.ts (3 hunks)
  • packages/clerk-js/src/ui/components/OrganizationProfile/OrganizationProfileRoutes.tsx (3 hunks)
  • packages/clerk-js/src/ui/components/Subscriptions/SubscriptionsList.tsx (3 hunks)
  • packages/clerk-js/src/ui/components/UserProfile/UserProfileRoutes.tsx (2 hunks)
  • packages/clerk-js/src/ui/utils/createCustomPages.tsx (2 hunks)
  • packages/clerk-js/src/utils/componentGuards.ts (1 hunks)
  • packages/types/src/commerceSettings.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (9)
**/*.{js,jsx,ts,tsx}

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • .cursor/rules/development.mdc
packages/**/*.ts

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • .cursor/rules/development.mdc
packages/**/*.{ts,tsx,d.ts}

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • .cursor/rules/development.mdc
**/*.{ts,tsx}

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • .cursor/rules/development.mdc
  • .cursor/rules/typescript.mdc
packages/{clerk-js,elements,themes}/**/*

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • .cursor/rules/monorepo.mdc
**/*

Instructions used from:

Sources:
⚙️ CodeRabbit Configuration File

**/*.{tsx,jsx}

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • .cursor/rules/development.mdc
**/*.{jsx,tsx}

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • .cursor/rules/react.mdc
**/*.tsx

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • .cursor/rules/react.mdc
🧠 Learnings (8)
📓 Common learnings
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/monorepo.mdc:0-0
Timestamp: 2025-06-30T10:30:56.197Z
Learning: Applies to packages/{clerk-js,elements,themes}/**/* : Visual regression testing should be performed for UI components.
.changeset/public-bags-stay.md (9)
Learnt from: dstaley
PR: clerk/javascript#6116
File: .changeset/tangy-garlics-say.md:1-2
Timestamp: 2025-06-13T16:09:53.061Z
Learning: In the Clerk JavaScript repository, contributors create intentionally empty changeset files (containing only the YAML delimiters) when a PR touches only non-published parts of the codebase (e.g., sandbox assets). This signals that no package release is required, so such changesets should not be flagged as missing content.
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/monorepo.mdc:0-0
Timestamp: 2025-06-30T10:30:56.197Z
Learning: Applies to packages/{clerk-js,elements,themes}/**/* : Visual regression testing should be performed for UI components.
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/global.mdc:0-0
Timestamp: 2025-06-30T10:30:13.397Z
Learning: Applies to packages/*/package.json : All packages must be published under the @clerk namespace
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/monorepo.mdc:0-0
Timestamp: 2025-06-30T10:30:56.197Z
Learning: Applies to packages/*/package.json : All packages must be published under the @clerk namespace on npm.
Learnt from: panteliselef
PR: clerk/javascript#6285
File: packages/types/src/commerce.ts:1305-1305
Timestamp: 2025-07-11T18:08:14.697Z
Learning: In the Clerk JavaScript repository, when there's a conflict between naming consistency (camelCase) and avoiding breaking changes, the team prioritizes maintaining backward compatibility over enforcing naming conventions, even for experimental APIs.
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/monorepo.mdc:0-0
Timestamp: 2025-06-30T10:30:56.197Z
Learning: Applies to packages/@clerk/*/package.json : Framework packages must depend on '@clerk/clerk-js' for core functionality.
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/monorepo.mdc:0-0
Timestamp: 2025-06-30T10:30:56.197Z
Learning: Applies to packages/clerk-react/**/*.{test,spec}.{js,ts,tsx} : Component testing should use React Testing Library.
Learnt from: panteliselef
PR: clerk/javascript#6097
File: packages/clerk-js/src/ui/elements/LineItems.tsx:89-89
Timestamp: 2025-06-10T09:38:56.214Z
Learning: In packages/clerk-js/src/ui/elements/LineItems.tsx, the Title component's React.forwardRef should use HTMLTableCellElement as the generic type parameter, even though it renders a Dt element. This is the correct implementation according to the codebase maintainer.
Learnt from: wobsoriano
PR: clerk/javascript#6163
File: packages/backend/src/api/endpoints/APIKeysApi.ts:60-70
Timestamp: 2025-06-20T17:44:17.570Z
Learning: The Clerk codebase uses POST method for API key update operations instead of the typical PATCH method, as clarified by the maintainer wobsoriano.
packages/clerk-js/src/core/clerk.ts (8)
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/monorepo.mdc:0-0
Timestamp: 2025-06-30T10:30:56.197Z
Learning: Applies to packages/{clerk-js,elements,themes}/**/* : Visual regression testing should be performed for UI components.
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/monorepo.mdc:0-0
Timestamp: 2025-06-30T10:30:56.197Z
Learning: Applies to packages/clerk-react/**/*.{test,spec}.{js,ts,tsx} : Component testing should use React Testing Library.
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/monorepo.mdc:0-0
Timestamp: 2025-06-30T10:30:56.197Z
Learning: Applies to packages/@clerk/*/package.json : Framework packages must depend on '@clerk/clerk-js' for core functionality.
Learnt from: wobsoriano
PR: clerk/javascript#5858
File: packages/clerk-js/src/core/modules/apiKeys/index.ts:84-97
Timestamp: 2025-06-10T17:35:08.986Z
Learning: In the APIKeys service methods (packages/clerk-js/src/core/modules/apiKeys/index.ts), error handling is intentionally delegated to the component level rather than being implemented within the service methods themselves. This architectural pattern allows calling components to handle errors according to their specific UI needs.
Learnt from: dstaley
PR: clerk/javascript#6100
File: packages/clerk-js/src/ui/components/OAuthConsent/OAuthConsent.tsx:121-124
Timestamp: 2025-06-16T17:08:58.414Z
Learning: The @clerk/clerk-js package only supports browsers released in the last two years (since May 8, 2023), so modern CSS features like color-mix() are fully supported across all target browsers without requiring fallbacks.
Learnt from: LauraBeatris
PR: clerk/javascript#6273
File: packages/testing/src/playwright/unstable/page-objects/sessionTask.ts:22-27
Timestamp: 2025-07-11T17:12:28.495Z
Learning: In Clerk's test utilities, particularly for page objects like sessionTask.ts, when handling task type enums, prefer graceful handling of unknown/unsupported task types rather than throwing errors. This prevents breaking existing tests when new task types are introduced to the SessionTask['key'] union type.
Learnt from: panteliselef
PR: clerk/javascript#6097
File: packages/clerk-js/src/ui/elements/LineItems.tsx:89-89
Timestamp: 2025-06-10T09:38:56.214Z
Learning: In packages/clerk-js/src/ui/elements/LineItems.tsx, the Title component's React.forwardRef should use HTMLTableCellElement as the generic type parameter, even though it renders a Dt element. This is the correct implementation according to the codebase maintainer.
Learnt from: panteliselef
PR: clerk/javascript#6285
File: packages/types/src/commerce.ts:1305-1305
Timestamp: 2025-07-11T18:08:14.697Z
Learning: In the Clerk JavaScript repository, when there's a conflict between naming consistency (camelCase) and avoiding breaking changes, the team prioritizes maintaining backward compatibility over enforcing naming conventions, even for experimental APIs.
packages/clerk-js/src/ui/utils/createCustomPages.tsx (10)
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/monorepo.mdc:0-0
Timestamp: 2025-06-30T10:30:56.197Z
Learning: Applies to packages/clerk-react/**/*.{test,spec}.{js,ts,tsx} : Component testing should use React Testing Library.
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/monorepo.mdc:0-0
Timestamp: 2025-06-30T10:30:56.197Z
Learning: Applies to packages/{clerk-js,elements,themes}/**/* : Visual regression testing should be performed for UI components.
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/development.mdc:0-0
Timestamp: 2025-06-30T10:29:42.997Z
Learning: Applies to packages/**/index.{js,ts} : Use tree-shaking friendly exports
Learnt from: panteliselef
PR: clerk/javascript#6097
File: packages/clerk-js/src/ui/elements/LineItems.tsx:89-89
Timestamp: 2025-06-10T09:38:56.214Z
Learning: In packages/clerk-js/src/ui/elements/LineItems.tsx, the Title component's React.forwardRef should use HTMLTableCellElement as the generic type parameter, even though it renders a Dt element. This is the correct implementation according to the codebase maintainer.
Learnt from: LauraBeatris
PR: clerk/javascript#6273
File: packages/testing/src/playwright/unstable/page-objects/sessionTask.ts:22-27
Timestamp: 2025-07-11T17:12:28.495Z
Learning: In Clerk's test utilities, particularly for page objects like sessionTask.ts, when handling task type enums, prefer graceful handling of unknown/unsupported task types rather than throwing errors. This prevents breaking existing tests when new task types are introduced to the SessionTask['key'] union type.
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/monorepo.mdc:0-0
Timestamp: 2025-06-30T10:30:56.197Z
Learning: Applies to packages/@clerk/*/package.json : Framework packages must depend on '@clerk/clerk-js' for core functionality.
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/typescript.mdc:0-0
Timestamp: 2025-06-30T10:33:45.961Z
Learning: Applies to **/*.{ts,tsx} : Proper use of utility types instead of manual type construction
Learnt from: wobsoriano
PR: clerk/javascript#5858
File: packages/clerk-js/src/core/modules/apiKeys/index.ts:84-97
Timestamp: 2025-06-10T17:35:08.986Z
Learning: In the APIKeys service methods (packages/clerk-js/src/core/modules/apiKeys/index.ts), error handling is intentionally delegated to the component level rather than being implemented within the service methods themselves. This architectural pattern allows calling components to handle errors according to their specific UI needs.
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/typescript.mdc:0-0
Timestamp: 2025-06-30T10:33:45.961Z
Learning: Applies to **/*.{ts,tsx} : Use `public` explicitly for clarity in public APIs
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/development.mdc:0-0
Timestamp: 2025-06-30T10:29:42.997Z
Learning: Applies to **/*.{js,jsx,ts,tsx} : Use dynamic imports for optional features
packages/clerk-js/src/ui/components/Subscriptions/SubscriptionsList.tsx (11)
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/react.mdc:0-0
Timestamp: 2025-06-30T10:32:37.848Z
Learning: Applies to **/*.{jsx,tsx} : Implement proper subscription cleanup
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/react.mdc:0-0
Timestamp: 2025-06-30T10:32:37.848Z
Learning: Applies to **/*.{jsx,tsx} : Use proper hook structure
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/monorepo.mdc:0-0
Timestamp: 2025-06-30T10:30:56.197Z
Learning: Applies to packages/clerk-react/**/*.{test,spec}.{js,ts,tsx} : Component testing should use React Testing Library.
Learnt from: panteliselef
PR: clerk/javascript#6097
File: packages/clerk-js/src/ui/elements/LineItems.tsx:89-89
Timestamp: 2025-06-10T09:38:56.214Z
Learning: In packages/clerk-js/src/ui/elements/LineItems.tsx, the Title component's React.forwardRef should use HTMLTableCellElement as the generic type parameter, even though it renders a Dt element. This is the correct implementation according to the codebase maintainer.
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/react.mdc:0-0
Timestamp: 2025-06-30T10:32:37.848Z
Learning: Applies to **/*.{jsx,tsx} : Use proper state updates with callbacks
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/react.mdc:0-0
Timestamp: 2025-06-30T10:32:37.848Z
Learning: Applies to **/*.{jsx,tsx} : Implement proper virtualization for lists
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/react.mdc:0-0
Timestamp: 2025-06-30T10:32:37.848Z
Learning: Applies to **/*.tsx : Use proper type guards for conditional rendering
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/react.mdc:0-0
Timestamp: 2025-06-30T10:32:37.848Z
Learning: Applies to **/*.{jsx,tsx} : Use proper button types
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/react.mdc:0-0
Timestamp: 2025-06-30T10:32:37.848Z
Learning: Applies to **/*.{jsx,tsx} : Implement proper state selectors
Learnt from: LauraBeatris
PR: clerk/javascript#6117
File: packages/clerk-js/src/ui/components/SessionTasks/index.tsx:64-83
Timestamp: 2025-06-18T16:33:36.764Z
Learning: In SessionTasks component at packages/clerk-js/src/ui/components/SessionTasks/index.tsx, the useEffect that checks for pending tasks should only run on mount (not react to currentTask/status changes) to handle browser back navigation edge cases without interfering with normal task completion flow managed by nextTask().
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/react.mdc:0-0
Timestamp: 2025-06-30T10:32:37.848Z
Learning: Applies to **/*.{jsx,tsx} : Use Context API for theme/authentication
packages/clerk-js/src/ui/components/UserProfile/UserProfileRoutes.tsx (14)
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/react.mdc:0-0
Timestamp: 2025-06-30T10:32:37.848Z
Learning: Applies to **/*.tsx : Use proper type guards for conditional rendering
Learnt from: LauraBeatris
PR: clerk/javascript#6117
File: packages/clerk-js/src/ui/components/SessionTasks/index.tsx:64-83
Timestamp: 2025-06-18T16:33:36.764Z
Learning: In SessionTasks component at packages/clerk-js/src/ui/components/SessionTasks/index.tsx, the useEffect that checks for pending tasks should only run on mount (not react to currentTask/status changes) to handle browser back navigation edge cases without interfering with normal task completion flow managed by nextTask().
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/monorepo.mdc:0-0
Timestamp: 2025-06-30T10:30:56.197Z
Learning: Applies to packages/clerk-react/**/*.{test,spec}.{js,ts,tsx} : Component testing should use React Testing Library.
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/nextjs.mdc:0-0
Timestamp: 2025-06-30T10:31:43.578Z
Learning: Applies to app/**/page.tsx : Use page.tsx for route segments that render UI in the App Router
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/nextjs.mdc:0-0
Timestamp: 2025-06-30T10:31:43.578Z
Learning: Applies to app/**/layout.tsx : Use layout.tsx for shared UI that wraps multiple pages in the App Router
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/nextjs.mdc:0-0
Timestamp: 2025-06-30T10:31:43.578Z
Learning: Applies to pages/**/*.{js,ts,jsx,tsx} : Use SWR for client-side data fetching in Pages Router
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/nextjs.mdc:0-0
Timestamp: 2025-06-30T10:31:43.578Z
Learning: Applies to {app/**/*.tsx,pages/**/*.{js,ts,jsx,tsx}} : Use Link component for client-side navigation between pages
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/react.mdc:0-0
Timestamp: 2025-06-30T10:32:37.848Z
Learning: Applies to **/*.{jsx,tsx} : Use Context API for theme/authentication
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/nextjs.mdc:0-0
Timestamp: 2025-06-30T10:31:43.578Z
Learning: Applies to app/**/[[]...*[]]/**/page.tsx : Use double brackets for catch-all routes: [...slug]/page.tsx
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/nextjs.mdc:0-0
Timestamp: 2025-06-30T10:31:43.578Z
Learning: Applies to app/**/*.tsx : Use useRouter hook for programmatic navigation in Client Components
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/nextjs.mdc:0-0
Timestamp: 2025-06-30T10:31:43.578Z
Learning: Applies to app/**/default.tsx : Use default.tsx for parallel routes fallbacks in the App Router
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/nextjs.mdc:0-0
Timestamp: 2025-06-30T10:31:43.578Z
Learning: Applies to app/**/error.tsx : Use error.tsx for error boundaries at the route level in the App Router
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/nextjs.mdc:0-0
Timestamp: 2025-06-30T10:31:43.578Z
Learning: Applies to pages/**/*.{js,ts,jsx,tsx} : Use getStaticPaths with getStaticProps for dynamic static generation in Pages Router
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/nextjs.mdc:0-0
Timestamp: 2025-06-30T10:31:43.578Z
Learning: Applies to app/**/*.tsx : Use redirect function for server-side redirects in Server Components
packages/clerk-js/src/utils/componentGuards.ts (3)
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/monorepo.mdc:0-0
Timestamp: 2025-06-30T10:30:56.197Z
Learning: Applies to packages/{clerk-js,elements,themes}/**/* : Visual regression testing should be performed for UI components.
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/react.mdc:0-0
Timestamp: 2025-06-30T10:32:37.848Z
Learning: Applies to **/*.tsx : Use proper type guards for conditional rendering
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/monorepo.mdc:0-0
Timestamp: 2025-06-30T10:30:56.197Z
Learning: Applies to packages/clerk-react/**/*.{test,spec}.{js,ts,tsx} : Component testing should use React Testing Library.
packages/clerk-js/src/ui/components/OrganizationProfile/OrganizationProfileRoutes.tsx (7)
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/react.mdc:0-0
Timestamp: 2025-06-30T10:32:37.848Z
Learning: Applies to **/*.tsx : Use proper type guards for conditional rendering
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/monorepo.mdc:0-0
Timestamp: 2025-06-30T10:30:56.197Z
Learning: Applies to packages/clerk-react/**/*.{test,spec}.{js,ts,tsx} : Component testing should use React Testing Library.
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/monorepo.mdc:0-0
Timestamp: 2025-06-30T10:30:56.197Z
Learning: Applies to packages/{clerk-js,elements,themes}/**/* : Visual regression testing should be performed for UI components.
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/nextjs.mdc:0-0
Timestamp: 2025-06-30T10:31:43.578Z
Learning: Applies to app/**/page.tsx : Use page.tsx for route segments that render UI in the App Router
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/nextjs.mdc:0-0
Timestamp: 2025-06-30T10:31:43.578Z
Learning: Applies to app/**/layout.tsx : Use layout.tsx for shared UI that wraps multiple pages in the App Router
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/nextjs.mdc:0-0
Timestamp: 2025-06-30T10:31:43.578Z
Learning: Applies to pages/**/*.{js,ts,jsx,tsx} : Use SWR for client-side data fetching in Pages Router
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/react.mdc:0-0
Timestamp: 2025-06-30T10:32:37.848Z
Learning: Applies to **/*.{jsx,tsx} : Use Context API for theme/authentication
🧬 Code Graph Analysis (3)
packages/clerk-js/src/core/clerk.ts (1)
packages/clerk-js/src/utils/componentGuards.ts (1)
  • disabledAllBillingFeatures (33-35)
packages/clerk-js/src/ui/components/Subscriptions/SubscriptionsList.tsx (1)
packages/clerk-js/src/ui/elements/Section.tsx (1)
  • ProfileSection (315-323)
packages/clerk-js/src/ui/components/OrganizationProfile/OrganizationProfileRoutes.tsx (1)
packages/clerk-js/src/ui/components/OrganizationProfile/OrganizationPlansPage.tsx (1)
  • OrganizationPlansPage (54-60)
⏰ 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 (23)
.changeset/public-bags-stay.md (1)

1-7: LGTM - Changeset properly documents the billing feature refactoring.

The changeset correctly describes the patch-level changes to support more granular billing feature controls in UserProfile and OrgProfile components.

packages/clerk-js/src/core/clerk.ts (4)

97-97: LGTM - Import updated for granular billing feature guard.

The import change correctly updates to use the new combined billing feature guard that checks both user and organization billing states.


577-586: LGTM - Checkout guard updated consistently.

The billing feature check in __internal_openCheckout is correctly updated to use the new combined guard while maintaining the same error handling behavior.


606-615: LGTM - Plan details guard updated consistently.

The billing feature check in __internal_openPlanDetails follows the same pattern as the checkout method, ensuring consistent behavior across billing-related UI components.


1061-1070: LGTM - Pricing table guard updated consistently.

The mountPricingTable method correctly adopts the new combined billing feature guard, completing the consistent refactoring across all billing-related UI methods.

packages/clerk-js/src/ui/components/Subscriptions/SubscriptionsList.tsx (2)

5-5: LGTM: Proper hook import for accessing environment settings.

The addition of useEnvironment to access the newly structured commerce settings is correct and follows React hook patterns.


48-48: LGTM: Correct destructuring of commerce settings.

The destructuring of commerceSettings from useEnvironment() is appropriate for accessing the nested billing configuration.

packages/clerk-js/src/ui/utils/createCustomPages.tsx (2)

6-7: LGTM: Improved import specificity for billing feature guards.

The replacement of generic billing feature guards with specific disabledOrganizationBillingFeature and disabledUserBillingFeature provides better granularity and aligns with the overall refactoring goals.


99-101: LGTM: Correct implementation of context-specific billing feature checks.

The logic properly uses the appropriate billing feature guard based on the organization parameter, providing better separation between user and organization billing features.

packages/clerk-js/src/ui/components/UserProfile/UserProfileRoutes.tsx (2)

83-83: LGTM: Correct use of user-specific billing flag.

The update to use commerceSettings.billing.user.enabled instead of the generic billing flag provides better granularity for user profile billing features.


91-97: LGTM: Proper conditional rendering for plans route.

The nested conditional correctly renders the plans route only when commerceSettings.billing.user.hasPaidPlans is true, ensuring users only see plan options when paid plans are available.

packages/clerk-js/src/core/resources/CommerceSettings.ts (3)

14-21: LGTM: Well-structured nested billing properties.

The addition of nested organization and user objects with enabled and hasPaidPlans properties provides the granular control needed for the billing feature refactoring while maintaining a clean structure.


38-41: LGTM: Proper JSON deserialization with fallbacks.

The fromJSON method correctly handles the new nested properties with appropriate fallback values to false, ensuring robustness when properties are missing from the input data.


53-60: LGTM: Correct snapshot serialization with proper naming conversion.

The __internal_toSnapshot method properly converts the camelCase properties to snake_case format, maintaining consistency with the expected JSON structure.

packages/types/src/commerceSettings.ts (3)

12-19: LGTM: Well-defined nested billing structure for JSON interface.

The addition of nested organization and user objects with enabled and has_paid_plans properties to the JSON interface properly follows snake_case naming conventions and provides the granular structure needed for the billing refactoring.


29-36: LGTM: Consistent nested billing structure for Resource interface.

The Resource interface correctly mirrors the JSON structure using camelCase naming conventions (hasPaidPlans instead of has_paid_plans), maintaining consistency with TypeScript conventions.


12-36: Ensure Security Review and Enforcement of Billing Access Controls

These updates to CommerceSettingsResource.billing modify how billing features and plans are toggled and accessed. Please engage the Clerk security team to confirm that proper controls are in place and consider implementing the following best practices:

  • Principle of Least Privilege
    • Grant only the minimum access needed for billing operations (e.g., admin or billing manager roles).
  • Role-Based Access Control (RBAC)
    • Define and enforce clear roles/permissions around viewing invoices, managing payment methods, and changing subscription plans.
  • Secure Feature Flags
    • Store toggles in encrypted, authenticated storage.
    • Enforce flags on the backend, not just in the UI.
  • Audit Logging
    • Record every billing-related action with user identity, timestamp, and before/after state.
  • Protection of API Endpoints
    • Require strong authentication and authorization checks (e.g., JWTs, tokens) for all billing APIs.
  • Data Encryption
    • Use TLS for in-transit data and encrypt billing data at rest.
  • Input Validation
    • Sanitize and validate all inputs to billing endpoints to prevent injection attacks.
  • Regular Security Reviews
    • Conduct periodic audits and penetration tests focused on billing flows.
  • User Notifications
    • Alert users/admins on critical events (e.g., plan changes, failed payments) to detect fraud.
  • Backup & Recovery
    • Ensure reliable backups of billing data and tested recovery procedures.
  • Compliance
    • Verify PCI-DSS and other relevant regulatory requirements are met.

File: packages/types/src/commerceSettings.ts
Lines: 12–36

packages/clerk-js/src/utils/componentGuards.ts (6)

25-27: LGTM! Well-implemented user billing guard.

The new guard correctly checks user billing status with proper optional chaining and follows the established patterns in the file.


29-31: LGTM! Consistent organization billing guard implementation.

The guard correctly checks organization billing status and maintains consistency with the user billing guard pattern.


33-35: Excellent composition pattern for combined billing check.

The guard correctly uses logical AND to determine if all billing features are disabled, and properly reuses existing guards following DRY principles. The logic ensures billing is only considered fully disabled when both user and organization billing are disabled.


37-39: LGTM! Correctly updated to use nested billing structure.

The guard properly accesses the new nested organization.hasPaidPlans property with appropriate optional chaining and fallback handling.


41-43: LGTM! Consistent with organization billing guard pattern.

The guard correctly uses the new nested user.hasPaidPlans property and maintains consistency with the organization billing guard implementation.


25-43: No remaining references to the old disabledBillingFeature guard found.

A full-text search across the repository yielded zero matches for disabledBillingFeature, confirming that all references have been updated to the new, granular billing guards. No further action is required.

Comment on lines +99 to +105
{commerceSettings.billing.organization.hasPaidPlans ? (
<Route path='plans'>
<Suspense fallback={''}>
<OrganizationPlansPage />
</Suspense>
</Route>
) : null}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Fix type safety and approve the conditional plans route logic.

The logic to conditionally render the plans route based on available paid plans is excellent and aligns with the PR objectives. However, the same type safety issue exists here with nested property access.

Apply this diff to use optional chaining:

-                {commerceSettings.billing.organization.hasPaidPlans ? (
+                {commerceSettings.billing.organization?.hasPaidPlans ? (
🤖 Prompt for AI Agents
In
packages/clerk-js/src/ui/components/OrganizationProfile/OrganizationProfileRoutes.tsx
around lines 99 to 105, the conditional rendering of the plans route accesses
nested properties without type safety, risking runtime errors. Fix this by using
optional chaining when accessing
commerceSettings.billing.organization.hasPaidPlans to safely handle cases where
any intermediate property might be undefined or null.

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.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy