-
Notifications
You must be signed in to change notification settings - Fork 377
feat(clerk-js): Update SubscriptionDetails to support free trials #6569
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
feat(clerk-js): Update SubscriptionDetails to support free trials #6569
Conversation
🦋 Changeset detectedLatest commit: bbebb54 The changes in this PR will be included in the next version bump. This PR includes changesets to release 22 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for GitHub.
|
@clerk/agent-toolkit
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/dev-cli
@clerk/elements
@clerk/clerk-expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/clerk-react
@clerk/react-router
@clerk/remix
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/themes
@clerk/types
@clerk/upgrade
@clerk/vue
commit: |
📝 WalkthroughWalkthroughAdds free-trial support to SubscriptionDetails: UI labels, badges, headings, menu actions, and confirmation dialogs switch to trial-specific localization keys when selectedSubscription?.isFreeTrial is true. Subscription card and summary show trial-start/end and first-payment details. Two unit tests cover free-trial display and cancellation flow. New en-US localization keys and corresponding type definitions were added. A changeset bumps minor versions for @clerk/localizations, @clerk/clerk-js, and @clerk/types. bundlewatch size threshold for ui-common was slightly increased. Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. 📜 Recent review detailsConfiguration used: CodeRabbit UI 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (4)
packages/clerk-js/src/ui/components/SubscriptionDetails/__tests__/SubscriptionDetails.test.tsx (1)
1189-1196
: Fix ESLint: remove unusedgetAllByText
from destructure
getAllByText
is not used in this test case and triggers @typescript-eslint/no-unused-vars. Remove it (or prefix with_
).Apply this diff:
- const { getByRole, getByText, getAllByText, userEvent } = render( + const { getByRole, getByText, userEvent } = render( <Drawer.Root open onOpenChange={() => {}} > <SubscriptionDetails /> </Drawer.Root>,packages/clerk-js/src/ui/components/SubscriptionDetails/index.tsx (3)
291-302
: Dialog description: correct branching and placeholders
- Free-trial: cancelFreeTrialDescription (plan)
- Upcoming: cancelSubscriptionNoCharge
- Active non-trial: cancelSubscriptionAccessUntil (plan, date)
One small suggestion: avoid the type cast on date by guarding before rendering to make the invariant explicit.
Example:
- : localizationKeys('commerce.cancelSubscriptionAccessUntil', { - plan: selectedSubscription.plan.name, - // this will always be defined in this state - date: selectedSubscription.periodEnd as Date, - }) + : selectedSubscription.periodEnd + ? localizationKeys('commerce.cancelSubscriptionAccessUntil', { + plan: selectedSubscription.plan.name, + date: selectedSubscription.periodEnd, + }) + : localizationKeys('commerce.cancelSubscriptionNoCharge')
341-345
: Optional: avoid template-literal keys for stronger typingUsing a template string inside localizationKeys works but loses key-level type safety. A small refactor keeps typing precise.
- <LineItems.Title - description={localizationKeys( - `commerce.subscriptionDetails.${isFreeTrial ? 'firstPaymentOn' : 'nextPaymentOn'}`, - )} - /> + <LineItems.Title + description={ + isFreeTrial + ? localizationKeys('commerce.subscriptionDetails.firstPaymentOn') + : localizationKeys('commerce.subscriptionDetails.nextPaymentOn') + } + />- <LineItems.Title - description={localizationKeys( - `commerce.subscriptionDetails.${isFreeTrial ? 'firstPaymentAmount' : 'nextPaymentAmount'}`, - )} - /> + <LineItems.Title + description={ + isFreeTrial + ? localizationKeys('commerce.subscriptionDetails.firstPaymentAmount') + : localizationKeys('commerce.subscriptionDetails.nextPaymentAmount') + } + />Also applies to: 349-353
62-76
: Optional: annotate explicit return type for exported componentFor public exports, we prefer explicit return types. Consider annotating
SubscriptionDetails
withJSX.Element
.-export const SubscriptionDetails = (props: __internal_SubscriptionDetailsProps) => { +export const SubscriptionDetails = (props: __internal_SubscriptionDetailsProps): JSX.Element => {
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (5)
.changeset/cruel-bears-sniff.md
(1 hunks)packages/clerk-js/src/ui/components/SubscriptionDetails/__tests__/SubscriptionDetails.test.tsx
(1 hunks)packages/clerk-js/src/ui/components/SubscriptionDetails/index.tsx
(9 hunks)packages/localizations/src/en-US.ts
(3 hunks)packages/types/src/localization.ts
(2 hunks)
🧰 Additional context used
📓 Path-based instructions (17)
.changeset/**
📄 CodeRabbit Inference Engine (.cursor/rules/monorepo.mdc)
Automated releases must use Changesets.
Files:
.changeset/cruel-bears-sniff.md
**/*.{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/types/src/localization.ts
packages/clerk-js/src/ui/components/SubscriptionDetails/__tests__/SubscriptionDetails.test.tsx
packages/clerk-js/src/ui/components/SubscriptionDetails/index.tsx
packages/localizations/src/en-US.ts
**/*.{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/types/src/localization.ts
packages/clerk-js/src/ui/components/SubscriptionDetails/__tests__/SubscriptionDetails.test.tsx
packages/clerk-js/src/ui/components/SubscriptionDetails/index.tsx
packages/localizations/src/en-US.ts
packages/**/*.{ts,tsx}
📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
packages/types/src/localization.ts
packages/clerk-js/src/ui/components/SubscriptionDetails/__tests__/SubscriptionDetails.test.tsx
packages/clerk-js/src/ui/components/SubscriptionDetails/index.tsx
packages/localizations/src/en-US.ts
packages/**/*.{ts,tsx,d.ts}
📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)
Packages should export TypeScript types alongside runtime code
Files:
packages/types/src/localization.ts
packages/clerk-js/src/ui/components/SubscriptionDetails/__tests__/SubscriptionDetails.test.tsx
packages/clerk-js/src/ui/components/SubscriptionDetails/index.tsx
packages/localizations/src/en-US.ts
**/*.{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
Avoidany
type - preferunknown
when type is uncertain, then narrow with type guards
Useinterface
for object shapes that might be extended
Usetype
for unions, primitives, and computed types
Preferreadonly
properties for immutable data structures
Useprivate
for internal implementation details
Useprotected
for inheritance hierarchies
Usepublic
explicitly for clarity in public APIs
Preferreadonly
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
Useconst assertions
for literal types:as const
Usesatisfies
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 ...
Noany
types without justification
Proper error handling with typed errors
Consistent use ofreadonly
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/types/src/localization.ts
packages/clerk-js/src/ui/components/SubscriptionDetails/__tests__/SubscriptionDetails.test.tsx
packages/clerk-js/src/ui/components/SubscriptionDetails/index.tsx
packages/localizations/src/en-US.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/types/src/localization.ts
packages/clerk-js/src/ui/components/SubscriptionDetails/__tests__/SubscriptionDetails.test.tsx
packages/clerk-js/src/ui/components/SubscriptionDetails/index.tsx
packages/localizations/src/en-US.ts
**/*
⚙️ CodeRabbit Configuration File
If there are no tests added or modified as part of the PR, please suggest that tests be added to cover the changes.
Files:
packages/types/src/localization.ts
packages/clerk-js/src/ui/components/SubscriptionDetails/__tests__/SubscriptionDetails.test.tsx
packages/clerk-js/src/ui/components/SubscriptionDetails/index.tsx
packages/localizations/src/en-US.ts
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/SubscriptionDetails/__tests__/SubscriptionDetails.test.tsx
packages/clerk-js/src/ui/components/SubscriptionDetails/index.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/SubscriptionDetails/__tests__/SubscriptionDetails.test.tsx
packages/clerk-js/src/ui/components/SubscriptionDetails/index.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/clerk-js/src/ui/components/SubscriptionDetails/__tests__/SubscriptionDetails.test.tsx
packages/{clerk-js,elements,themes}/**/*.{test,spec}.{js,jsx,ts,tsx}
📄 CodeRabbit Inference Engine (.cursor/rules/monorepo.mdc)
Visual regression testing should be performed for UI components.
Files:
packages/clerk-js/src/ui/components/SubscriptionDetails/__tests__/SubscriptionDetails.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/SubscriptionDetails/__tests__/SubscriptionDetails.test.tsx
packages/clerk-js/src/ui/components/SubscriptionDetails/index.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/SubscriptionDetails/__tests__/SubscriptionDetails.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/SubscriptionDetails/__tests__/SubscriptionDetails.test.tsx
packages/localizations/**/*
📄 CodeRabbit Inference Engine (.cursor/rules/monorepo.mdc)
Localization files must be placed in 'packages/localizations/'.
Files:
packages/localizations/src/en-US.ts
**/localizations/**/*.ts
⚙️ CodeRabbit Configuration File
**/localizations/**/*.ts
: Review the changes to localization files with the following guidelines:
- Ensure that no existing translations are accidentally removed unless they are being replaced or fixed. If a string is removed, verify that it is intentional and justified.
- Check that all translations are friendly, formal, or semi-formal. Explicit, offensive, or inappropriate language is not allowed. If you find any potentially offensive language or are unsure, tag the @clerk/sdk-infra team in a separate comment. If you do not intend to tag the team, refer to it as "Clerk SDK Infra team" instead.
- Use the most up-to-date base localization file (https://github.com/clerk/javascript/blob/main/packages/localizations/src/en-US.ts) to validate changes, ensuring consistency and completeness.
- Confirm that new translations are accurate, contextually appropriate, and match the intent of the original English strings.
- Check for formatting issues, such as missing placeholders, incorrect variable usage, or syntax errors.
- Ensure that all keys are unique and that there are no duplicate or conflicting entries.
- If you notice missing translations for new keys, flag them for completion.
Files:
packages/localizations/src/en-US.ts
🧬 Code Graph Analysis (2)
packages/clerk-js/src/ui/components/SubscriptionDetails/__tests__/SubscriptionDetails.test.tsx (3)
packages/clerk-js/src/ui/elements/Drawer.tsx (1)
Drawer
(555-564)packages/clerk-js/src/ui/components/SubscriptionDetails/index.tsx (1)
SubscriptionDetails
(62-76)packages/clerk-js/src/ui/lazyModules/components.ts (1)
SubscriptionDetails
(116-118)
packages/clerk-js/src/ui/components/SubscriptionDetails/index.tsx (3)
packages/clerk-js/src/ui/customizables/elementDescriptors.ts (1)
descriptors
(565-565)packages/clerk-js/src/ui/elements/LineItems.tsx (1)
LineItems
(289-294)packages/clerk-js/src/ui/utils/formatDate.ts (1)
formatDate
(1-13)
🪛 ESLint
packages/clerk-js/src/ui/components/SubscriptionDetails/__tests__/SubscriptionDetails.test.tsx
[error] 1189-1189: 'getAllByText' is assigned a value but never used. Allowed unused vars must match /^_/u.
(@typescript-eslint/no-unused-vars)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
- GitHub Check: Build Packages
- GitHub Check: Formatting | Dedupe | Changeset
- GitHub Check: semgrep/ci
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (12)
.changeset/cruel-bears-sniff.md (1)
2-7
: Changeset looks correct and scoped to a minor feature bumpMinor version bumps for @clerk/localizations, @clerk/clerk-js, and @clerk/types with a concise feature note align with the surface-area of this PR (new i18n keys, UI work, and types). No concerns.
packages/types/src/localization.ts (2)
190-194
: New commerce free-trial keys are well-typed
- cancelFreeTrial*, keepFreeTrial entries added under commerce with correct param typing (plan where needed).
- Matches usage in UI and strings in en-US.
No issues.
219-224
: subscriptionDetails additions for trial/first-payment are consistent
- firstPaymentOn/Amount and trialStartedOn/EndsOn added with plain LocalizationValue, which matches their usage patterns.
- Complements existing nextPayment* keys without breaking older flows.
Looks good.
packages/clerk-js/src/ui/components/SubscriptionDetails/__tests__/SubscriptionDetails.test.tsx (1)
1016-1123
: Good coverage for active free-trial UI and actionsThe test asserts all free-trial-specific labels, hides regular-subscription labels, and verifies the menu action. This aligns with the new i18n keys and gating logic. Nice.
packages/localizations/src/en-US.ts (2)
67-71
: Free-trial dialog copy: accurate and aligned with types
- cancelFreeTrial, cancelFreeTrialTitle, cancelFreeTrialDescription, keepFreeTrial are added and use the expected {{plan}} placeholder where appropriate.
- Tone and phrasing fit the product voice.
Approved.
148-155
: subscriptionDetails “first payment” and “trial” labels: LGTMThe new keys (firstPaymentOn/Amount, trialStartedOn/EndsOn) are present and used by the updated UI/tests. No placeholder or formatting issues spotted.
packages/clerk-js/src/ui/components/SubscriptionDetails/index.tsx (6)
246-251
: Confirmation “keep” action correctly switches for free trialSwitching the secondary button’s localization key to keepFreeTrial when isFreeTrial is true is correct and matches the UX.
261-266
: Confirmation “cancel” action properly contextualized for free trialUsing the cancelFreeTrial key with the plan name parameter is consistent with the title/description and tests. Good.
278-285
: Dialog title: correct localization gating and params
- Free-trial: cancelFreeTrialTitle with plan param
- Regular: cancelSubscriptionTitle with computed plan label
This matches the string contracts.
326-357
: Summary uses “first payment” wording on free trials: correctDeriving isFreeTrial from the active subscription and swapping nextPayment* to firstPayment* provides the right semantics for trials. Nicely done.
564-568
: Detail labels correctly switch for trials
- SubscribedOn → Trial started on
- RenewsAt → Trial ends on (unless canceled)
Matches the expected UX and localizations.
Also applies to: 575-582
526-527
: No changes needed—SubscriptionBadge supports the simplified{ status: 'free_trial' }
prop
TheSubscriptionBadge
component is defined as:export const SubscriptionBadge = <T extends { status: CommerceSubscriptionItemResource['status'] }>({ subscription, elementDescriptor, }: { subscription: T | { status: 'free_trial' }; elementDescriptor?: ElementDescriptor; }) => { … }Since its
subscription
prop already allows the{ status: 'free_trial' }
shape, passing only{ status: 'free_trial' }
whensubscription.isFreeTrial
is fully supported.
34276a4
to
fee72b9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (4)
packages/clerk-js/bundlewatch.config.json (1)
7-7
: Slight bundle ceiling bump is fine; keep an eye on incremental driftThe +0.1KB tolerance for ui-common*.js seems reasonable for the new feature. Please keep these increases minimal and justified to avoid threshold creep over time. If the final built size fits under the old 114KB after tree-shaking tweaks, consider reverting.
packages/clerk-js/src/ui/components/SubscriptionDetails/__tests__/SubscriptionDetails.test.tsx (1)
1213-1221
: Nit: Localization copy may read a bit awkward (“Plan plan”)The title string results in “Cancel free trial for Pro Plan plan?”. Consider updating the en-US localization to avoid the double “plan” (e.g., “Cancel free trial for Pro Plan?”). Tests will need updating accordingly if you change the copy.
packages/clerk-js/src/ui/components/SubscriptionDetails/index.tsx (2)
277-285
: Title handling is correct; consider refining localization to avoid “Plan plan”Functionally correct. As a copy nit, the
cancelFreeTrialTitle
key that renders “Cancel free trial for {plan} plan?” can sound repetitive depending on plan names (“Pro Plan plan”). Consider revising the localized string to “Cancel free trial for {plan}?” and adjusting tests accordingly.
526-528
: Avoid passing a partial “subscription-like” object to SubscriptionBadgeYou’re constructing
{ status: 'free_trial' }
to drive the badge. IfSubscriptionBadge
expects aCommerceSubscriptionItemResource
, this is brittle and undermines type safety. Prefer one of:
- Add a
statusOverride?: 'free_trial' | ...
prop toSubscriptionBadge
, or- Move the
isFreeTrial
check insideSubscriptionBadge
and render the free-trial badge based on the real subscription.This keeps props typed and avoids sneaky runtime surprises if
SubscriptionBadge
starts relying on additional fields later.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (6)
.changeset/cruel-bears-sniff.md
(1 hunks)packages/clerk-js/bundlewatch.config.json
(1 hunks)packages/clerk-js/src/ui/components/SubscriptionDetails/__tests__/SubscriptionDetails.test.tsx
(1 hunks)packages/clerk-js/src/ui/components/SubscriptionDetails/index.tsx
(9 hunks)packages/localizations/src/en-US.ts
(3 hunks)packages/types/src/localization.ts
(2 hunks)
✅ Files skipped from review due to trivial changes (1)
- .changeset/cruel-bears-sniff.md
🚧 Files skipped from review as they are similar to previous changes (2)
- packages/localizations/src/en-US.ts
- packages/types/src/localization.ts
🧰 Additional context used
📓 Path-based instructions (14)
**/*.{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/bundlewatch.config.json
packages/clerk-js/src/ui/components/SubscriptionDetails/index.tsx
packages/clerk-js/src/ui/components/SubscriptionDetails/__tests__/SubscriptionDetails.test.tsx
**/*
⚙️ CodeRabbit Configuration File
If there are no tests added or modified as part of the PR, please suggest that tests be added to cover the changes.
Files:
packages/clerk-js/bundlewatch.config.json
packages/clerk-js/src/ui/components/SubscriptionDetails/index.tsx
packages/clerk-js/src/ui/components/SubscriptionDetails/__tests__/SubscriptionDetails.test.tsx
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/SubscriptionDetails/index.tsx
packages/clerk-js/src/ui/components/SubscriptionDetails/__tests__/SubscriptionDetails.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/SubscriptionDetails/index.tsx
packages/clerk-js/src/ui/components/SubscriptionDetails/__tests__/SubscriptionDetails.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/SubscriptionDetails/index.tsx
packages/clerk-js/src/ui/components/SubscriptionDetails/__tests__/SubscriptionDetails.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/SubscriptionDetails/index.tsx
packages/clerk-js/src/ui/components/SubscriptionDetails/__tests__/SubscriptionDetails.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
Avoidany
type - preferunknown
when type is uncertain, then narrow with type guards
Useinterface
for object shapes that might be extended
Usetype
for unions, primitives, and computed types
Preferreadonly
properties for immutable data structures
Useprivate
for internal implementation details
Useprotected
for inheritance hierarchies
Usepublic
explicitly for clarity in public APIs
Preferreadonly
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
Useconst assertions
for literal types:as const
Usesatisfies
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 ...
Noany
types without justification
Proper error handling with typed errors
Consistent use ofreadonly
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/SubscriptionDetails/index.tsx
packages/clerk-js/src/ui/components/SubscriptionDetails/__tests__/SubscriptionDetails.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/SubscriptionDetails/index.tsx
packages/clerk-js/src/ui/components/SubscriptionDetails/__tests__/SubscriptionDetails.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/clerk-js/src/ui/components/SubscriptionDetails/index.tsx
packages/clerk-js/src/ui/components/SubscriptionDetails/__tests__/SubscriptionDetails.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/SubscriptionDetails/index.tsx
packages/clerk-js/src/ui/components/SubscriptionDetails/__tests__/SubscriptionDetails.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/clerk-js/src/ui/components/SubscriptionDetails/__tests__/SubscriptionDetails.test.tsx
packages/{clerk-js,elements,themes}/**/*.{test,spec}.{js,jsx,ts,tsx}
📄 CodeRabbit Inference Engine (.cursor/rules/monorepo.mdc)
Visual regression testing should be performed for UI components.
Files:
packages/clerk-js/src/ui/components/SubscriptionDetails/__tests__/SubscriptionDetails.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/SubscriptionDetails/__tests__/SubscriptionDetails.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/SubscriptionDetails/__tests__/SubscriptionDetails.test.tsx
🧬 Code Graph Analysis (2)
packages/clerk-js/src/ui/components/SubscriptionDetails/index.tsx (3)
packages/clerk-js/src/ui/customizables/elementDescriptors.ts (1)
descriptors
(565-565)packages/clerk-js/src/ui/elements/LineItems.tsx (1)
LineItems
(289-294)packages/clerk-js/src/ui/utils/formatDate.ts (1)
formatDate
(1-13)
packages/clerk-js/src/ui/components/SubscriptionDetails/__tests__/SubscriptionDetails.test.tsx (3)
packages/clerk-js/src/ui/elements/Drawer.tsx (1)
Drawer
(555-564)packages/clerk-js/src/ui/components/SubscriptionDetails/index.tsx (1)
SubscriptionDetails
(62-76)packages/clerk-js/src/ui/lazyModules/components.ts (1)
SubscriptionDetails
(116-118)
🪛 ESLint
packages/clerk-js/src/ui/components/SubscriptionDetails/__tests__/SubscriptionDetails.test.tsx
[error] 1189-1189: 'getAllByText' is assigned a value but never used. Allowed unused vars must match /^_/u.
(@typescript-eslint/no-unused-vars)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
- GitHub Check: Build Packages
- GitHub Check: Formatting | Dedupe | Changeset
- GitHub Check: semgrep/ci
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (8)
packages/clerk-js/src/ui/components/SubscriptionDetails/__tests__/SubscriptionDetails.test.tsx (1)
1017-1123
: LGTM: Solid coverage for free-trial display and menu actionGood assertions for trial-specific labels, payment wording, and the “Cancel free trial” menu item. This meaningfully exercises the new UX.
packages/clerk-js/src/ui/components/SubscriptionDetails/index.tsx (7)
246-251
: Good: “Keep” action adapts to free-trial stateSwitching the ghost button label between keepSubscription and keepFreeTrial aligns with the new flow and maintains localization. Looks correct.
260-266
: Good: “Cancel” action leverages trial-aware localization with plan interpolationThe dynamic label properly injects the plan name for free trials. Matches the test assertions.
291-302
: Description branches cover all states cleanlyThe free-trial description route vs. upcoming vs. access-until is well delineated. Using
handleError
in the cancel path adheres to error-handling guidelines. No issues.
326-353
: Nice: Summary switches to “first payment” wording when on free trialUsing
firstPaymentOn
/firstPaymentAmount
whenisFreeTrial
keeps the semantics accurate. Localization keys are used consistently.
426-433
: Menu action label correctly maps to trial-aware cancellationGood conditional on
subscription.isFreeTrial
to surface the correct destructive action and copy.
564-580
: Good: Trial-aware detail labelsSwitching
subscribedOn
->trialStartedOn
andrenewsAt
->trialEndsOn
(when not canceled) makes the card details accurate for trials and keeps i18n intact.
326-327
:isFreeTrial
field confirmed on CommerceSubscriptionItemResourceThe
CommerceSubscriptionItemResource
interface inpackages/types/src/commerce.ts
(line 1077) declaresisFreeTrial: boolean
, so usingsubscription.isFreeTrial
here is safe.
Description
This PR introduces new labels and CTAs that reflect the free trial state inside
<SubscriptionDetails/>
.Checklist
pnpm test
runs as expected.pnpm build
runs as expected.Type of change
Summary by CodeRabbit
New Features
Tests
Chores