Skip to content

Conversation

@LauraBeatris
Copy link
Member

@LauraBeatris LauraBeatris commented Nov 19, 2025

Description

There's a PR, introducing a guard within the organization public hooks, to trigger a in-app UI prompt to enable organizations.

This flow doesn't work well when triggered within billing components or the useCheckout hook, when used with for=organizations, since the order of operations and the current UX when enabling billing from the Dashboard.

  1. Enable billing
  2. Enable organizations (or the other way around)
  3. Dashboard flow would change to create plans for organizations

For now, we'll keep the prompt specific to organization components, and later think about an in-app flow to enable billing if necessary.

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

  • Refactor
    • Replaced internal organization hook usage with an organization context across billing, payments, pricing, statements, and subscription UIs — no visible behavior changes.
  • Chores
    • Added a changeset entry for a patch release; no user-facing impact.

@LauraBeatris LauraBeatris self-assigned this Nov 19, 2025
@changeset-bot
Copy link

changeset-bot bot commented Nov 19, 2025

🦋 Changeset detected

Latest commit: 83e7f51

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

This PR includes changesets to release 3 packages
Name Type
@clerk/clerk-js Patch
@clerk/chrome-extension Patch
@clerk/clerk-expo 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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 19, 2025

Walkthrough

Replaces useOrganization() with useOrganizationContext() across billing-related Clerk.js components, updating accesses from organization?.id to organizationCtx?.organization?.id. Adds a changeset entry for an internal patch release. No user-facing API changes.

Changes

Cohort / File(s) Change Summary
Billing Components
packages/clerk-js/src/ui/components/PaymentAttempts/PaymentAttemptPage.tsx, packages/clerk-js/src/ui/components/PaymentMethods/PaymentMethods.tsx, packages/clerk-js/src/ui/components/PricingTable/PricingTableDefault.tsx, packages/clerk-js/src/ui/components/Statements/StatementPage.tsx, packages/clerk-js/src/ui/components/SubscriptionDetails/index.tsx
Replaced useOrganization import with useOrganizationContext, introduced organizationCtx local variable, and updated property access from organization?.id to organizationCtx?.organization?.id (SWR keys, clerk.billing.* calls, effect deps, payloads). Added developer comments explaining avoidance of triggering in-app organizations prompt in development.
Plans Context
packages/clerk-js/src/ui/contexts/components/Plans.tsx
Replaced useOrganization import with useOrganizationContext, used organizationCtx?.organization in enabled-check logic and billing hook params.
Changeset
.changeset/cuddly-cougars-buy.md
Added changeset documenting an internal patch: swapping useOrganizationuseOrganizationContext in billing components; no user-facing impact.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–30 minutes

  • Verify consistent import replacements and local variable renames (useOrganizationuseOrganizationContext, organizationorganizationCtx).
  • Confirm all null-safe accesses use organizationCtx?.organization?.id.
  • Check SWR keys, clerk.billing.* callsites, effect dependency arrays, callback payloads, and added comments for correctness.

Poem

🐰 I hopped through hooks both old and new,

Swapped a name and kept the billing true.
organization nested in context snug,
A tiny patch — a happy little hug. ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: replacing useOrganization with useOrganizationContext in billing components, which aligns with all modified files.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch laura/update-billing-org-usage

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

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 d8b067c and 83e7f51.

📒 Files selected for processing (7)
  • .changeset/cuddly-cougars-buy.md (1 hunks)
  • packages/clerk-js/src/ui/components/PaymentAttempts/PaymentAttemptPage.tsx (3 hunks)
  • packages/clerk-js/src/ui/components/PaymentMethods/PaymentMethods.tsx (4 hunks)
  • packages/clerk-js/src/ui/components/PricingTable/PricingTableDefault.tsx (3 hunks)
  • packages/clerk-js/src/ui/components/Statements/StatementPage.tsx (3 hunks)
  • packages/clerk-js/src/ui/components/SubscriptionDetails/index.tsx (4 hunks)
  • packages/clerk-js/src/ui/contexts/components/Plans.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/clerk-js/src/ui/contexts/components/Plans.tsx
  • packages/clerk-js/src/ui/components/PricingTable/PricingTableDefault.tsx
  • .changeset/cuddly-cougars-buy.md
🧰 Additional context used
🧬 Code graph analysis (1)
packages/clerk-js/src/ui/components/PaymentAttempts/PaymentAttemptPage.tsx (1)
packages/shared/src/react/contexts.tsx (1)
  • useOrganizationContext (131-131)
⏰ 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). (1)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (4)
packages/clerk-js/src/ui/components/Statements/StatementPage.tsx (1)

1-1: LGTM! Clean refactor to useOrganizationContext.

The migration from useOrganization to useOrganizationContext is implemented correctly. The pattern is consistent between the SWR key (line 41) and the actual API call (line 47), both properly using organizationCtx?.organization?.id with safe optional chaining. The explanatory comment clearly documents the rationale for avoiding the development prompt.

Also applies to: 29-30, 41-41, 47-47

packages/clerk-js/src/ui/components/PaymentMethods/PaymentMethods.tsx (1)

1-1: LGTM! Consistent refactor across multiple components.

The migration is correctly applied to both RemoveScreen and PaymentMethodMenu components. The pattern is consistent:

  • Both include explanatory comments (addressing past review discussion)
  • Both use organizationCtx?.organization?.id with safe optional chaining
  • Both properly check subscriberType === 'organization' before using the organization ID

The changes maintain the existing behavior while avoiding the development prompt as intended.

Also applies to: 67-68, 76-76, 202-203, 220-220

packages/clerk-js/src/ui/components/PaymentAttempts/PaymentAttemptPage.tsx (1)

1-1: LGTM! Correctly implemented refactor.

The changes follow the same consistent pattern as other billing components:

  • Import updated to useOrganizationContext
  • Both the SWR key (line 47) and API call (line 53) use organizationCtx?.organization?.id
  • Safe optional chaining handles potential undefined values
  • Explanatory comment documents the rationale

Also applies to: 35-36, 47-47, 53-53

packages/clerk-js/src/ui/components/SubscriptionDetails/index.tsx (1)

1-1: LGTM! Refactor correctly includes dependency array update.

The migration is properly implemented with attention to React hooks best practices:

  • Import updated to useOrganizationContext
  • The cancel() call (line 199) uses organizationCtx?.organization?.id
  • Importantly, the useCallback dependency array (line 217) is correctly updated to reference organizationCtx?.organization?.id, ensuring proper memoization
  • Explanatory comment documents the rationale

Also applies to: 185-186, 199-199, 217-217


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

@vercel
Copy link

vercel bot commented Nov 19, 2025

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

Project Deployment Preview Comments Updated (UTC)
clerk-js-sandbox Ready Ready Preview Comment Nov 19, 2025 5:51pm

@LauraBeatris LauraBeatris marked this pull request as ready for review November 19, 2025 16:23
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: 0

🧹 Nitpick comments (1)
.changeset/cuddly-cougars-buy.md (1)

5-5: Minor grammar fix: use hyphen in compound adjective.

The phrase "not user facing" should be hyphenated as "not user-facing" when used as a compound adjective.

Apply this diff:

-Internal change, not user facing: Replace `useOrganization` within billing components with `useOrganizationContext`
+Internal change, not user-facing: Replace `useOrganization` within billing components with `useOrganizationContext`
📜 Review details

Configuration used: Path: .coderabbit.yaml

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 edbd18c and ef34eed.

📒 Files selected for processing (7)
  • .changeset/cuddly-cougars-buy.md (1 hunks)
  • packages/clerk-js/src/ui/components/PaymentAttempts/PaymentAttemptPage.tsx (3 hunks)
  • packages/clerk-js/src/ui/components/PaymentMethods/PaymentMethods.tsx (5 hunks)
  • packages/clerk-js/src/ui/components/PricingTable/PricingTableDefault.tsx (3 hunks)
  • packages/clerk-js/src/ui/components/Statements/StatementPage.tsx (3 hunks)
  • packages/clerk-js/src/ui/components/SubscriptionDetails/index.tsx (4 hunks)
  • packages/clerk-js/src/ui/contexts/components/Plans.tsx (3 hunks)
🧰 Additional context used
🪛 LanguageTool
.changeset/cuddly-cougars-buy.md

[grammar] ~5-~5: Use a hyphen to join words.
Context: ...s': patch --- Internal change, not user facing: Replace useOrganization within...

(QB_NEW_EN_HYPHEN)

🔇 Additional comments (6)
packages/clerk-js/src/ui/components/SubscriptionDetails/index.tsx (1)

1-1: LGTM! Clean refactoring from useOrganization to useOrganizationContext.

The refactoring is correct and consistent:

  • Import updated to useOrganizationContext
  • Variable renamed to organizationCtx
  • Access path updated to organizationCtx?.organization?.id
  • Dependency array correctly references the primitive ID value

The optional chaining ensures null-safety is maintained throughout.

Also applies to: 176-176, 198-198, 216-216

packages/clerk-js/src/ui/components/PricingTable/PricingTableDefault.tsx (1)

1-1: LGTM! Consistent refactoring pattern.

The changes follow the same pattern as other components:

  • Hook updated to useOrganizationContext
  • Variable renamed to organizationCtx
  • Boolean check updated to !!organizationCtx?.organization

The refactoring maintains the same null-safety guarantees.

Also applies to: 107-107, 140-140

packages/clerk-js/src/ui/components/PaymentMethods/PaymentMethods.tsx (1)

1-1: LGTM! Both RemoveScreen and PaymentMethodMenu updated correctly.

The refactoring is applied consistently across both nested components:

  • RemoveScreen uses organizationCtx?.organization?.id in the remove flow (line 75)
  • PaymentMethodMenu uses organizationCtx?.organization?.id in the makeDefault flow (line 218)

Both maintain proper null-safety with optional chaining.

Also applies to: 63-63, 75-75, 199-199, 218-218

packages/clerk-js/src/ui/components/Statements/StatementPage.tsx (1)

1-1: LGTM! SWR key and API call updated consistently.

The refactoring correctly updates both:

  • The SWR cache key (line 40) to include organizationCtx?.organization?.id
  • The API call parameter (line 46) to pass organizationCtx?.organization?.id

This ensures SWR caching behavior remains correct with the new context structure.

Also applies to: 26-26, 40-40, 46-46

packages/clerk-js/src/ui/components/PaymentAttempts/PaymentAttemptPage.tsx (1)

1-1: LGTM! Consistent refactoring with SWR integration.

Following the same pattern as StatementPage, both the SWR cache key (line 46) and the API call (line 52) are updated to use organizationCtx?.organization?.id. This maintains correct caching behavior.

Also applies to: 32-32, 46-46, 52-52

packages/clerk-js/src/ui/contexts/components/Plans.tsx (1)

8-8: LGTM! Hook enablement logic correctly updated.

The refactoring updates the billing hook enablement condition to check Boolean(organizationCtx?.organization) instead of checking the organization directly. This maintains the same logical behavior while using the new context structure.

Also applies to: 35-35, 47-47

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

📜 Review details

Configuration used: Path: .coderabbit.yaml

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 ef34eed and eccdbdf.

📒 Files selected for processing (1)
  • .changeset/cuddly-cougars-buy.md (1 hunks)
🧰 Additional context used
🪛 LanguageTool
.changeset/cuddly-cougars-buy.md

[grammar] ~5-~5: Use a hyphen to join words.
Context: ...s': patch --- Internal change, not user facing: Replace useOrganization with `...

(QB_NEW_EN_HYPHEN)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Formatting | Dedupe | Changeset
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (1)
.changeset/cuddly-cougars-buy.md (1)

1-5: Changeset structure and versioning look good.

The YAML format is correct, package identifier matches the target, and the patch version bump is appropriate for this internal refactoring. The description accurately captures the scope of the hook replacement across billing components.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 19, 2025

Open in StackBlitz

@clerk/agent-toolkit

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

@clerk/astro

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

@clerk/backend

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

@clerk/chrome-extension

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

@clerk/clerk-js

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

@clerk/dev-cli

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

@clerk/elements

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

@clerk/clerk-expo

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

@clerk/expo-passkeys

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

@clerk/express

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

@clerk/fastify

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

@clerk/localizations

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

@clerk/nextjs

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

@clerk/nuxt

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

@clerk/clerk-react

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

@clerk/react-router

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

@clerk/remix

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

@clerk/shared

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

@clerk/tanstack-react-start

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

@clerk/testing

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

@clerk/themes

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

@clerk/types

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

@clerk/upgrade

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

@clerk/vue

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

commit: d8b067c

const { params, navigate } = useRouter();
const subscriberType = useSubscriberTypeContext();
const { organization } = useOrganization();
const organizationCtx = useOrganizationContext();
Copy link
Contributor

Choose a reason for hiding this comment

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

❔ is appending Ctx to a variable context a pattern?

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct, it's unsafe to apply destructuring ({ organization }) to the return value, as the context might be undefined, so it's better to access with the nullish operator organizationCtx?.organization

Copy link
Contributor

Choose a reason for hiding this comment

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

TIL

const card = useCardState();
const subscriberType = useSubscriberTypeContext();
const { organization } = useOrganization();
const organizationCtx = useOrganizationContext();
Copy link
Contributor

Choose a reason for hiding this comment

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

❔ Is it worth adding a comment explaining why we are using useOrganizationContext?

Copy link
Member Author

Choose a reason for hiding this comment

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

If I was writing billing components, would be nice to see it as a reference. I recognize that commenting on every reference of it can be repetitive but seems worth it.

Copy link
Contributor

Choose a reason for hiding this comment

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

hmm, you are right. Feel free to ignore my comment

@LauraBeatris LauraBeatris force-pushed the laura/update-billing-org-usage branch from d8b067c to 83e7f51 Compare November 19, 2025 17:50
@LauraBeatris LauraBeatris merged commit 5e5e24a into main Nov 19, 2025
105 of 108 checks passed
@LauraBeatris LauraBeatris deleted the laura/update-billing-org-usage branch November 19, 2025 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants