Skip to content

Conversation

@panteliselef
Copy link
Contributor

@panteliselef panteliselef commented Jun 25, 2025

Description

React

Usage without provider

const {
  // Resource properties
  id,
  paymentSource,
  plan,
  externalClientSecret,
  planPeriod,
  planPeriodStart,
  totals,
  isImmediatePlanChange,
  
  // helpers
  isStarting,
  isConfirming,
  status,
  error,
  fetchStatus,
  
  
  // methods
  start,
  confirm,
  clear,
  finalize
} = useCheckout({ planId: "cplan_xxx", planPeriod: "month" });

Usage with provider

<CheckoutProvider for="user" planId="cplan_xxxx" planPeriod="month">
   <UpgragdeButton />
</CheckoutProvider>

function UpgragdeButton() {
   const checkout = useCheckout();
}

Vanilla JS

const checkout = Clek.checkout({ 
	for: "org",
	planId:"cplan_xxx",
	planPeriod: "month"
})

const { data, error} = await checkout.start()
const { data, error} = await  checkout.confirm()
checkout.finalize()
checkout.clear()
checkout.subscribe()
checkout.getState()

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Summary by CodeRabbit

  • New Features

    • Introduced an experimental billing and checkout experience, including a new useCheckout() hook and <CheckoutProvider/> component for managing checkout flows.
    • Added an experimental checkout method for programmatic management of checkout sessions.
    • Enhanced error handling and status tracking within checkout-related components.
  • Refactor

    • Unified and simplified checkout-related components to use the new experimental hook and provider, replacing manual state and error management.
    • Updated context providers to include the new checkout provider for centralized state management.
    • Consolidated checkout UI stages and improved conditional rendering based on fetch status.
  • Tests

    • Added comprehensive tests covering checkout state management, concurrency, error handling, and TypeScript type validation.
  • Chores

    • Updated test configurations and scripts to include Vitest alongside Jest.
    • Adjusted bundle size limits for UI common files.

@changeset-bot
Copy link

changeset-bot bot commented Jun 25, 2025

🦋 Changeset detected

Latest commit: 64c24fb

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

This PR includes changesets to release 22 packages
Name Type
@clerk/tanstack-react-start Minor
@clerk/react-router Minor
@clerk/nextjs Minor
@clerk/shared Minor
@clerk/clerk-react Minor
@clerk/remix Minor
@clerk/clerk-js Minor
@clerk/types Minor
@clerk/agent-toolkit Patch
@clerk/astro Patch
@clerk/backend Patch
@clerk/chrome-extension Patch
@clerk/elements Patch
@clerk/expo-passkeys Patch
@clerk/clerk-expo Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/nuxt Patch
@clerk/testing Patch
@clerk/vue Patch
@clerk/localizations Patch
@clerk/themes 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 Jun 25, 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 11, 2025 7:10pm

@panteliselef
Copy link
Contributor Author

!snapshot

@clerk-cookie
Copy link
Collaborator

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

Package Version
@clerk/agent-toolkit 0.1.3-snapshot.v20250626091436
@clerk/astro 2.9.3-snapshot.v20250626091436
@clerk/backend 2.2.1-snapshot.v20250626091436
@clerk/chrome-extension 2.5.1-snapshot.v20250626091436
@clerk/clerk-js 5.70.0-snapshot.v20250626091436
@clerk/elements 0.23.35-snapshot.v20250626091436
@clerk/clerk-expo 2.14.0-snapshot.v20250626091436
@clerk/expo-passkeys 0.3.12-snapshot.v20250626091436
@clerk/express 1.7.2-snapshot.v20250626091436
@clerk/fastify 2.4.2-snapshot.v20250626091436
@clerk/localizations 3.17.1-snapshot.v20250626091436
@clerk/nextjs 6.24.0-snapshot.v20250626091436
@clerk/nuxt 1.7.3-snapshot.v20250626091436
@clerk/clerk-react 5.33.0-snapshot.v20250626091436
@clerk/react-router 1.6.2-snapshot.v20250626091436
@clerk/remix 4.8.3-snapshot.v20250626091436
@clerk/shared 3.10.0-snapshot.v20250626091436
@clerk/tanstack-react-start 0.18.1-snapshot.v20250626091436
@clerk/testing 1.8.3-snapshot.v20250626091436
@clerk/themes 2.2.52-snapshot.v20250626091436
@clerk/types 4.62.0-snapshot.v20250626091436
@clerk/vue 1.8.10-snapshot.v20250626091436

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

npm i @clerk/[email protected] --save-exact

@clerk/astro

npm i @clerk/[email protected] --save-exact

@clerk/backend

npm i @clerk/[email protected] --save-exact

@clerk/chrome-extension

npm i @clerk/[email protected] --save-exact

@clerk/clerk-js

npm i @clerk/[email protected] --save-exact

@clerk/elements

npm i @clerk/[email protected] --save-exact

@clerk/clerk-expo

npm i @clerk/[email protected] --save-exact

@clerk/expo-passkeys

npm i @clerk/[email protected] --save-exact

@clerk/express

npm i @clerk/[email protected] --save-exact

@clerk/fastify

npm i @clerk/[email protected] --save-exact

@clerk/localizations

npm i @clerk/[email protected] --save-exact

@clerk/nextjs

npm i @clerk/[email protected] --save-exact

@clerk/nuxt

npm i @clerk/[email protected] --save-exact

@clerk/clerk-react

npm i @clerk/[email protected] --save-exact

@clerk/react-router

npm i @clerk/[email protected] --save-exact

@clerk/remix

npm i @clerk/[email protected] --save-exact

@clerk/shared

npm i @clerk/[email protected] --save-exact

@clerk/tanstack-react-start

npm i @clerk/[email protected] --save-exact

@clerk/testing

npm i @clerk/[email protected] --save-exact

@clerk/themes

npm i @clerk/[email protected] --save-exact

@clerk/types

npm i @clerk/[email protected] --save-exact

@clerk/vue

npm i @clerk/[email protected] --save-exact

@clerk clerk deleted a comment from clerk-cookie Jun 26, 2025
@panteliselef
Copy link
Contributor Author

!snapshot

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

♻️ Duplicate comments (4)
packages/shared/src/react/hooks/useCheckout.ts (3)

18-20: Replace any with proper function type constraint.

The use of any violates TypeScript best practices. Consider using a more specific function type or unknown with proper type narrowing.

-type RemoveFunctions<T> = {
-  [K in keyof T as T[K] extends (...args: any[]) => any ? never : K]: T[K];
-};
+type RemoveFunctions<T> = {
+  [K in keyof T as T[K] extends (...args: unknown[]) => unknown ? never : K]: T[K];
+};

54-54: Add JSDoc documentation for the exported public API.

This exported hook lacks comprehensive documentation. The coding guidelines require JSDoc comments for public APIs including @param, @returns, @throws, and @example.

+/**
+ * Hook for managing checkout state and actions in commerce flows.
+ * 
+ * @param options - Configuration options for the checkout
+ * @param options.for - Specifies if checkout is for 'organization' 
+ * @param options.planId - The subscription plan ID
+ * @param options.planPeriod - The plan billing period
+ * @returns Object containing checkout state and management methods
+ * @throws Error when user is not authenticated
+ * @throws Error when organization checkout is requested but no active organization
+ * @example
+ * ```tsx
+ * const { checkout } = useCheckout({
+ *   for: 'organization',
+ *   planId: 'plan_123',
+ *   planPeriod: 'monthly'
+ * });
+ * ```
+ */
 export const useCheckout = (options?: UseCheckoutOptions): __experimental_UseCheckoutReturn => {

109-110: Fix TypeScript error suppression with proper type handling.

The @ts-ignore comment suppresses TypeScript errors instead of addressing the underlying type mismatch. This violates coding guidelines and can lead to runtime issues.

The checkout: null assignment suggests a type structure issue. Consider either:

  1. Removing the checkout property from the destructured object in the properties memoization
  2. Properly typing the return object to handle this property
   const checkout = {
     ...properties,
     getState: manager.getState,
-    // @ts-ignore
-    checkout: null,
     start: manager.start,

If the checkout property needs to be excluded from the properties object, handle it in the destructuring:

   const {
     reload,
     confirm,
     pathRoot,
+    checkout,
     // All the above need to be removed from the properties
     ...rest
   } = managerProperties.checkout;
packages/clerk-js/src/core/modules/checkout/__tests__/manager.spec.ts (1)

510-512: Replace non-null assertion with proper type narrowing.

The non-null assertion operator ! is discouraged by the coding guidelines. Consider using proper type narrowing instead to ensure type safety.

       // Resolve the operation
-      resolveOperation!(mockCheckout);
+      if (resolveOperation) {
+        resolveOperation(mockCheckout);
+      }
       await operationPromise;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ba655f9 and 3f97051.

📒 Files selected for processing (6)
  • packages/clerk-js/src/core/modules/checkout/__tests__/manager.spec.ts (1 hunks)
  • packages/clerk-js/src/core/modules/checkout/instance.ts (1 hunks)
  • packages/clerk-js/src/core/modules/checkout/manager.ts (1 hunks)
  • packages/shared/src/react/hooks/__tests__/useCheckout.type.spec.ts (1 hunks)
  • packages/shared/src/react/hooks/useCheckout.ts (1 hunks)
  • packages/types/src/clerk.ts (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • packages/clerk-js/src/core/modules/checkout/instance.ts
  • packages/shared/src/react/hooks/tests/useCheckout.type.spec.ts
  • packages/clerk-js/src/core/modules/checkout/manager.ts
  • packages/types/src/clerk.ts
🧰 Additional context used
📓 Path-based instructions (10)
`**/*.{js,jsx,ts,tsx}`: All code must pass ESLint checks with the project's conf...

**/*.{js,jsx,ts,tsx}: All code must pass ESLint checks with the project's configuration
Use Prettier for consistent code formatting
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
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Validate all inputs and sanitize outputs
Implement proper logging with different levels

📄 Source: CodeRabbit Inference Engine (.cursor/rules/development.mdc)

List of files the instruction was applied to:

  • packages/shared/src/react/hooks/useCheckout.ts
  • packages/clerk-js/src/core/modules/checkout/__tests__/manager.spec.ts
`packages/**/*.ts`: TypeScript is required for all packages

packages/**/*.ts: TypeScript is required for all packages

📄 Source: CodeRabbit Inference Engine (.cursor/rules/development.mdc)

List of files the instruction was applied to:

  • packages/shared/src/react/hooks/useCheckout.ts
  • packages/clerk-js/src/core/modules/checkout/__tests__/manager.spec.ts
`packages/**/*.{ts,tsx,d.ts}`: Packages should export TypeScript types alongside runtime code

packages/**/*.{ts,tsx,d.ts}: Packages should export TypeScript types alongside runtime code

📄 Source: CodeRabbit Inference Engine (.cursor/rules/development.mdc)

List of files the instruction was applied to:

  • packages/shared/src/react/hooks/useCheckout.ts
  • packages/clerk-js/src/core/modules/checkout/__tests__/manager.spec.ts
`**/*.{ts,tsx}`: Use proper TypeScript error types

**/*.{ts,tsx}: Use proper TypeScript error types

📄 Source: CodeRabbit Inference Engine (.cursor/rules/development.mdc)

List of files the instruction was applied to:

  • packages/shared/src/react/hooks/useCheckout.ts
  • packages/clerk-js/src/core/modules/checkout/__tests__/manager.spec.ts
`**/*.{ts,tsx}`: Always define explicit return types for functions, especially p...

**/*.{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
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
Document public functions and APIs with JSDoc-style comments including @param, @returns, @throws, and @example
Define custom error classes for domain-specific errors
Use the Result pattern for error handling instead of throwing exceptions
Use optional chaining and nullish coalescing for safe property access
Let TypeScript infer types when types are obvious
Use const assertions for literal types: as const
Use satisfies operator for type checking without widening
Use readonly arrays and objects for immutability
Use immutable update patterns (spread, etc.) for objects and arrays
Use lazy loading for large types
Prefer unknown over any for performance
Use type-only imports: import type { ... }
Use branded types for domain safety
No any types without justification
Proper error handling with typed errors
Consistent use of readonly for immutable data
Proper generic constraints in TypeScript generics
No unused type parameters in generics
Proper use of utility types instead of manual type construction
Type-only imports where possible for performance
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)

📄 Source: CodeRabbit Inference Engine (.cursor/rules/typescript.mdc)

List of files the instruction was applied to:

  • packages/shared/src/react/hooks/useCheckout.ts
  • packages/clerk-js/src/core/modules/checkout/__tests__/manager.spec.ts
`**/*.ts`: If there are no tests added or modified as part of the PR, please suggest that tests be added to cover the changes.

**/*.ts: If there are no tests added or modified as part of the PR, please suggest that tests be added to cover the changes.

⚙️ Source: CodeRabbit Configuration File

List of files the instruction was applied to:

  • packages/shared/src/react/hooks/useCheckout.ts
  • packages/clerk-js/src/core/modules/checkout/__tests__/manager.spec.ts
`**/{__tests__,**/__tests__}/**/*.{js,jsx,ts,tsx}`: Test files should be co-located with source files or in `__tests__` directories

**/{__tests__,**/__tests__}/**/*.{js,jsx,ts,tsx}: Test files should be co-located with source files or in __tests__ directories

📄 Source: CodeRabbit Inference Engine (.cursor/rules/development.mdc)

List of files the instruction was applied to:

  • packages/clerk-js/src/core/modules/checkout/__tests__/manager.spec.ts
`**/*.{test,spec}.{js,ts,tsx}`: Unit tests should use Jest or Vitest as the test runner.

**/*.{test,spec}.{js,ts,tsx}: Unit tests should use Jest or Vitest as the test runner.

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

List of files the instruction was applied to:

  • packages/clerk-js/src/core/modules/checkout/__tests__/manager.spec.ts
`packages/{clerk-js,elements,themes}/**/*`: Visual regression testing should be performed for UI components.

packages/{clerk-js,elements,themes}/**/*: Visual regression testing should be performed for UI components.

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

List of files the instruction was applied to:

  • packages/clerk-js/src/core/modules/checkout/__tests__/manager.spec.ts
`**/__tests__/**/*.{ts,tsx}`: Use Vitest for type-safe testing in TypeScript Cre...

**/__tests__/**/*.{ts,tsx}: Use Vitest for type-safe testing in TypeScript
Create type-safe test builders/factories
Use branded types for test isolation
Implement proper mock types that match interfaces in tests

📄 Source: CodeRabbit Inference Engine (.cursor/rules/typescript.mdc)

List of files the instruction was applied to:

  • packages/clerk-js/src/core/modules/checkout/__tests__/manager.spec.ts
🧠 Learnings (3)
📓 Common learnings
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-react/**/*.{test,spec}.{js,ts,tsx} : Component testing should use React Testing Library.
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: 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: bratsos
PR: clerk/javascript#6259
File: packages/clerk-js/src/ui/components/SignUp/signUpFormHelpers.ts:377-379
Timestamp: 2025-07-07T16:57:10.869Z
Learning: In the Clerk JavaScript repository, when working with TypeScript decision tables or rule-based systems, redundant-looking ternary operators may be intentionally kept for TypeScript type narrowing when the compiler cannot infer that a value is non-null despite conditional checks. This is a pragmatic approach to handle TypeScript's type system limitations without overcomplicating the code.
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 useState for simple state management
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: 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 proper hook structure
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 cleanup
packages/shared/src/react/hooks/useCheckout.ts (34)
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/react.mdc:0-0
Timestamp: 2025-06-30T10:32:37.848Z
Learning: Applies to **/*.{jsx,tsx} : Use useState for simple state management
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 useReducer for complex state logic
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/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 **/*.tsx : Use proper type definitions for props and state
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: 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 initialization
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: LauraBeatris
PR: clerk/javascript#6117
File: packages/clerk-js/src/ui/components/SessionTasks/tasks/ForceOrganizationSelection.tsx:17-21
Timestamp: 2025-06-18T23:27:13.537Z
Learning: In Clerk's JavaScript codebase, query errors from hooks like useOrganizationList are not typically handled in AIO (All-in-One) components. Error handling may be connected with the Card context instead, suggesting a centralized error handling approach rather than component-level error handling.
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/development.mdc:0-0
Timestamp: 2025-06-30T10:29:42.997Z
Learning: Applies to **/*.{ts,tsx} : Use proper TypeScript error types
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 proper type annotations for variables and parameters where inference isn't clear
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 error handling with typed errors
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/typescript.mdc:0-0
Timestamp: 2025-06-30T10:33:45.961Z
Learning: Applies to **/*.{ts,tsx} : Avoid `any` type - prefer `unknown` when type is uncertain, then narrow with type guards
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} : Always define explicit return types for functions, especially public APIs
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/typescript.mdc:0-0
Timestamp: 2025-06-30T10:33:45.961Z
Learning: Applies to **/__tests__/**/*.{ts,tsx} : Implement proper mock types that match interfaces in tests
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 event types for handlers
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} : No `any` types without justification
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} : Prefer `unknown` over `any` for performance
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: CR
PR: clerk/javascript#0
File: .cursor/rules/typescript.mdc:0-0
Timestamp: 2025-06-30T10:33:45.961Z
Learning: Applies to **/*.{ts,tsx} : No unused type parameters in generics
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 generic constraints in TypeScript generics
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} : Document public functions and APIs with JSDoc-style comments including @param, @returns, @throws, and @example
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} : Maintain comprehensive JSDoc comments for 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} : All public APIs must be documented with JSDoc
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/development.mdc:0-0
Timestamp: 2025-06-30T10:29:42.997Z
Learning: Use TypeDoc for generating API documentation
Learnt from: wobsoriano
PR: clerk/javascript#6229
File: packages/backend/src/api/endpoints/MachineTokensApi.ts:47-89
Timestamp: 2025-07-01T15:20:41.834Z
Learning: In the Clerk JavaScript repository, for the MachineTokensApi class (packages/backend/src/api/endpoints/MachineTokensApi.ts), the maintainers prefer to rely on TypeScript types and readable property names for API documentation rather than JSDoc comments.
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/react.mdc:0-0
Timestamp: 2025-06-30T10:32:37.848Z
Learning: Applies to **/*.{jsx,tsx} : Implement proper error states
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 optional chaining and nullish coalescing for safe property access
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 normalization
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} : Consistent use of `readonly` for immutable data
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 immutable update patterns (spread, etc.) for objects and arrays
packages/clerk-js/src/core/modules/checkout/__tests__/manager.spec.ts (15)
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/typescript.mdc:0-0
Timestamp: 2025-06-30T10:33:45.961Z
Learning: Applies to **/__tests__/**/*.{ts,tsx} : Create type-safe test builders/factories
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/*/jest.config.{js,ts} : Each framework integration package must have its own test configuration.
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/development.mdc:0-0
Timestamp: 2025-06-30T10:29:42.997Z
Learning: Include tests for all new features
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/typescript.mdc:0-0
Timestamp: 2025-06-30T10:33:45.961Z
Learning: Applies to **/__tests__/**/*.{ts,tsx} : Use branded types for test isolation
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/typescript.mdc:0-0
Timestamp: 2025-06-30T10:33:45.961Z
Learning: Applies to **/__tests__/**/*.{ts,tsx} : Implement proper mock types that match interfaces in tests
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/development.mdc:0-0
Timestamp: 2025-06-30T10:29:42.997Z
Learning: Unit tests are required for all new functionality
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/react.mdc:0-0
Timestamp: 2025-06-30T10:32:37.848Z
Learning: Applies to **/*.test.{jsx,tsx} : Implement proper test assertions
Learnt from: bratsos
PR: clerk/javascript#6259
File: packages/clerk-js/src/ui/components/SignUp/signUpFormHelpers.ts:377-379
Timestamp: 2025-07-07T16:57:10.869Z
Learning: In the Clerk JavaScript repository, when working with TypeScript decision tables or rule-based systems, redundant-looking ternary operators may be intentionally kept for TypeScript type narrowing when the compiler cannot infer that a value is non-null despite conditional checks. This is a pragmatic approach to handle TypeScript's type system limitations without overcomplicating the code.
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 optional chaining and nullish coalescing for safe property access
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 `satisfies` operator for type checking without widening
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 `const assertions` for literal types: `as const`
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 **/*.test.{jsx,tsx} : Implement proper test isolation
🧬 Code Graph Analysis (2)
packages/shared/src/react/hooks/useCheckout.ts (5)
packages/types/src/commerce.ts (2)
  • CommerceCheckoutResource (218-231)
  • CommerceSubscriptionPlanPeriod (21-21)
packages/types/src/clerk.ts (2)
  • __experimental_CheckoutInstance (88-95)
  • __experimental_CheckoutCacheState (63-70)
packages/shared/src/react/hooks/index.ts (4)
  • useCheckout (15-15)
  • useClerk (8-8)
  • useOrganization (2-2)
  • useUser (7-7)
packages/shared/src/react/contexts.tsx (1)
  • useCheckoutContext (117-117)
packages/react/src/isomorphicClerk.ts (2)
  • user (659-665)
  • organization (667-673)
packages/clerk-js/src/core/modules/checkout/__tests__/manager.spec.ts (2)
packages/types/src/commerce.ts (1)
  • CommerceCheckoutResource (218-231)
packages/clerk-js/src/core/modules/checkout/manager.ts (3)
  • CheckoutKey (187-187)
  • createCheckoutManager (187-187)
  • FETCH_STATUS (44-48)
🪛 ESLint
packages/clerk-js/src/core/modules/checkout/__tests__/manager.spec.ts

[error] 511-511: Forbidden non-null assertion.

(@typescript-eslint/no-non-null-assertion)

⏰ 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). (4)
  • GitHub Check: Build Packages
  • GitHub Check: Formatting | Dedupe | Changeset
  • GitHub Check: semgrep/ci
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (2)
packages/clerk-js/src/core/modules/checkout/__tests__/manager.spec.ts (2)

8-55: Excellent test structure with type-safe mocks!

The test helpers (createMockCheckoutResource, createMockError, createCacheKey) follow best practices for creating type-safe test builders. The mock factories ensure comprehensive coverage of the CommerceCheckoutResource interface while maintaining flexibility through partial overrides.


56-695: Comprehensive test coverage with excellent isolation!

The test suite provides thorough coverage of the checkout manager functionality including:

  • State management and immutability
  • Subscription lifecycle and listener isolation
  • Operation execution with proper loading states
  • Concurrent operation deduplication
  • Error propagation and recovery
  • Cache isolation between different keys
  • State derivation logic

The tests follow best practices with proper setup/teardown, type-safe mocks, and clear assertions.

@panteliselef panteliselef merged commit f6a1c35 into main Jul 11, 2025
36 checks passed
@panteliselef panteliselef deleted the elef/com-960-useCheckout branch July 11, 2025 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants