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

    • Migrated SWR usage to React Query and promoted TanStack Query to a runtime dependency.
  • Bug Fixes

    • Fixed query-clearing on sign-out by adjusting effect timing and guards.
  • Chores

    • Removed SWR compatibility shims and environment-based switches; simplified build/test configuration and internal plumbing.
  • New Features

    • Added pagination utility helpers.
  • Tests

    • Added and expanded tests for pagination, billing/payment initialization, and sign-out behaviors.

✏️ 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: 4b8d27a

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 13, 2026 1:02am

@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: 4b8d27a

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 8, 2026

📝 Walkthrough

Walkthrough

Removes SWR-based implementations and virtual data-hook shims across packages/shared and related packages, deletes the compile-time flag __CLERK_USE_RQ__, promotes @tanstack/query-core to a runtime dependency, and removes swr from shared and ui packages. Replaces many SWR re-exports with concrete React Query implementations for hooks (billing, pagination, statements, subscriptions, payment attempts, Stripe loader), removes SWR compatibility wrappers/virtual modules, updates providers and test helpers to drop SWR wiring, simplifies tests by removing environment-conditional assertions, and moves the authentication guard inside the useEffect of useClearQueriesOnSignOut.

Possibly related PRs

  • PR 7455 — Implements the same SWR removal and React Query consolidation, deleting .swr files and eliminating the __CLERK_USE_RQ__ switch.
  • PR 7565 — Targets the SWR → React Query switch as well; described as reverting or reintroducing SWR-based behavior and environment-based switching.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title "feat(shared): Remove SWR" clearly and specifically describes the main change: removal of SWR from the shared package.
Linked Issues check ✅ Passed The PR addresses all three objectives from USER-4251: moves authenticated check inside useEffect (useClearQueriesOnSignOut.ts), uses explicit null checks instead of Boolean(user) for authenticated values, and changes isSignedIn from Boolean to explicit null checks (user !== null).
Out of Scope Changes check ✅ Passed All changes are in scope: SWR removal (swr.tsx/rq.tsx pairs deleted, .tsx implementations updated), @tanstack/query-core promoted to runtime dependency, CLERK_USE_RQ global removed, virtual module system eliminated, and CI simplified. No unrelated modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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


📜 Recent 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 040e666 and ab287e3.

📒 Files selected for processing (1)
  • .github/workflows/ci.yml
⏰ 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). (25)
  • GitHub Check: Static analysis
  • GitHub Check: Unit Tests (**)
  • GitHub Check: Publish with pkg-pr-new
  • GitHub Check: Integration Tests (billing, chrome)
  • GitHub Check: Integration Tests (quickstart, chrome, 16)
  • GitHub Check: Integration Tests (machine, chrome)
  • GitHub Check: Integration Tests (sessions, chrome)
  • GitHub Check: Integration Tests (nuxt, chrome)
  • GitHub Check: Integration Tests (quickstart, chrome, 15)
  • GitHub Check: Integration Tests (handshake:staging, chrome)
  • GitHub Check: Integration Tests (nextjs, chrome, 16)
  • GitHub Check: Integration Tests (sessions:staging, chrome)
  • GitHub Check: Integration Tests (ap-flows, chrome)
  • GitHub Check: Integration Tests (express, chrome)
  • GitHub Check: Integration Tests (tanstack-react-start, chrome)
  • GitHub Check: Integration Tests (custom, chrome)
  • GitHub Check: Integration Tests (nextjs, chrome, 15)
  • GitHub Check: Integration Tests (astro, chrome)
  • GitHub Check: Integration Tests (react-router, chrome)
  • GitHub Check: Integration Tests (vue, chrome)
  • GitHub Check: Integration Tests (handshake, chrome)
  • GitHub Check: Integration Tests (generic, chrome)
  • GitHub Check: Integration Tests (localhost, chrome)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (6)
.github/workflows/ci.yml (6)

204-204: LGTM - Job name simplified.

The removal of the conditional ", RQ" suffix aligns with consolidating to React Query as the sole implementation.


217-223: Verify the unit test matrix reduction is intentional.

The matrix now contains only a single configuration (Node 22, full test suite). Confirm this is the intended simplification after removing RQ-specific matrix entries, and that other Node version coverage (if previously tested) is no longer required.


271-271: LGTM - Artifact naming simplified.

Removed the RQ-specific suffix from the turbo summary artifact name, consistent with the single implementation path.


279-279: LGTM - Integration test job naming cleaned up.

The job name now only includes test-name, test-project, and optional next-version, removing the RQ-related conditional formatting.


386-388: LGTM - Verdaccio publish command simplified.

The command now unconditionally runs pnpm turbo build $TURBO_ARGS --only without the CLERK_USE_RQ conditional rebuild step. The registry safety check is preserved.


470-470: LGTM - Playwright traces artifact naming simplified.

Removed RQ-specific suffix from the artifact name while preserving the next-version conditional for Next.js version differentiation.


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

…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

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

🤖 Fix all issues with AI agents
In @packages/shared/src/react/hooks/usePagesOrInfinite.tsx:
- Around line 199-205: fetchPrevious can decrement to 0 even though pagination
is 1-based; update the handler in usePagesOrInfinite (fetchPrevious) to clamp to
the configured initialPage (not 0) — e.g. use setPaginatedPage(n =>
Math.max(initialPage, n - 1)) (replace the Math.max(0, ...) call), and include
initialPage in the useCallback dependency array so the clamp honors the
configured default.
🧹 Nitpick comments (1)
packages/shared/src/react/hooks/usePagesOrInfinite.tsx (1)

191-197: Consider using 1 as floor for consistency.

Same issue as fetchPrevious - using Math.max(0, ...) is inconsistent with the 1-based pagination. While less critical here since incrementing won't reach 0, using Math.max(1, ...) would be more consistent.

Proposed fix
 const fetchNext = useCallback(() => {
   if (triggerInfinite) {
     void infiniteQuery.fetchNextPage({ cancelRefetch: false });
     return;
   }
-  setPaginatedPage(n => Math.max(0, n + 1));
+  setPaginatedPage(n => Math.max(1, n + 1));
 }, [infiniteQuery, triggerInfinite]);
📜 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 ec21010 and 1453374.

📒 Files selected for processing (3)
  • packages/shared/src/react/hooks/__tests__/usePagesOrInfinite.shared.spec.ts
  • packages/shared/src/react/hooks/usePagesOrInfinite.shared.ts
  • packages/shared/src/react/hooks/usePagesOrInfinite.tsx
🧰 Additional context used
📓 Path-based instructions (15)
**/*.{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/__tests__/usePagesOrInfinite.shared.spec.ts
  • packages/shared/src/react/hooks/usePagesOrInfinite.tsx
  • packages/shared/src/react/hooks/usePagesOrInfinite.shared.ts
**/*.{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/__tests__/usePagesOrInfinite.shared.spec.ts
  • packages/shared/src/react/hooks/usePagesOrInfinite.tsx
  • packages/shared/src/react/hooks/usePagesOrInfinite.shared.ts
packages/**/src/**/*.{ts,tsx}

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

TypeScript is required for all packages

Files:

  • packages/shared/src/react/hooks/__tests__/usePagesOrInfinite.shared.spec.ts
  • packages/shared/src/react/hooks/usePagesOrInfinite.tsx
  • packages/shared/src/react/hooks/usePagesOrInfinite.shared.ts
**/*.{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/__tests__/usePagesOrInfinite.shared.spec.ts
  • packages/shared/src/react/hooks/usePagesOrInfinite.tsx
  • packages/shared/src/react/hooks/usePagesOrInfinite.shared.ts
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/__tests__/usePagesOrInfinite.shared.spec.ts
  • packages/shared/src/react/hooks/usePagesOrInfinite.tsx
  • packages/shared/src/react/hooks/usePagesOrInfinite.shared.ts
**/*.{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__/usePagesOrInfinite.shared.spec.ts
**/*.ts?(x)

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

Use proper TypeScript error types

Files:

  • packages/shared/src/react/hooks/__tests__/usePagesOrInfinite.shared.spec.ts
  • packages/shared/src/react/hooks/usePagesOrInfinite.tsx
  • packages/shared/src/react/hooks/usePagesOrInfinite.shared.ts
**/*.{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__/usePagesOrInfinite.shared.spec.ts
**/*.{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/__tests__/usePagesOrInfinite.shared.spec.ts
  • packages/shared/src/react/hooks/usePagesOrInfinite.tsx
  • packages/shared/src/react/hooks/usePagesOrInfinite.shared.ts
**/*.{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/__tests__/usePagesOrInfinite.shared.spec.ts
  • packages/shared/src/react/hooks/usePagesOrInfinite.tsx
  • packages/shared/src/react/hooks/usePagesOrInfinite.shared.ts
**/*.{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/__tests__/usePagesOrInfinite.shared.spec.ts
  • packages/shared/src/react/hooks/usePagesOrInfinite.tsx
  • packages/shared/src/react/hooks/usePagesOrInfinite.shared.ts
**/*

⚙️ CodeRabbit configuration file

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

**/*: 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/__tests__/usePagesOrInfinite.shared.spec.ts
  • packages/shared/src/react/hooks/usePagesOrInfinite.tsx
  • packages/shared/src/react/hooks/usePagesOrInfinite.shared.ts
**/*.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/usePagesOrInfinite.tsx
**/*.{md,tsx}

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

Update documentation for API changes

Files:

  • packages/shared/src/react/hooks/usePagesOrInfinite.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/usePagesOrInfinite.tsx
🧬 Code graph analysis (1)
packages/shared/src/react/hooks/__tests__/usePagesOrInfinite.shared.spec.ts (1)
packages/shared/src/react/hooks/usePagesOrInfinite.shared.ts (4)
  • calculateOffsetCount (104-106)
  • calculatePageCount (123-125)
  • calculateHasNextPage (144-151)
  • calculateHasPreviousPage (168-170)
⏰ 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). (27)
  • GitHub Check: Integration Tests (machine, chrome, RQ)
  • GitHub Check: Integration Tests (quickstart, chrome, 16)
  • GitHub Check: Integration Tests (quickstart, chrome, 15)
  • GitHub Check: Integration Tests (nextjs, chrome, 16)
  • GitHub Check: Integration Tests (nextjs, chrome, 16, RQ)
  • GitHub Check: Integration Tests (billing, chrome)
  • GitHub Check: Integration Tests (nextjs, chrome, 15)
  • GitHub Check: Integration Tests (localhost, chrome)
  • GitHub Check: Integration Tests (machine, chrome)
  • GitHub Check: Integration Tests (react-router, chrome)
  • GitHub Check: Integration Tests (billing, chrome, RQ)
  • GitHub Check: Integration Tests (custom, chrome)
  • GitHub Check: Integration Tests (nuxt, chrome)
  • GitHub Check: Integration Tests (tanstack-react-start, chrome)
  • GitHub Check: Integration Tests (astro, chrome)
  • GitHub Check: Integration Tests (vue, chrome)
  • GitHub Check: Integration Tests (handshake:staging, chrome)
  • GitHub Check: Integration Tests (handshake, chrome)
  • GitHub Check: Integration Tests (ap-flows, chrome)
  • GitHub Check: Integration Tests (sessions, chrome)
  • GitHub Check: Integration Tests (generic, chrome)
  • GitHub Check: Integration Tests (sessions:staging, chrome)
  • GitHub Check: Integration Tests (express, chrome)
  • GitHub Check: Build Packages
  • GitHub Check: Formatting | Dedupe | Changeset
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (3)
packages/shared/src/react/hooks/usePagesOrInfinite.shared.ts (1)

88-170: LGTM!

The pagination utility functions are well-documented with comprehensive JSDoc comments and examples. The edge case handling (negative page count when offset exceeds total) is appropriately documented in the test file. The logic is correct for standard 1-based pagination.

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

1-184: LGTM!

Comprehensive test coverage for all pagination utilities including edge cases and an integration test demonstrating real-world usage scenarios.

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

1-261: Implementation looks solid overall.

The hook correctly integrates React Query for both paginated and infinite modes, properly handles cache management, sign-out cleanup, and derives computed values consistently. The pagination helper functions are used correctly for boundary calculations.

Comment on lines +199 to +205
const fetchPrevious = useCallback(() => {
if (triggerInfinite) {
// not natively supported by forward-only pagination; noop
return;
}
setPaginatedPage(n => Math.max(0, n - 1));
}, [triggerInfinite]);
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 | 🟡 Minor

Page 0 possible with 1-based pagination.

fetchPrevious allows navigating to page 0 when on page 1, but pagination is 1-based (initialPage defaults to 1). While hasPreviousPage guards against this in the UI, direct calls to fetchPrevious could put state into an invalid page 0.

Proposed fix
 const fetchPrevious = useCallback(() => {
   if (triggerInfinite) {
     // not natively supported by forward-only pagination; noop
     return;
   }
-  setPaginatedPage(n => Math.max(0, n - 1));
+  setPaginatedPage(n => Math.max(1, n - 1));
 }, [triggerInfinite]);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const fetchPrevious = useCallback(() => {
if (triggerInfinite) {
// not natively supported by forward-only pagination; noop
return;
}
setPaginatedPage(n => Math.max(0, n - 1));
}, [triggerInfinite]);
const fetchPrevious = useCallback(() => {
if (triggerInfinite) {
// not natively supported by forward-only pagination; noop
return;
}
setPaginatedPage(n => Math.max(1, n - 1));
}, [triggerInfinite]);
🤖 Prompt for AI Agents
In @packages/shared/src/react/hooks/usePagesOrInfinite.tsx around lines 199 -
205, fetchPrevious can decrement to 0 even though pagination is 1-based; update
the handler in usePagesOrInfinite (fetchPrevious) to clamp to the configured
initialPage (not 0) — e.g. use setPaginatedPage(n => Math.max(initialPage, n -
1)) (replace the Math.max(0, ...) call), and include initialPage in the
useCallback dependency array so the clamp honors the configured default.

Add useClearQueriesOnSignOut to useInitializePaymentMethod to purge
cached externalClientSecret when user signs out. Update queryKey format
to match standard cache key pattern and fix placeholderData to respect
isEnabled state.
@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.v20260112172748
@clerk/astro 3.0.0-snapshot.v20260112172748
@clerk/backend 3.0.0-snapshot.v20260112172748
@clerk/chrome-extension 3.0.0-snapshot.v20260112172748
@clerk/clerk-js 6.0.0-snapshot.v20260112172748
@clerk/dev-cli 1.0.0-snapshot.v20260112172748
@clerk/expo 3.0.0-snapshot.v20260112172748
@clerk/expo-passkeys 1.0.0-snapshot.v20260112172748
@clerk/express 2.0.0-snapshot.v20260112172748
@clerk/fastify 2.6.9-snapshot.v20260112172748
@clerk/localizations 4.0.0-snapshot.v20260112172748
@clerk/msw 0.0.1-snapshot.v20260112172748
@clerk/nextjs 7.0.0-snapshot.v20260112172748
@clerk/nuxt 2.0.0-snapshot.v20260112172748
@clerk/react 6.0.0-snapshot.v20260112172748
@clerk/react-router 3.0.0-snapshot.v20260112172748
@clerk/shared 4.0.0-snapshot.v20260112172748
@clerk/tanstack-react-start 1.0.0-snapshot.v20260112172748
@clerk/testing 2.0.0-snapshot.v20260112172748
@clerk/ui 1.0.0-snapshot.v20260112172748
@clerk/upgrade 2.0.0-snapshot.v20260112172748
@clerk/vue 2.0.0-snapshot.v20260112172748

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

React Query is now the default, so there's no need for separate
RQ matrix entries in unit tests and integration tests.
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