Skip to content

Conversation

@jacekradko
Copy link
Member

@jacekradko jacekradko commented Jan 8, 2026

Description

Also adding fixes from #7544

Fixes: USER-4251

Snapshot deployed to https://github.com/clerk/dashboard/pull/7966

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

  • Dependencies

    • Replaced SWR with React Query (TanStack Query) and promoted it to a runtime dependency (v5.90.16).
  • Bug Fixes

    • Fixed useClearQueriesOnSignOut by adjusting effect dependency and guard behavior.
  • Chores

    • Removed environment-based conditional code paths for consistent behavior.
    • Simplified SWR compatibility wrappers and testing helpers.
  • Tests

    • Added and expanded pagination utility tests for more robust coverage.

✏️ Tip: You can customize this high-level summary in your review settings.

@changeset-bot
Copy link

changeset-bot bot commented Jan 8, 2026

🦋 Changeset detected

Latest commit: aa68070

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

This PR includes changesets to release 20 packages
Name Type
@clerk/shared Major
@clerk/agent-toolkit Patch
@clerk/astro Patch
@clerk/backend Patch
@clerk/chrome-extension Patch
@clerk/clerk-js Patch
@clerk/expo-passkeys Patch
@clerk/expo Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/localizations Patch
@clerk/msw Patch
@clerk/nextjs Patch
@clerk/nuxt Patch
@clerk/react-router Patch
@clerk/react Patch
@clerk/tanstack-react-start Patch
@clerk/testing Patch
@clerk/ui 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

@vercel
Copy link

vercel bot commented Jan 8, 2026

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

Project Deployment Review Updated (UTC)
clerk-js-sandbox Ready Ready Preview, Comment Jan 8, 2026 10:13pm

@jacekradko
Copy link
Member Author

!allow-major

@jacekradko jacekradko changed the title feat(shared): Remove SWR feat(shared): Remove SWR Jan 8, 2026
@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 8, 2026

Open in StackBlitz

@clerk/agent-toolkit

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

@clerk/astro

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

@clerk/backend

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

@clerk/chrome-extension

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

@clerk/clerk-js

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

@clerk/dev-cli

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

@clerk/expo

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

@clerk/expo-passkeys

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

@clerk/express

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

@clerk/fastify

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

@clerk/localizations

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

@clerk/nextjs

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

@clerk/nuxt

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

@clerk/react

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

@clerk/react-router

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

@clerk/shared

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

@clerk/tanstack-react-start

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

@clerk/testing

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

@clerk/ui

npm i https://pkg.pr.new/@clerk/ui@7568

@clerk/upgrade

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

@clerk/vue

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

commit: aa68070

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 8, 2026

Caution

Review failed

An error occurred during the review process. Please try again later.

📝 Walkthrough

Walkthrough

Removes SWR-based implementations and virtual data-hook shims across the shared package, deletes the CLERK_USE_RQ flag and related typings/config, promotes @tanstack/query-core to a runtime dependency, removes SWR from shared and ui packages, replaces re-export shims with concrete React Query implementations, updates providers and test helpers to drop SWR compatibility, and updates tests to remove environment-conditional assertions. Many .swr.tsx files and the virtual:data-hooks declarations were deleted or replaced with .tsx React Query implementations.

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning Most changes directly support SWR removal and the USER-4251 fixes. The bundlewatch config size increase (128KB to 129KB) appears out of scope and may indicate a build artifact change unrelated to the stated objectives. Verify whether the bundlewatch.config.json size increase is intentional or a build artifact change that should be addressed separately.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed The PR addresses all three coding requirements from USER-4251: moves authenticated check inside useEffect to preserve hook order, changes Boolean(user) to explicit null checks or hardcoded true, and updates isSignedIn handling to use explicit null checks instead of truthiness.
Docstring Coverage ✅ Passed Docstring coverage is 92.31% which is sufficient. The required threshold is 80.00%.
Title check ✅ Passed The title 'feat(shared): Remove SWR' accurately summarizes the primary objective of the pull request, which is to remove SWR dependencies and implementations from the shared package.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In @packages/shared/src/react/billing/useInitializePaymentMethod.tsx:
- Around line 22-74: Call useClearQueriesOnSignOut to purge the cached
initializePaymentMethod result on sign-out: import useClearQueriesOnSignOut and
invoke it in useInitializePaymentMethod (after you compute queryKey / query)
with isSignedOut: user === null, authenticated: the authenticated value from
useUserContext (or equivalent boolean available from user context), and
stableKeys: queryKey (or the stableKey used by other billing hooks). This
ensures the sensitive externalClientSecret in initializedPaymentMethod is
removed from the query cache on sign-out.

In @packages/shared/src/react/hooks/usePagesOrInfinite.tsx:
- Around line 201-208: The non-infinite pagination logic multiplies offsetCount
twice, producing wrong results when initialPageRef.current > 1; update the
hasNextPage and hasPreviousPage conditions to stop multiplying offsetCount by
pageSizeRef.current again: when not triggerInfinite, set hasNextPage to count -
offsetCount > page * pageSizeRef.current, and set hasPreviousPage to (page - 1)
* pageSizeRef.current > offsetCount; keep triggerInfinite branches using
infiniteQuery as-is and reference the symbols offsetCount, pageSizeRef.current,
initialPageRef.current, triggerInfinite, infiniteQuery, hasNextPage, and
hasPreviousPage when making the change.
📜 Review details

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 32151b0 and ec21010.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (58)
  • .changeset/polite-cars-lose.md
  • .changeset/remove-swr-switches.md
  • packages/clerk-js/package.json
  • packages/clerk-js/src/test/create-fixtures.tsx
  • packages/shared/global.d.ts
  • packages/shared/package.json
  • packages/shared/src/react/billing/useInitializePaymentMethod.rq.tsx
  • packages/shared/src/react/billing/useInitializePaymentMethod.swr.tsx
  • packages/shared/src/react/billing/useInitializePaymentMethod.tsx
  • packages/shared/src/react/billing/useStripeClerkLibs.rq.tsx
  • packages/shared/src/react/billing/useStripeClerkLibs.swr.tsx
  • packages/shared/src/react/billing/useStripeClerkLibs.tsx
  • packages/shared/src/react/billing/useStripeLoader.rq.tsx
  • packages/shared/src/react/billing/useStripeLoader.swr.tsx
  • packages/shared/src/react/billing/useStripeLoader.tsx
  • packages/shared/src/react/clerk-swr.ts
  • packages/shared/src/react/contexts.tsx
  • packages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsx
  • packages/shared/src/react/hooks/__tests__/useAPIKeys.spec.tsx
  • packages/shared/src/react/hooks/__tests__/useClearQueriesOnSignOut.spec.ts
  • packages/shared/src/react/hooks/__tests__/usePagesOrInfinite.spec.ts
  • packages/shared/src/react/hooks/__tests__/usePlans.spec.tsx
  • packages/shared/src/react/hooks/__tests__/useSubscription.spec.tsx
  • packages/shared/src/react/hooks/__tests__/wrapper.tsx
  • packages/shared/src/react/hooks/createBillingPaginatedHook.tsx
  • packages/shared/src/react/hooks/index.ts
  • packages/shared/src/react/hooks/useAPIKeys.swr.tsx
  • packages/shared/src/react/hooks/useAPIKeys.ts
  • packages/shared/src/react/hooks/useAPIKeys.tsx
  • packages/shared/src/react/hooks/useClearQueriesOnSignOut.ts
  • packages/shared/src/react/hooks/useOrganization.tsx
  • packages/shared/src/react/hooks/useOrganizationList.tsx
  • packages/shared/src/react/hooks/usePagesOrInfinite.rq.tsx
  • packages/shared/src/react/hooks/usePagesOrInfinite.swr.tsx
  • packages/shared/src/react/hooks/usePagesOrInfinite.tsx
  • packages/shared/src/react/hooks/usePaymentAttemptQuery.rq.tsx
  • packages/shared/src/react/hooks/usePaymentAttemptQuery.swr.tsx
  • packages/shared/src/react/hooks/usePaymentAttemptQuery.tsx
  • packages/shared/src/react/hooks/usePlanDetailsQuery.rq.tsx
  • packages/shared/src/react/hooks/usePlanDetailsQuery.swr.tsx
  • packages/shared/src/react/hooks/usePlanDetailsQuery.tsx
  • packages/shared/src/react/hooks/useStatementQuery.rq.tsx
  • packages/shared/src/react/hooks/useStatementQuery.swr.tsx
  • packages/shared/src/react/hooks/useStatementQuery.tsx
  • packages/shared/src/react/hooks/useSubscription.rq.tsx
  • packages/shared/src/react/hooks/useSubscription.swr.tsx
  • packages/shared/src/react/hooks/useSubscription.tsx
  • packages/shared/src/react/providers/SWRConfigCompat.rq.tsx
  • packages/shared/src/react/providers/SWRConfigCompat.swr.tsx
  • packages/shared/src/react/providers/SWRConfigCompat.tsx
  • packages/shared/src/types/virtual-data-hooks.d.ts
  • packages/shared/tsconfig.json
  • packages/shared/tsdown.config.mts
  • packages/shared/vitest.config.mts
  • packages/shared/vitest.setup.mts
  • packages/ui/bundlewatch.config.json
  • packages/ui/package.json
  • packages/ui/src/contexts/CoreClerkContextWrapper.tsx
💤 Files with no reviewable changes (27)
  • packages/shared/src/react/providers/SWRConfigCompat.tsx
  • packages/shared/src/react/providers/SWRConfigCompat.swr.tsx
  • packages/shared/src/react/hooks/usePaymentAttemptQuery.swr.tsx
  • packages/shared/src/types/virtual-data-hooks.d.ts
  • packages/shared/src/react/hooks/useAPIKeys.ts
  • packages/shared/global.d.ts
  • packages/shared/src/react/hooks/usePaymentAttemptQuery.rq.tsx
  • packages/shared/src/react/hooks/useStatementQuery.swr.tsx
  • packages/shared/src/react/billing/useStripeLoader.swr.tsx
  • packages/shared/src/react/billing/useStripeLoader.rq.tsx
  • packages/shared/src/react/hooks/useSubscription.rq.tsx
  • packages/shared/vitest.setup.mts
  • packages/shared/src/react/providers/SWRConfigCompat.rq.tsx
  • packages/shared/src/react/hooks/usePlanDetailsQuery.rq.tsx
  • packages/shared/src/react/billing/useInitializePaymentMethod.swr.tsx
  • packages/shared/src/react/hooks/usePagesOrInfinite.swr.tsx
  • packages/shared/src/react/hooks/usePagesOrInfinite.rq.tsx
  • packages/shared/src/react/billing/useInitializePaymentMethod.rq.tsx
  • packages/shared/src/react/hooks/useSubscription.swr.tsx
  • packages/shared/vitest.config.mts
  • packages/shared/src/react/hooks/usePlanDetailsQuery.swr.tsx
  • packages/shared/src/react/clerk-swr.ts
  • packages/shared/src/react/hooks/useStatementQuery.rq.tsx
  • packages/shared/src/react/hooks/useAPIKeys.swr.tsx
  • packages/shared/tsdown.config.mts
  • packages/shared/src/react/billing/useStripeClerkLibs.swr.tsx
  • packages/shared/src/react/billing/useStripeClerkLibs.rq.tsx
🧰 Additional context used
📓 Path-based instructions (19)
**/*.{js,jsx,ts,tsx}

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

All code must pass ESLint checks with the project's configuration

Files:

  • packages/shared/src/react/hooks/useClearQueriesOnSignOut.ts
  • packages/shared/src/react/hooks/__tests__/useAPIKeys.spec.tsx
  • packages/shared/src/react/hooks/useOrganizationList.tsx
  • packages/shared/src/react/hooks/__tests__/usePagesOrInfinite.spec.ts
  • packages/shared/src/react/hooks/__tests__/useClearQueriesOnSignOut.spec.ts
  • packages/shared/src/react/hooks/useStatementQuery.tsx
  • packages/shared/src/react/billing/useInitializePaymentMethod.tsx
  • packages/shared/src/react/hooks/__tests__/usePlans.spec.tsx
  • packages/shared/src/react/hooks/index.ts
  • packages/clerk-js/src/test/create-fixtures.tsx
  • packages/shared/src/react/hooks/useAPIKeys.tsx
  • packages/shared/src/react/hooks/useOrganization.tsx
  • packages/shared/src/react/hooks/createBillingPaginatedHook.tsx
  • packages/shared/src/react/hooks/useSubscription.tsx
  • packages/shared/src/react/hooks/__tests__/wrapper.tsx
  • packages/shared/src/react/contexts.tsx
  • packages/shared/src/react/billing/useStripeLoader.tsx
  • packages/shared/src/react/hooks/__tests__/useSubscription.spec.tsx
  • packages/shared/src/react/billing/useStripeClerkLibs.tsx
  • packages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsx
  • packages/shared/src/react/hooks/usePaymentAttemptQuery.tsx
  • packages/shared/src/react/hooks/usePagesOrInfinite.tsx
  • packages/ui/src/contexts/CoreClerkContextWrapper.tsx
  • packages/shared/src/react/hooks/usePlanDetailsQuery.tsx
**/*.{js,jsx,ts,tsx,json,md,yml,yaml}

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

Use Prettier for consistent code formatting

Files:

  • packages/shared/src/react/hooks/useClearQueriesOnSignOut.ts
  • packages/shared/src/react/hooks/__tests__/useAPIKeys.spec.tsx
  • packages/shared/src/react/hooks/useOrganizationList.tsx
  • packages/shared/package.json
  • packages/ui/package.json
  • packages/ui/bundlewatch.config.json
  • packages/shared/src/react/hooks/__tests__/usePagesOrInfinite.spec.ts
  • packages/shared/src/react/hooks/__tests__/useClearQueriesOnSignOut.spec.ts
  • packages/shared/tsconfig.json
  • packages/shared/src/react/hooks/useStatementQuery.tsx
  • packages/shared/src/react/billing/useInitializePaymentMethod.tsx
  • packages/shared/src/react/hooks/__tests__/usePlans.spec.tsx
  • packages/shared/src/react/hooks/index.ts
  • packages/clerk-js/src/test/create-fixtures.tsx
  • packages/shared/src/react/hooks/useAPIKeys.tsx
  • packages/shared/src/react/hooks/useOrganization.tsx
  • packages/shared/src/react/hooks/createBillingPaginatedHook.tsx
  • packages/clerk-js/package.json
  • packages/shared/src/react/hooks/useSubscription.tsx
  • packages/shared/src/react/hooks/__tests__/wrapper.tsx
  • packages/shared/src/react/contexts.tsx
  • packages/shared/src/react/billing/useStripeLoader.tsx
  • packages/shared/src/react/hooks/__tests__/useSubscription.spec.tsx
  • packages/shared/src/react/billing/useStripeClerkLibs.tsx
  • packages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsx
  • packages/shared/src/react/hooks/usePaymentAttemptQuery.tsx
  • packages/shared/src/react/hooks/usePagesOrInfinite.tsx
  • packages/ui/src/contexts/CoreClerkContextWrapper.tsx
  • packages/shared/src/react/hooks/usePlanDetailsQuery.tsx
packages/**/src/**/*.{ts,tsx}

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

TypeScript is required for all packages

Files:

  • packages/shared/src/react/hooks/useClearQueriesOnSignOut.ts
  • packages/shared/src/react/hooks/__tests__/useAPIKeys.spec.tsx
  • packages/shared/src/react/hooks/useOrganizationList.tsx
  • packages/shared/src/react/hooks/__tests__/usePagesOrInfinite.spec.ts
  • packages/shared/src/react/hooks/__tests__/useClearQueriesOnSignOut.spec.ts
  • packages/shared/src/react/hooks/useStatementQuery.tsx
  • packages/shared/src/react/billing/useInitializePaymentMethod.tsx
  • packages/shared/src/react/hooks/__tests__/usePlans.spec.tsx
  • packages/shared/src/react/hooks/index.ts
  • packages/clerk-js/src/test/create-fixtures.tsx
  • packages/shared/src/react/hooks/useAPIKeys.tsx
  • packages/shared/src/react/hooks/useOrganization.tsx
  • packages/shared/src/react/hooks/createBillingPaginatedHook.tsx
  • packages/shared/src/react/hooks/useSubscription.tsx
  • packages/shared/src/react/hooks/__tests__/wrapper.tsx
  • packages/shared/src/react/contexts.tsx
  • packages/shared/src/react/billing/useStripeLoader.tsx
  • packages/shared/src/react/hooks/__tests__/useSubscription.spec.tsx
  • packages/shared/src/react/billing/useStripeClerkLibs.tsx
  • packages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsx
  • packages/shared/src/react/hooks/usePaymentAttemptQuery.tsx
  • packages/shared/src/react/hooks/usePagesOrInfinite.tsx
  • packages/ui/src/contexts/CoreClerkContextWrapper.tsx
  • packages/shared/src/react/hooks/usePlanDetailsQuery.tsx
**/*.{ts,tsx,js,jsx}

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

Follow established naming conventions (PascalCase for components, camelCase for variables)

Files:

  • packages/shared/src/react/hooks/useClearQueriesOnSignOut.ts
  • packages/shared/src/react/hooks/__tests__/useAPIKeys.spec.tsx
  • packages/shared/src/react/hooks/useOrganizationList.tsx
  • packages/shared/src/react/hooks/__tests__/usePagesOrInfinite.spec.ts
  • packages/shared/src/react/hooks/__tests__/useClearQueriesOnSignOut.spec.ts
  • packages/shared/src/react/hooks/useStatementQuery.tsx
  • packages/shared/src/react/billing/useInitializePaymentMethod.tsx
  • packages/shared/src/react/hooks/__tests__/usePlans.spec.tsx
  • packages/shared/src/react/hooks/index.ts
  • packages/clerk-js/src/test/create-fixtures.tsx
  • packages/shared/src/react/hooks/useAPIKeys.tsx
  • packages/shared/src/react/hooks/useOrganization.tsx
  • packages/shared/src/react/hooks/createBillingPaginatedHook.tsx
  • packages/shared/src/react/hooks/useSubscription.tsx
  • packages/shared/src/react/hooks/__tests__/wrapper.tsx
  • packages/shared/src/react/contexts.tsx
  • packages/shared/src/react/billing/useStripeLoader.tsx
  • packages/shared/src/react/hooks/__tests__/useSubscription.spec.tsx
  • packages/shared/src/react/billing/useStripeClerkLibs.tsx
  • packages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsx
  • packages/shared/src/react/hooks/usePaymentAttemptQuery.tsx
  • packages/shared/src/react/hooks/usePagesOrInfinite.tsx
  • packages/ui/src/contexts/CoreClerkContextWrapper.tsx
  • packages/shared/src/react/hooks/usePlanDetailsQuery.tsx
packages/**/src/**/*.{ts,tsx,js,jsx}

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

packages/**/src/**/*.{ts,tsx,js,jsx}: Maintain comprehensive JSDoc comments for public APIs
Use tree-shaking friendly exports
Validate all inputs and sanitize outputs
All public APIs must be documented with JSDoc
Use dynamic imports for optional features
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
Implement proper logging with different levels

Files:

  • packages/shared/src/react/hooks/useClearQueriesOnSignOut.ts
  • packages/shared/src/react/hooks/__tests__/useAPIKeys.spec.tsx
  • packages/shared/src/react/hooks/useOrganizationList.tsx
  • packages/shared/src/react/hooks/__tests__/usePagesOrInfinite.spec.ts
  • packages/shared/src/react/hooks/__tests__/useClearQueriesOnSignOut.spec.ts
  • packages/shared/src/react/hooks/useStatementQuery.tsx
  • packages/shared/src/react/billing/useInitializePaymentMethod.tsx
  • packages/shared/src/react/hooks/__tests__/usePlans.spec.tsx
  • packages/shared/src/react/hooks/index.ts
  • packages/clerk-js/src/test/create-fixtures.tsx
  • packages/shared/src/react/hooks/useAPIKeys.tsx
  • packages/shared/src/react/hooks/useOrganization.tsx
  • packages/shared/src/react/hooks/createBillingPaginatedHook.tsx
  • packages/shared/src/react/hooks/useSubscription.tsx
  • packages/shared/src/react/hooks/__tests__/wrapper.tsx
  • packages/shared/src/react/contexts.tsx
  • packages/shared/src/react/billing/useStripeLoader.tsx
  • packages/shared/src/react/hooks/__tests__/useSubscription.spec.tsx
  • packages/shared/src/react/billing/useStripeClerkLibs.tsx
  • packages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsx
  • packages/shared/src/react/hooks/usePaymentAttemptQuery.tsx
  • packages/shared/src/react/hooks/usePagesOrInfinite.tsx
  • packages/ui/src/contexts/CoreClerkContextWrapper.tsx
  • packages/shared/src/react/hooks/usePlanDetailsQuery.tsx
**/*.ts?(x)

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

Use proper TypeScript error types

Files:

  • packages/shared/src/react/hooks/useClearQueriesOnSignOut.ts
  • packages/shared/src/react/hooks/__tests__/useAPIKeys.spec.tsx
  • packages/shared/src/react/hooks/useOrganizationList.tsx
  • packages/shared/src/react/hooks/__tests__/usePagesOrInfinite.spec.ts
  • packages/shared/src/react/hooks/__tests__/useClearQueriesOnSignOut.spec.ts
  • packages/shared/src/react/hooks/useStatementQuery.tsx
  • packages/shared/src/react/billing/useInitializePaymentMethod.tsx
  • packages/shared/src/react/hooks/__tests__/usePlans.spec.tsx
  • packages/shared/src/react/hooks/index.ts
  • packages/clerk-js/src/test/create-fixtures.tsx
  • packages/shared/src/react/hooks/useAPIKeys.tsx
  • packages/shared/src/react/hooks/useOrganization.tsx
  • packages/shared/src/react/hooks/createBillingPaginatedHook.tsx
  • packages/shared/src/react/hooks/useSubscription.tsx
  • packages/shared/src/react/hooks/__tests__/wrapper.tsx
  • packages/shared/src/react/contexts.tsx
  • packages/shared/src/react/billing/useStripeLoader.tsx
  • packages/shared/src/react/hooks/__tests__/useSubscription.spec.tsx
  • packages/shared/src/react/billing/useStripeClerkLibs.tsx
  • packages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsx
  • packages/shared/src/react/hooks/usePaymentAttemptQuery.tsx
  • packages/shared/src/react/hooks/usePagesOrInfinite.tsx
  • packages/ui/src/contexts/CoreClerkContextWrapper.tsx
  • packages/shared/src/react/hooks/usePlanDetailsQuery.tsx
**/*.{ts,tsx}

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

**/*.{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
Implement type guards for unknown types using the pattern function isType(value: unknown): value is Type
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 in classes
Use protected for inheritance hierarchies
Use public explicitly for clarity in public APIs
Use mixins for shared behavior across unrelated classes in TypeScript
Use generic constraints with bounded type parameters like <T extends { id: string }>
Use utility types like Omit, Partial, and Pick for data transformation instead of manual type construction
Use discriminated unions instead of boolean flags for state management and API responses
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation at the type level
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Document functions with JSDoc comments including @param, @returns, @throws, and @example tags
Create custom error classes that extend Error for specific error types
Use the Result pattern for error handling instead of throwing exceptions
Use optional chaining (?.) and nullish coalescing (??) operators for safe property access
Let TypeScript infer obvious types to reduce verbosity
Use const assertions with as const for literal types
Use satisfies operator for type checking without widening types
Declare readonly arrays and objects for immutable data structures
Use spread operator and array spread for immutable updates instead of mutations
Use lazy loading for large types...

Files:

  • packages/shared/src/react/hooks/useClearQueriesOnSignOut.ts
  • packages/shared/src/react/hooks/__tests__/useAPIKeys.spec.tsx
  • packages/shared/src/react/hooks/useOrganizationList.tsx
  • packages/shared/src/react/hooks/__tests__/usePagesOrInfinite.spec.ts
  • packages/shared/src/react/hooks/__tests__/useClearQueriesOnSignOut.spec.ts
  • packages/shared/src/react/hooks/useStatementQuery.tsx
  • packages/shared/src/react/billing/useInitializePaymentMethod.tsx
  • packages/shared/src/react/hooks/__tests__/usePlans.spec.tsx
  • packages/shared/src/react/hooks/index.ts
  • packages/clerk-js/src/test/create-fixtures.tsx
  • packages/shared/src/react/hooks/useAPIKeys.tsx
  • packages/shared/src/react/hooks/useOrganization.tsx
  • packages/shared/src/react/hooks/createBillingPaginatedHook.tsx
  • packages/shared/src/react/hooks/useSubscription.tsx
  • packages/shared/src/react/hooks/__tests__/wrapper.tsx
  • packages/shared/src/react/contexts.tsx
  • packages/shared/src/react/billing/useStripeLoader.tsx
  • packages/shared/src/react/hooks/__tests__/useSubscription.spec.tsx
  • packages/shared/src/react/billing/useStripeClerkLibs.tsx
  • packages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsx
  • packages/shared/src/react/hooks/usePaymentAttemptQuery.tsx
  • packages/shared/src/react/hooks/usePagesOrInfinite.tsx
  • packages/ui/src/contexts/CoreClerkContextWrapper.tsx
  • packages/shared/src/react/hooks/usePlanDetailsQuery.tsx
**/*.{js,ts,jsx,tsx}

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

Use ESLint with custom configurations tailored for different package types

Files:

  • packages/shared/src/react/hooks/useClearQueriesOnSignOut.ts
  • packages/shared/src/react/hooks/__tests__/useAPIKeys.spec.tsx
  • packages/shared/src/react/hooks/useOrganizationList.tsx
  • packages/shared/src/react/hooks/__tests__/usePagesOrInfinite.spec.ts
  • packages/shared/src/react/hooks/__tests__/useClearQueriesOnSignOut.spec.ts
  • packages/shared/src/react/hooks/useStatementQuery.tsx
  • packages/shared/src/react/billing/useInitializePaymentMethod.tsx
  • packages/shared/src/react/hooks/__tests__/usePlans.spec.tsx
  • packages/shared/src/react/hooks/index.ts
  • packages/clerk-js/src/test/create-fixtures.tsx
  • packages/shared/src/react/hooks/useAPIKeys.tsx
  • packages/shared/src/react/hooks/useOrganization.tsx
  • packages/shared/src/react/hooks/createBillingPaginatedHook.tsx
  • packages/shared/src/react/hooks/useSubscription.tsx
  • packages/shared/src/react/hooks/__tests__/wrapper.tsx
  • packages/shared/src/react/contexts.tsx
  • packages/shared/src/react/billing/useStripeLoader.tsx
  • packages/shared/src/react/hooks/__tests__/useSubscription.spec.tsx
  • packages/shared/src/react/billing/useStripeClerkLibs.tsx
  • packages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsx
  • packages/shared/src/react/hooks/usePaymentAttemptQuery.tsx
  • packages/shared/src/react/hooks/usePagesOrInfinite.tsx
  • packages/ui/src/contexts/CoreClerkContextWrapper.tsx
  • packages/shared/src/react/hooks/usePlanDetailsQuery.tsx
**/*.{js,ts,jsx,tsx,json,md,yml,yaml}

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

Use Prettier for code formatting across all packages

Files:

  • packages/shared/src/react/hooks/useClearQueriesOnSignOut.ts
  • packages/shared/src/react/hooks/__tests__/useAPIKeys.spec.tsx
  • packages/shared/src/react/hooks/useOrganizationList.tsx
  • packages/shared/package.json
  • packages/ui/package.json
  • packages/ui/bundlewatch.config.json
  • packages/shared/src/react/hooks/__tests__/usePagesOrInfinite.spec.ts
  • packages/shared/src/react/hooks/__tests__/useClearQueriesOnSignOut.spec.ts
  • packages/shared/tsconfig.json
  • packages/shared/src/react/hooks/useStatementQuery.tsx
  • packages/shared/src/react/billing/useInitializePaymentMethod.tsx
  • packages/shared/src/react/hooks/__tests__/usePlans.spec.tsx
  • packages/shared/src/react/hooks/index.ts
  • packages/clerk-js/src/test/create-fixtures.tsx
  • packages/shared/src/react/hooks/useAPIKeys.tsx
  • packages/shared/src/react/hooks/useOrganization.tsx
  • packages/shared/src/react/hooks/createBillingPaginatedHook.tsx
  • packages/clerk-js/package.json
  • packages/shared/src/react/hooks/useSubscription.tsx
  • packages/shared/src/react/hooks/__tests__/wrapper.tsx
  • packages/shared/src/react/contexts.tsx
  • packages/shared/src/react/billing/useStripeLoader.tsx
  • packages/shared/src/react/hooks/__tests__/useSubscription.spec.tsx
  • packages/shared/src/react/billing/useStripeClerkLibs.tsx
  • packages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsx
  • packages/shared/src/react/hooks/usePaymentAttemptQuery.tsx
  • packages/shared/src/react/hooks/usePagesOrInfinite.tsx
  • packages/ui/src/contexts/CoreClerkContextWrapper.tsx
  • packages/shared/src/react/hooks/usePlanDetailsQuery.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.

**/*: Only comment on issues that would block merging, ignore minor or stylistic concerns.
Restrict feedback to errors, security risks, or functionality-breaking problems.
Do not post comments on code style, formatting, or non-critical improvements.
Keep reviews short: flag only issues that make the PR unsafe to merge.
Group similar issues into a single comment instead of posting multiple notes.
Skip repetition: if a pattern repeats, mention it once at a summary level only.
Do not add general suggestions, focus strictly on merge-blocking concerns.
If there are no critical problems, respond with minimal approval (e.g., 'Looks good'). Do not add additional review.
Avoid line-by-line commentary unless it highlights a critical bug or security hole.
Highlight only issues that could cause runtime errors, data loss, or severe maintainability issues.
Ignore minor optimization opportunities, focus solely on correctness and safety.
Provide a top-level summary of critical blockers rather than detailed per-line notes.
Comment only when the issue must be resolved before merge, otherwise remain silent.
When in doubt, err on the side of fewer comments, brevity and blocking issues only.
Avoid posting any refactoring issues.

Files:

  • packages/shared/src/react/hooks/useClearQueriesOnSignOut.ts
  • packages/shared/src/react/hooks/__tests__/useAPIKeys.spec.tsx
  • packages/shared/src/react/hooks/useOrganizationList.tsx
  • packages/shared/package.json
  • packages/ui/package.json
  • packages/ui/bundlewatch.config.json
  • packages/shared/src/react/hooks/__tests__/usePagesOrInfinite.spec.ts
  • packages/shared/src/react/hooks/__tests__/useClearQueriesOnSignOut.spec.ts
  • packages/shared/tsconfig.json
  • packages/shared/src/react/hooks/useStatementQuery.tsx
  • packages/shared/src/react/billing/useInitializePaymentMethod.tsx
  • packages/shared/src/react/hooks/__tests__/usePlans.spec.tsx
  • packages/shared/src/react/hooks/index.ts
  • packages/clerk-js/src/test/create-fixtures.tsx
  • packages/shared/src/react/hooks/useAPIKeys.tsx
  • packages/shared/src/react/hooks/useOrganization.tsx
  • packages/shared/src/react/hooks/createBillingPaginatedHook.tsx
  • packages/clerk-js/package.json
  • packages/shared/src/react/hooks/useSubscription.tsx
  • packages/shared/src/react/hooks/__tests__/wrapper.tsx
  • packages/shared/src/react/contexts.tsx
  • packages/shared/src/react/billing/useStripeLoader.tsx
  • packages/shared/src/react/hooks/__tests__/useSubscription.spec.tsx
  • packages/shared/src/react/billing/useStripeClerkLibs.tsx
  • packages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsx
  • packages/shared/src/react/hooks/usePaymentAttemptQuery.tsx
  • packages/shared/src/react/hooks/usePagesOrInfinite.tsx
  • packages/ui/src/contexts/CoreClerkContextWrapper.tsx
  • packages/shared/src/react/hooks/usePlanDetailsQuery.tsx
**/*.{test,spec}.{ts,tsx,js,jsx}

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

**/*.{test,spec}.{ts,tsx,js,jsx}: Unit tests are required for all new functionality
Verify proper error handling and edge cases
Include tests for all new features

Files:

  • packages/shared/src/react/hooks/__tests__/useAPIKeys.spec.tsx
  • packages/shared/src/react/hooks/__tests__/usePagesOrInfinite.spec.ts
  • packages/shared/src/react/hooks/__tests__/useClearQueriesOnSignOut.spec.ts
  • packages/shared/src/react/hooks/__tests__/usePlans.spec.tsx
  • packages/shared/src/react/hooks/__tests__/useSubscription.spec.tsx
  • packages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsx
**/*.tsx

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

**/*.tsx: Use error boundaries in React components
Minimize re-renders in React components

**/*.tsx: Use proper type definitions for props and state in React components
Leverage TypeScript's type inference where possible in React components
Use proper event types for handlers in React components
Implement proper generic types for reusable React components
Use proper type guards for conditional rendering in React components

Files:

  • packages/shared/src/react/hooks/__tests__/useAPIKeys.spec.tsx
  • packages/shared/src/react/hooks/useOrganizationList.tsx
  • packages/shared/src/react/hooks/useStatementQuery.tsx
  • packages/shared/src/react/billing/useInitializePaymentMethod.tsx
  • packages/shared/src/react/hooks/__tests__/usePlans.spec.tsx
  • packages/clerk-js/src/test/create-fixtures.tsx
  • packages/shared/src/react/hooks/useAPIKeys.tsx
  • packages/shared/src/react/hooks/useOrganization.tsx
  • packages/shared/src/react/hooks/createBillingPaginatedHook.tsx
  • packages/shared/src/react/hooks/useSubscription.tsx
  • packages/shared/src/react/hooks/__tests__/wrapper.tsx
  • packages/shared/src/react/contexts.tsx
  • packages/shared/src/react/billing/useStripeLoader.tsx
  • packages/shared/src/react/hooks/__tests__/useSubscription.spec.tsx
  • packages/shared/src/react/billing/useStripeClerkLibs.tsx
  • packages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsx
  • packages/shared/src/react/hooks/usePaymentAttemptQuery.tsx
  • packages/shared/src/react/hooks/usePagesOrInfinite.tsx
  • packages/ui/src/contexts/CoreClerkContextWrapper.tsx
  • packages/shared/src/react/hooks/usePlanDetailsQuery.tsx
**/*.{test,spec,e2e}.{ts,tsx,js,jsx}

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

Use real Clerk instances for integration tests

Files:

  • packages/shared/src/react/hooks/__tests__/useAPIKeys.spec.tsx
  • packages/shared/src/react/hooks/__tests__/usePagesOrInfinite.spec.ts
  • packages/shared/src/react/hooks/__tests__/useClearQueriesOnSignOut.spec.ts
  • packages/shared/src/react/hooks/__tests__/usePlans.spec.tsx
  • packages/shared/src/react/hooks/__tests__/useSubscription.spec.tsx
  • packages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsx
**/*.{md,tsx}

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

Update documentation for API changes

Files:

  • packages/shared/src/react/hooks/__tests__/useAPIKeys.spec.tsx
  • packages/shared/src/react/hooks/useOrganizationList.tsx
  • packages/shared/src/react/hooks/useStatementQuery.tsx
  • packages/shared/src/react/billing/useInitializePaymentMethod.tsx
  • packages/shared/src/react/hooks/__tests__/usePlans.spec.tsx
  • packages/clerk-js/src/test/create-fixtures.tsx
  • packages/shared/src/react/hooks/useAPIKeys.tsx
  • packages/shared/src/react/hooks/useOrganization.tsx
  • packages/shared/src/react/hooks/createBillingPaginatedHook.tsx
  • packages/shared/src/react/hooks/useSubscription.tsx
  • packages/shared/src/react/hooks/__tests__/wrapper.tsx
  • packages/shared/src/react/contexts.tsx
  • packages/shared/src/react/billing/useStripeLoader.tsx
  • packages/shared/src/react/hooks/__tests__/useSubscription.spec.tsx
  • packages/shared/src/react/billing/useStripeClerkLibs.tsx
  • packages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsx
  • packages/shared/src/react/hooks/usePaymentAttemptQuery.tsx
  • packages/shared/src/react/hooks/usePagesOrInfinite.tsx
  • packages/ui/src/contexts/CoreClerkContextWrapper.tsx
  • packages/shared/src/react/hooks/usePlanDetailsQuery.tsx
**/*.{jsx,tsx}

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

**/*.{jsx,tsx}: Always use functional components with hooks instead of class components
Follow PascalCase naming for components (e.g., 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
Separate UI components from business logic components
Use useState for simple state management in React components
Use useReducer for complex state logic in React components
Implement proper state initialization in React components
Use proper state updates with callbacks in React components
Implement proper state cleanup in React components
Use Context API for theme/authentication state management
Implement proper state persistence in React applications
Use React.memo for expensive components
Implement proper useCallback for handlers in React components
Use proper useMemo for expensive computations in React components
Implement proper virtualization for lists in React components
Use proper code splitting with React.lazy in React applications
Implement proper cleanup in useEffect hooks
Use proper refs for DOM access in React components
Implement proper event listener cleanup in React components
Use proper abort controllers for fetch in React components
Implement proper subscription cleanup in React components
Use proper HTML elements for semantic HTML in React components
Implement proper ARIA attributes for accessibility in React components
Use proper heading hierarchy in React components
Implement proper form labels in React components
Use proper button types in React components
Implement proper focus management for keyboard navigation in React components
Use proper keyboard shortcuts in React components
Implement proper tab order in React components
Use proper ...

Files:

  • packages/shared/src/react/hooks/__tests__/useAPIKeys.spec.tsx
  • packages/shared/src/react/hooks/useOrganizationList.tsx
  • packages/shared/src/react/hooks/useStatementQuery.tsx
  • packages/shared/src/react/billing/useInitializePaymentMethod.tsx
  • packages/shared/src/react/hooks/__tests__/usePlans.spec.tsx
  • packages/clerk-js/src/test/create-fixtures.tsx
  • packages/shared/src/react/hooks/useAPIKeys.tsx
  • packages/shared/src/react/hooks/useOrganization.tsx
  • packages/shared/src/react/hooks/createBillingPaginatedHook.tsx
  • packages/shared/src/react/hooks/useSubscription.tsx
  • packages/shared/src/react/hooks/__tests__/wrapper.tsx
  • packages/shared/src/react/contexts.tsx
  • packages/shared/src/react/billing/useStripeLoader.tsx
  • packages/shared/src/react/hooks/__tests__/useSubscription.spec.tsx
  • packages/shared/src/react/billing/useStripeClerkLibs.tsx
  • packages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsx
  • packages/shared/src/react/hooks/usePaymentAttemptQuery.tsx
  • packages/shared/src/react/hooks/usePagesOrInfinite.tsx
  • packages/ui/src/contexts/CoreClerkContextWrapper.tsx
  • packages/shared/src/react/hooks/usePlanDetailsQuery.tsx
**/*.{test,spec}.{jsx,tsx}

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

**/*.{test,spec}.{jsx,tsx}: Use React Testing Library for unit testing React components
Test component behavior, not implementation details
Use proper test queries in React Testing Library tests
Implement proper test isolation in React component tests
Use proper test coverage in React component tests
Test component interactions in integration tests
Use proper test data in React component tests
Implement proper test setup in React component tests
Use proper test cleanup in React component tests
Implement proper test assertions in React component tests
Use proper test structure for React component tests

Files:

  • packages/shared/src/react/hooks/__tests__/useAPIKeys.spec.tsx
  • packages/shared/src/react/hooks/__tests__/usePlans.spec.tsx
  • packages/shared/src/react/hooks/__tests__/useSubscription.spec.tsx
  • packages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsx
packages/*/package.json

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

packages/*/package.json: Packages should export TypeScript types alongside runtime code
Follow semantic versioning for all packages

All packages must be published under @clerk namespace

packages/*/package.json: Framework packages should depend on @clerk/clerk-js for core functionality
@clerk/shared should be a common dependency for most packages in the monorepo

Files:

  • packages/shared/package.json
  • packages/ui/package.json
  • packages/clerk-js/package.json
**/package.json

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

Use pnpm as the package manager for this monorepo

Files:

  • packages/shared/package.json
  • packages/ui/package.json
  • packages/clerk-js/package.json
**/index.ts

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

Avoid barrel files (index.ts re-exports) as they can cause circular dependencies

Files:

  • packages/shared/src/react/hooks/index.ts
🧬 Code graph analysis (14)
packages/shared/src/react/hooks/useClearQueriesOnSignOut.ts (1)
packages/clerk-js/src/core/auth/AuthCookieService.ts (1)
  • isSignedOut (98-103)
packages/shared/src/react/hooks/useOrganizationList.tsx (2)
packages/react/src/isomorphicClerk.ts (1)
  • user (730-736)
packages/shared/src/react/hooks/createCacheKeys.ts (1)
  • createCacheKeys (7-23)
packages/shared/src/react/hooks/__tests__/useClearQueriesOnSignOut.spec.ts (1)
packages/shared/src/react/hooks/useClearQueriesOnSignOut.ts (2)
  • withInfiniteKey (6-6)
  • useClearQueriesOnSignOut (28-61)
packages/shared/src/react/billing/useInitializePaymentMethod.tsx (8)
packages/shared/src/types/billing.ts (2)
  • ForPayerType (89-89)
  • BillingInitializedPaymentMethodResource (369-382)
packages/shared/src/react/contexts.tsx (2)
  • useOrganizationContext (119-119)
  • useUserContext (122-122)
packages/shared/src/react/index.ts (2)
  • useOrganizationContext (15-15)
  • useUserContext (18-18)
packages/shared/src/react/hooks/useBillingHookEnabled.ts (1)
  • useBillingHookEnabled (7-27)
packages/shared/src/react/clerk-rq/useQuery.ts (1)
  • useClerkQuery (39-41)
packages/shared/src/react/clerk-rq/keep-previous-data.ts (1)
  • defineKeepPreviousDataFn (4-11)
packages/shared/src/react/clerk-rq/use-clerk-query-client.ts (1)
  • useClerkQueryClient (84-84)
packages/clerk-js/src/core/modules/billing/payment-source-methods.ts (1)
  • initializePaymentMethod (20-30)
packages/shared/src/react/hooks/__tests__/usePlans.spec.tsx (1)
packages/clerk-js/src/test/utils.ts (1)
  • waitFor (73-73)
packages/clerk-js/src/test/create-fixtures.tsx (2)
packages/ui/src/contexts/CoreClerkContextWrapper.tsx (1)
  • CoreClerkContextWrapper (21-67)
packages/clerk-js/src/test/core-fixtures.ts (1)
  • clerkMock (249-256)
packages/shared/src/react/hooks/useAPIKeys.tsx (2)
packages/shared/src/react/hooks/createCacheKeys.ts (1)
  • createCacheKeys (7-23)
packages/shared/src/react/stable-keys.ts (1)
  • STABLE_KEYS (30-51)
packages/shared/src/react/hooks/useOrganization.tsx (3)
packages/react/src/isomorphicClerk.ts (1)
  • organization (738-744)
packages/shared/src/react/hooks/createCacheKeys.ts (1)
  • createCacheKeys (7-23)
packages/shared/src/react/stable-keys.ts (1)
  • STABLE_KEYS (30-51)
packages/shared/src/react/hooks/createBillingPaginatedHook.tsx (1)
packages/react/src/isomorphicClerk.ts (1)
  • organization (738-744)
packages/shared/src/react/contexts.tsx (1)
packages/shared/src/react/index.ts (1)
  • OrganizationProvider (9-9)
packages/shared/src/react/billing/useStripeLoader.tsx (4)
packages/shared/src/react/billing/useStripeClerkLibs.tsx (1)
  • UseStripeClerkLibsResult (14-14)
packages/shared/src/react/hooks/useBillingHookEnabled.ts (1)
  • useBillingHookEnabled (7-27)
packages/shared/src/react/clerk-rq/useQuery.ts (1)
  • useClerkQuery (39-41)
packages/shared/src/react/clerk-rq/keep-previous-data.ts (1)
  • defineKeepPreviousDataFn (4-11)
packages/shared/src/react/billing/useStripeClerkLibs.tsx (4)
packages/shared/src/react/hooks/index.ts (1)
  • useClerk (10-10)
packages/shared/src/react/hooks/useBillingHookEnabled.ts (1)
  • useBillingHookEnabled (7-27)
packages/shared/src/react/clerk-rq/useQuery.ts (1)
  • useClerkQuery (39-41)
packages/shared/src/react/clerk-rq/keep-previous-data.ts (1)
  • defineKeepPreviousDataFn (4-11)
packages/ui/src/contexts/CoreClerkContextWrapper.tsx (1)
packages/shared/src/react/contexts.tsx (1)
  • OrganizationProvider (112-112)
packages/shared/src/react/hooks/usePlanDetailsQuery.tsx (7)
packages/shared/src/react/hooks/usePlanDetailsQuery.types.ts (2)
  • UsePlanDetailsQueryParams (7-28)
  • PlanDetailsQueryResult (33-50)
packages/shared/src/react/contexts.tsx (1)
  • useClerkInstanceContext (116-116)
packages/shared/src/react/index.ts (1)
  • useClerkInstanceContext (12-12)
packages/shared/src/react/hooks/usePlanDetailsQuery.shared.ts (1)
  • usePlanDetailsQueryCacheKeys (6-22)
packages/shared/src/react/hooks/useBillingHookEnabled.ts (1)
  • useBillingHookEnabled (7-27)
packages/shared/src/react/clerk-rq/useQuery.ts (1)
  • useClerkQuery (39-41)
packages/shared/src/react/clerk-rq/keep-previous-data.ts (1)
  • defineKeepPreviousDataFn (4-11)
⏰ 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). (28)
  • GitHub Check: Unit Tests (shared, clerk-js, RQ)
  • GitHub Check: Publish with pkg-pr-new
  • GitHub Check: Unit Tests (**)
  • GitHub Check: Integration Tests (billing, chrome, RQ)
  • GitHub Check: Integration Tests (tanstack-react-start, chrome)
  • GitHub Check: Integration Tests (quickstart, chrome, 15)
  • GitHub Check: Integration Tests (sessions:staging, chrome)
  • GitHub Check: Integration Tests (quickstart, chrome, 16)
  • GitHub Check: Integration Tests (astro, chrome)
  • GitHub Check: Integration Tests (nextjs, chrome, 15)
  • GitHub Check: Integration Tests (nextjs, chrome, 16, RQ)
  • GitHub Check: Integration Tests (handshake, chrome)
  • GitHub Check: Integration Tests (react-router, chrome)
  • GitHub Check: Integration Tests (handshake:staging, chrome)
  • GitHub Check: Integration Tests (nextjs, chrome, 16)
  • GitHub Check: Integration Tests (machine, chrome)
  • GitHub Check: Integration Tests (nuxt, chrome)
  • GitHub Check: Integration Tests (custom, chrome)
  • GitHub Check: Integration Tests (machine, chrome, RQ)
  • GitHub Check: Integration Tests (vue, chrome)
  • GitHub Check: Integration Tests (sessions, chrome)
  • GitHub Check: Integration Tests (billing, chrome)
  • GitHub Check: Integration Tests (generic, chrome)
  • GitHub Check: Integration Tests (express, chrome)
  • GitHub Check: Integration Tests (localhost, chrome)
  • GitHub Check: Integration Tests (ap-flows, chrome)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (14)
.changeset/polite-cars-lose.md (1)

1-5: Changeset entry is well-formed and accurately documents the fix.

The changeset correctly declares a patch bump for @clerk/shared with a clear, concise description that accurately reflects the useClearQueriesOnSignOut hook fix referenced in the PR objectives.

packages/shared/tsconfig.json (1)

26-30: Configuration cleanup looks correct.

The removal of virtual path aliases and virtual-data-hooks.d.ts from the include array aligns with the PR's objective to remove SWR and the virtual data-hooks system. The TypeScript compiler will catch any remaining references to removed modules during build.

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

3-3: The wrapper change is safe. All context provisioning in tests is handled via module-level mocks (vi.mock('../../contexts', ...)), not by the wrapper component itself. The wrapper serves only as a container for renderHook and the change from SWRConfigCompat to a simple fragment does not affect test behavior or functionality.

packages/shared/src/react/hooks/useAPIKeys.tsx (1)

105-111: LGTM!

The explicit null check for isSignedIn and hardcoded authenticated: true correctly implement the PR objectives to fix hook order issues while maintaining proper authentication gating.

packages/shared/src/react/hooks/index.ts (1)

24-24: LGTM!

Documentation correctly updated to reflect React Query as the sole implementation.

.changeset/remove-swr-switches.md (1)

1-5: LGTM!

Changeset correctly documents the major breaking change.

packages/shared/src/react/hooks/__tests__/usePagesOrInfinite.spec.ts (1)

725-725: LGTM!

Test correctly updated to remove environment-based branching, now expecting consistent React Query behavior.

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

92-92: LGTM!

Tests correctly updated to remove environment-based conditionals, expecting consistent React Query revalidation behavior across all scenarios.

packages/shared/src/react/hooks/useStatementQuery.tsx (1)

1-59: LGTM!

The hook implementation correctly:

  • Guards query execution with queryEnabled check before calling clerk.billing.getStatement
  • Clears queries on sign-out via useClearQueriesOnSignOut
  • Returns a stable result shape matching StatementQueryResult
  • Follows the same patterns as other billing hooks in this PR
packages/shared/src/react/contexts.tsx (1)

71-81: LGTM!

The OrganizationProvider simplification correctly removes the SWR wrapper dependency, aligning with the PR's objective to consolidate on React Query.

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

23-81: LGTM!

The implementation correctly:

  • Records telemetry on first render only (via recordedRef)
  • Clears queries on sign-out
  • Normalizes error to undefined for backward compatibility with SWR-based API
  • Provides revalidate function via query client invalidation
packages/shared/src/react/hooks/__tests__/useSubscription.spec.tsx (1)

94-133: LGTM!

The test updates correctly remove environment-flag conditional branches. The unified expectations for sign-out behavior (data becomes undefined even with keepPreviousData=true) align with the fix for USER-4251, ensuring stale data is properly cleared on sign-out.

packages/shared/src/react/hooks/usePlanDetailsQuery.tsx (1)

11-44: LGTM!

The implementation correctly:

  • Sets authenticated: false for useBillingHookEnabled since plan details are public data
  • Uses initialDataUpdatedAt: 0 to treat initial data as immediately stale
  • Omits useClearQueriesOnSignOut appropriately since this hook doesn't require authentication
packages/shared/src/react/hooks/usePagesOrInfinite.tsx (1)

13-112: Core hook structure looks good.

The implementation correctly:

  • Handles both paginated and infinite query modes
  • Uses useClearQueriesOnSignOut with proper cleanup callback to reset pagination state
  • Manages force re-renders for cache-only updates via forceUpdateCounter

Comment on lines +22 to +74
function useInitializePaymentMethod(options?: InitializePaymentMethodOptions): UseInitializePaymentMethodResult {
const { for: forType } = options ?? {};
const { organization } = useOrganizationContext();
const user = useUserContext();

const resource = forType === 'organization' ? organization : user;

const billingEnabled = useBillingHookEnabled(options);

const queryKey = useMemo(() => {
return ['billing-payment-method-initialize', { resourceId: resource?.id }] as const;
}, [resource?.id]);

const isEnabled = Boolean(resource?.id) && billingEnabled;

const query = useClerkQuery({
queryKey,
queryFn: async () => {
if (!resource) {
return undefined;
}

return resource.initializePaymentMethod({
gateway: 'stripe',
});
},
enabled: isEnabled,
staleTime: 1_000 * 60,
refetchOnWindowFocus: false,
placeholderData: defineKeepPreviousDataFn(true),
});

const [queryClient] = useClerkQueryClient();

const initializePaymentMethod = useCallback(async () => {
if (!resource) {
return undefined;
}

const result = await resource.initializePaymentMethod({
gateway: 'stripe',
});

queryClient.setQueryData(queryKey, result);

return result;
}, [queryClient, queryKey, resource]);

return {
initializedPaymentMethod: query.data ?? undefined,
initializePaymentMethod,
};
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Search for useClearQueriesOnSignOut usage in billing hooks
rg -n "useClearQueriesOnSignOut" packages/shared/src/react/billing/ packages/shared/src/react/hooks/

Repository: clerk/javascript

Length of output: 2757


🏁 Script executed:

#!/bin/bash
# Check usePaymentAttemptQuery to understand why it uses useClearQueriesOnSignOut
cat -n packages/shared/src/react/hooks/usePaymentAttemptQuery.tsx

Repository: clerk/javascript

Length of output: 2472


🏁 Script executed:

#!/bin/bash
# Also check the full useInitializePaymentMethod implementation with imports
cd packages/shared/src/react/billing
cat -n useInitializePaymentMethod.tsx | head -80

Repository: clerk/javascript

Length of output: 2884


🏁 Script executed:

#!/bin/bash
# Check what BillingInitializedPaymentMethodResource contains
rg -A 10 "BillingInitializedPaymentMethodResource" packages/shared/src/types/ | head -30

Repository: clerk/javascript

Length of output: 2248


🏁 Script executed:

#!/bin/bash
# Check if there's any other sign-out handling or cache invalidation logic in useInitializePaymentMethod context
rg -n "sign.*out|Sign.*Out" packages/shared/src/react/billing/ packages/shared/src/react/hooks/useBillingHookEnabled.tsx

Repository: clerk/javascript

Length of output: 157


🏁 Script executed:

#!/bin/bash
# Search for useBillingHookEnabled to understand if it has special sign-out logic
find packages/shared/src -name "*useBillingHookEnabled*"

Repository: clerk/javascript

Length of output: 116


🏁 Script executed:

#!/bin/bash
# Check other billing hooks to see the pattern of useClearQueriesOnSignOut
grep -l "useClearQueriesOnSignOut" packages/shared/src/react/hooks/*.tsx

Repository: clerk/javascript

Length of output: 279


🏁 Script executed:

#!/bin/bash
# Check useBillingHookEnabled
cat -n packages/shared/src/react/hooks/useBillingHookEnabled.ts

Repository: clerk/javascript

Length of output: 1394


🏁 Script executed:

#!/bin/bash
# Check useSubscription to see the full pattern
cat -n packages/shared/src/react/hooks/useSubscription.tsx

Repository: clerk/javascript

Length of output: 3261


Add useClearQueriesOnSignOut to clear cached payment method data on sign-out.

The hook caches the payment method initialization result containing externalClientSecret (a sensitive Stripe client secret) but doesn't clear this cache when the user signs out. This is inconsistent with other billing hooks (usePaymentAttemptQuery, useSubscription) which explicitly call useClearQueriesOnSignOut({isSignedOut: user === null, authenticated, stableKeys: stableKey}) to clear sensitive cached data. Add this call to prevent the client secret from persisting in the query cache after sign-out.

🤖 Prompt for AI Agents
In @packages/shared/src/react/billing/useInitializePaymentMethod.tsx around
lines 22 - 74, Call useClearQueriesOnSignOut to purge the cached
initializePaymentMethod result on sign-out: import useClearQueriesOnSignOut and
invoke it in useInitializePaymentMethod (after you compute queryKey / query)
with isSignedOut: user === null, authenticated: the authenticated value from
useUserContext (or equivalent boolean available from user context), and
stableKeys: queryKey (or the stableKey used by other billing hooks). This
ensures the sensitive externalClientSecret in initializedPaymentMethod is
removed from the query cache on sign-out.

…on bug

- Extract pagination calculations into pure utility functions for better testability:
  - calculateOffsetCount: calculates items to skip based on initial page
  - calculatePageCount: calculates total pages accounting for offset
  - calculateHasNextPage: determines if more pages exist
  - calculateHasPreviousPage: determines if previous pages exist
- Fix hasNextPage/hasPreviousPage double multiplication bug where offsetCount
  was incorrectly multiplied by pageSizeRef.current again
- Add comprehensive unit tests for pagination utilities (21 test cases)
@jacekradko
Copy link
Member Author

!snapshot

@clerk-cookie
Copy link
Collaborator

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

Package Version
@clerk/agent-toolkit 0.2.9-snapshot.v20260109165810
@clerk/astro 3.0.0-snapshot.v20260109165810
@clerk/backend 3.0.0-snapshot.v20260109165810
@clerk/chrome-extension 3.0.0-snapshot.v20260109165810
@clerk/clerk-js 6.0.0-snapshot.v20260109165810
@clerk/dev-cli 1.0.0-snapshot.v20260109165810
@clerk/expo 3.0.0-snapshot.v20260109165810
@clerk/expo-passkeys 1.0.0-snapshot.v20260109165810
@clerk/express 2.0.0-snapshot.v20260109165810
@clerk/fastify 2.6.9-snapshot.v20260109165810
@clerk/localizations 4.0.0-snapshot.v20260109165810
@clerk/msw 0.0.1-snapshot.v20260109165810
@clerk/nextjs 7.0.0-snapshot.v20260109165810
@clerk/nuxt 2.0.0-snapshot.v20260109165810
@clerk/react 6.0.0-snapshot.v20260109165810
@clerk/react-router 3.0.0-snapshot.v20260109165810
@clerk/shared 4.0.0-snapshot.v20260109165810
@clerk/tanstack-react-start 1.0.0-snapshot.v20260109165810
@clerk/testing 2.0.0-snapshot.v20260109165810
@clerk/ui 1.0.0-snapshot.v20260109165810
@clerk/upgrade 2.0.0-snapshot.v20260109165810
@clerk/vue 2.0.0-snapshot.v20260109165810

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/dev-cli

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

@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/msw

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/react

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

@clerk/react-router

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/ui

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

@clerk/upgrade

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

@clerk/vue

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

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.

3 participants