-
Notifications
You must be signed in to change notification settings - Fork 382
feat(vue): Add Billing buttons #6680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…for-astro-and-vue # Conflicts: # integration/tests/pricing-table.test.ts
🦋 Changeset detectedLatest commit: 7e21cd1 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughAdds experimental billing buttons to Clerk Vue: introduces CheckoutButton, PlanDetailsButton, and SubscriptionDetailsButton components, an experimental export entry, updates build config, extends child-assertion utilities, adds Vue template routes and demo views, adjusts tests to skip Astro, and documents the minor release via a changeset. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor User
participant App as Vue App
participant Btn as Billing Button (Vue)
participant Clerk as Clerk SDK
rect rgba(230,245,255,0.5)
note over App,Btn: Render phase
App->>Btn: Mount with slot child
Btn->>Btn: Assert single child, SignedIn/org checks
end
alt CheckoutButton click
User->>Btn: Click
Btn->>Clerk: __internal_openCheckout(planId, planPeriod, for, callbacks, props)
Clerk-->>User: Opens checkout UI
else PlanDetailsButton click
User->>Btn: Click
Btn->>Clerk: __internal_openPlanDetails(plan/planId, initialPlanPeriod, props)
Clerk-->>User: Shows plan details UI
else SubscriptionDetailsButton click
User->>Btn: Click
Btn->>Clerk: __internal_openSubscriptionDetails(for, onCancel, props)
Clerk-->>User: Shows subscription details UI
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Assessment against linked issues
Poem
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ 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)
✨ Finishing Touches
🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
Status, Documentation and Community
|
@clerk/agent-toolkit
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/dev-cli
@clerk/elements
@clerk/clerk-expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/clerk-react
@clerk/react-router
@clerk/remix
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/themes
@clerk/types
@clerk/upgrade
@clerk/vue
commit: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 7
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/vue/src/utils/childrenUtils.ts (1)
15-28
: Prevent runtime when slotContent is an empty arrayAccessing
slotContent[0].type
can throw if the slot returns[]
. Add an empty-array guard and a safe access.export const normalizeWithDefaultValue = (slotContent: VNode[] | undefined, defaultValue: string) => { // Render a button with the default value if no slot content is provided if (!slotContent) { return h('button', defaultValue); } // Render a button with the slot content if it's a text node - if (slotContent[0].type === Text) { + if (Array.isArray(slotContent) && slotContent.length === 0) { + return h('button', defaultValue); + } + if (slotContent[0] && slotContent[0].type === Text) { return h('button', slotContent); }
🧹 Nitpick comments (16)
.changeset/cold-parks-push.md (1)
1-6
: Clarify experimental import path and list components in the noteHelps consumers discover how to import and what’s included.
Expose billing buttons as experimental + +- New experimental components: CheckoutButton, PlanDetailsButton, SubscriptionDetailsButton. +- Import path: `@clerk/vue/experimental`. +- Note: Experimental APIs are subject to change without semver guarantees.packages/vue/tsup.config.ts (1)
24-27
: Include .vue files in auto-props generationEnsures SFCs (the new buttons) get runtime props inferred from TS.
- autoPropsPlugin({ - include: ['**/*.ts'], - }), + autoPropsPlugin({ + include: ['**/*.ts', '**/*.vue'], + }),integration/tests/pricing-table.test.ts (4)
35-36
: Reduce duplication: hoist Astro gating to a suiteWrap Astro-incompatible tests in a
test.describe
with a singletest.skip(...)
.Example:
test.describe('astro-incompatible', () => { test.skip(app.name.includes('astro'), 'Billing buttons not enabled on Astro yet'); test('renders pricing details of a specific plan', async (...) => { ... }); // other astro-incompatible tests... });
85-86
: Same suggestion: prefer describe-level skip for Astro gating
100-101
: Same suggestion: consolidate Astro gating to avoid drift
135-136
: Same suggestion: group and skip once per blockpackages/vue/src/components/PlanDetailsButton.vue (1)
1-12
: Add minimal JSDoc for the experimental public componentDocuments props and experimental status for consumers.
<script setup lang="ts"> +/** + * PlanDetailsButton (experimental) + * Renders a clickable child that opens the Clerk Plan Details drawer. + * Import from `@clerk/vue/experimental`. + */integration/templates/vue-vite/src/views/billing/PlanDetailsBtn.vue (2)
1-9
: Gate with SignedIn to avoid unauthenticated access errorsPlan and subscription views typically require an authenticated user. Wrap the button with
<SignedIn>
for consistency withCheckoutBtn.vue
.Apply:
<template> <main> - <PlanDetailsButton planId="cplan_2wMjqdlza0hTJc4HLCoBwAiExhF"> Plan details </PlanDetailsButton> + <SignedIn> + <PlanDetailsButton planId="cplan_2wMjqdlza0hTJc4HLCoBwAiExhF">Plan details</PlanDetailsButton> + </SignedIn> </main> </template> <script setup lang="ts"> -import { PlanDetailsButton } from '@clerk/vue/experimental'; +import { SignedIn } from '@clerk/vue'; +import { PlanDetailsButton } from '@clerk/vue/experimental'; </script>
3-3
: Trim incidental whitespace in button labelMinor readability tweak.
- <PlanDetailsButton planId="cplan_2wMjqdlza0hTJc4HLCoBwAiExhF"> Plan details </PlanDetailsButton> + <PlanDetailsButton planId="cplan_2wMjqdlza0hTJc4HLCoBwAiExhF">Plan details</PlanDetailsButton>integration/templates/vue-vite/src/router.ts (1)
50-65
: Protect billing routes with auth metadataThese routes surface user/account-specific actions. Add
meta: { requiresAuth: true }
so the existing guard can enforce sign-in (or update the guard to respectmeta
).{ name: 'CheckoutBtn', path: '/billing/checkout-btn', - component: () => import('./views/billing/CheckoutBtn.vue'), + component: () => import('./views/billing/CheckoutBtn.vue'), + meta: { requiresAuth: true }, }, { name: 'PlanDetailsBtn', path: '/billing/plan-details-btn', - component: () => import('./views/billing/PlanDetailsBtn.vue'), + component: () => import('./views/billing/PlanDetailsBtn.vue'), + meta: { requiresAuth: true }, }, { name: 'SubscriptionDetailsBtn', path: '/billing/subscription-details-btn', - component: () => import('./views/billing/SubscriptionDetailsBtn.vue'), + component: () => import('./views/billing/SubscriptionDetailsBtn.vue'), + meta: { requiresAuth: true }, },To hook the guard (outside this hunk), either:
- Add these route names to
authenticatedPages
, or- Prefer meta-based check:
// replace the second branch } else if (!isSignedIn.value && to.meta?.requiresAuth) { next('/sign-in');integration/templates/vue-vite/src/views/billing/SubscriptionDetailsBtn.vue (1)
1-9
: Add SignedIn wrapper for consistency and safetySubscription details typically require an authenticated session. Match
CheckoutBtn.vue
’s pattern.<template> <main> - <SubscriptionDetailsButton> Subscription details </SubscriptionDetailsButton> + <SignedIn> + <SubscriptionDetailsButton>Subscription details</SubscriptionDetailsButton> + </SignedIn> </main> </template> <script setup lang="ts"> -import { SubscriptionDetailsButton } from '@clerk/vue/experimental'; +import { SignedIn } from '@clerk/vue'; +import { SubscriptionDetailsButton } from '@clerk/vue/experimental'; </script>packages/vue/src/components/CheckoutButton.vue (2)
29-42
: Click handler: type and error resilience.Consider explicit return type and minimal guard around the internal call to aid DX and logging.
-function clickHandler() { +function clickHandler(): void | Promise<unknown> { if (!clerk.value) { return; } - - return clerk.value.__internal_openCheckout({ + try { + return clerk.value.__internal_openCheckout({ planId: props.planId, planPeriod: props.planPeriod, for: props.for, onSubscriptionComplete: props.onSubscriptionComplete, newSubscriptionRedirectUrl: props.newSubscriptionRedirectUrl, ...props.checkoutProps, - }); + }); + } catch (e) { + // Optional: surface a concise, actionable log for developers + console.error('CheckoutButton: failed to open checkout', e); + } }
46-52
: Accessibility default when no child is passed.With the proposed native button fallback, ensure
type="button"
to avoid form submission by default.- <component - :is="getChildComponent()" + <component + :is="getChildComponent()" + type="button"packages/vue/src/components/SubscriptionDetailsButton.vue (2)
29-39
: Type the handler and add minimal error logging.Align with CheckoutButton for consistency and DX.
-function clickHandler() { +function clickHandler(): void | Promise<unknown> { if (!clerk.value) { return; } - - return clerk.value.__internal_openSubscriptionDetails({ - for: props.for, - onSubscriptionCancel: props.onSubscriptionCancel, - ...props.subscriptionDetailsProps, - }); + try { + return clerk.value.__internal_openSubscriptionDetails({ + for: props.for, + onSubscriptionCancel: props.onSubscriptionCancel, + ...props.subscriptionDetailsProps, + }); + } catch (e) { + console.error('SubscriptionDetailsButton: failed to open subscription details', e); + } }
42-50
: Accessibility nit: default button type.Ensure
type="button"
on the fallback to prevent accidental form submits.- <component - :is="getChildComponent()" + <component + :is="getChildComponent()" + type="button"packages/vue/src/experimental.ts (1)
1-21
: Reduce repeated JSDoc noise.You can keep a single top-level experimental notice to cut repetition while preserving clarity.
-/** - * @experimental - * These components and their prop types are unstable and may change in future releases. - * They are part of Clerk's Billing feature which is available under public beta. - */ export { default as SubscriptionDetailsButton } from './components/SubscriptionDetailsButton.vue'; -/** - * @experimental - * These components and their prop types are unstable and may change in future releases. - * They are part of Clerk's Billing feature which is available under public beta. - */ export { default as CheckoutButton } from './components/CheckoutButton.vue'; -/** - * @experimental - * These components and their prop types are unstable and may change in future releases. - * They are part of Clerk's Billing feature which is available under public beta. - */ export { default as PlanDetailsButton } from './components/PlanDetailsButton.vue';
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (13)
.changeset/cold-parks-push.md
(1 hunks)integration/templates/vue-vite/src/router.ts
(1 hunks)integration/templates/vue-vite/src/views/billing/CheckoutBtn.vue
(1 hunks)integration/templates/vue-vite/src/views/billing/PlanDetailsBtn.vue
(1 hunks)integration/templates/vue-vite/src/views/billing/SubscriptionDetailsBtn.vue
(1 hunks)integration/tests/pricing-table.test.ts
(4 hunks)packages/vue/package.json
(1 hunks)packages/vue/src/components/CheckoutButton.vue
(1 hunks)packages/vue/src/components/PlanDetailsButton.vue
(1 hunks)packages/vue/src/components/SubscriptionDetailsButton.vue
(1 hunks)packages/vue/src/experimental.ts
(1 hunks)packages/vue/src/utils/childrenUtils.ts
(1 hunks)packages/vue/tsup.config.ts
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (12)
.changeset/**
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Automated releases must use Changesets.
Files:
.changeset/cold-parks-push.md
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
**/*.{js,jsx,ts,tsx}
: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels
Files:
integration/tests/pricing-table.test.ts
packages/vue/src/experimental.ts
packages/vue/tsup.config.ts
integration/templates/vue-vite/src/router.ts
packages/vue/src/utils/childrenUtils.ts
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use Prettier for consistent code formatting
Files:
integration/tests/pricing-table.test.ts
packages/vue/src/experimental.ts
packages/vue/package.json
packages/vue/tsup.config.ts
integration/templates/vue-vite/src/router.ts
packages/vue/src/utils/childrenUtils.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use proper TypeScript error types
**/*.{ts,tsx}
: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoidany
type - preferunknown
when type is uncertain, then narrow with type guards
Useinterface
for object shapes that might be extended
Usetype
for unions, primitives, and computed types
Preferreadonly
properties for immutable data structures
Useprivate
for internal implementation details
Useprotected
for inheritance hierarchies
Usepublic
explicitly for clarity in public APIs
Preferreadonly
for properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Useconst assertions
for literal types:as const
Usesatisfies
operator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports:import type { ... } from ...
Noany
types without justification
Proper error handling with typed errors
Consistent use ofreadonly
for immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)
Files:
integration/tests/pricing-table.test.ts
packages/vue/src/experimental.ts
packages/vue/tsup.config.ts
integration/templates/vue-vite/src/router.ts
packages/vue/src/utils/childrenUtils.ts
integration/**
📄 CodeRabbit inference engine (.cursor/rules/global.mdc)
Framework integration templates and E2E tests should be placed under the integration/ directory
Files:
integration/tests/pricing-table.test.ts
integration/templates/vue-vite/src/views/billing/CheckoutBtn.vue
integration/templates/vue-vite/src/views/billing/SubscriptionDetailsBtn.vue
integration/templates/vue-vite/src/router.ts
integration/templates/vue-vite/src/views/billing/PlanDetailsBtn.vue
integration/**/*
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
End-to-end tests and integration templates must be located in the 'integration/' directory.
Files:
integration/tests/pricing-table.test.ts
integration/templates/vue-vite/src/views/billing/CheckoutBtn.vue
integration/templates/vue-vite/src/views/billing/SubscriptionDetailsBtn.vue
integration/templates/vue-vite/src/router.ts
integration/templates/vue-vite/src/views/billing/PlanDetailsBtn.vue
integration/**/*.{test,spec}.{js,ts}
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Integration tests should use Playwright.
Files:
integration/tests/pricing-table.test.ts
**/*.{js,ts,tsx,jsx}
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.
Files:
integration/tests/pricing-table.test.ts
packages/vue/src/experimental.ts
packages/vue/tsup.config.ts
integration/templates/vue-vite/src/router.ts
packages/vue/src/utils/childrenUtils.ts
packages/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
packages/vue/src/experimental.ts
packages/vue/tsup.config.ts
packages/vue/src/utils/childrenUtils.ts
packages/**/*.{ts,tsx,d.ts}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Packages should export TypeScript types alongside runtime code
Files:
packages/vue/src/experimental.ts
packages/vue/tsup.config.ts
packages/vue/src/utils/childrenUtils.ts
packages/*/package.json
📄 CodeRabbit inference engine (.cursor/rules/global.mdc)
All publishable packages should be placed under the packages/ directory
packages/*/package.json
: All publishable packages must be located in the 'packages/' directory.
All packages must be published under the @clerk namespace on npm.
Semantic versioning must be used across all packages.
Files:
packages/vue/package.json
packages/*/tsup.config.{js,ts}
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
TypeScript compilation and bundling must use tsup.
Files:
packages/vue/tsup.config.ts
⏰ 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). (22)
- GitHub Check: Integration Tests (machine, chrome)
- GitHub Check: Integration Tests (nextjs, chrome, 15)
- GitHub Check: Integration Tests (billing, chrome)
- GitHub Check: Integration Tests (nextjs, chrome, 14)
- GitHub Check: Integration Tests (sessions, chrome)
- GitHub Check: Integration Tests (nuxt, chrome)
- GitHub Check: Integration Tests (expo-web, chrome)
- GitHub Check: Integration Tests (elements, chrome)
- GitHub Check: Integration Tests (astro, chrome)
- GitHub Check: Integration Tests (vue, chrome)
- GitHub Check: Integration Tests (quickstart, chrome)
- GitHub Check: Integration Tests (express, chrome)
- GitHub Check: Integration Tests (ap-flows, chrome)
- GitHub Check: Publish with pkg-pr-new
- GitHub Check: Unit Tests (18, --filter=@clerk/astro --filter=@clerk/backend --filter=@clerk/express --filter=@c...
- GitHub Check: Unit Tests (22, **)
- GitHub Check: Static analysis
- GitHub Check: Formatting | Dedupe | Changeset
- GitHub Check: semgrep/ci
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (8)
packages/vue/tsup.config.ts (2)
20-20
: LGTM on esbuild Vue plugin usage
12-12
: Build and verify experimental types output
Tsup config for packages/vue disablesdts
, so after running the package build, confirm thatdist/experimental.d.ts
is generated and aligns with the"types": "./dist/experimental.d.ts"
export inpackage.json
.packages/vue/src/utils/childrenUtils.ts (1)
6-13
: LGTM: extended ButtonName union covers new experimental buttonspackages/vue/package.json (1)
33-36
: New./experimental
export — verify build outputs and release semantics
- Ensure tsup includes
./src/experimental.ts
sodist/experimental.js
is emitted, andvue-tsc
generatesdist/experimental.d.ts
.- Since this widens the public surface, release as a minor and include docs/JSDoc for the new public APIs per guidelines.
- Run
pnpm lint:attw
/publint to validate the subpath export.If helpful, I can add the tsup entry and a changeset bump.
integration/templates/vue-vite/src/views/billing/CheckoutBtn.vue (1)
3-11
: LGTM — proper SignedIn gating and clear propsThe example is safe and aligned with the new experimental API.
packages/vue/src/components/CheckoutButton.vue (1)
15-23
: SSR/hydration caveat: throwing in setup().Throwing synchronously in setup can break SSR/hydration if auth state is not ready immediately. Consider guarding with a mounted check or a ready flag from
useAuth
.Would you like a patch that converts these throws to runtime guards with warnings until auth/org context is ready, then throws only when definitively missing?
packages/vue/src/components/SubscriptionDetailsButton.vue (1)
15-23
: SSR readiness check before throwing.Throwing in setup may break SSR/hydration while auth/org is still resolving.
I can provide a guarded variant (mounted + reactive checks) mirroring Clerk React’s runtime preconditions. Want a patch?
packages/vue/src/experimental.ts (1)
1-41
: Exports look correct and tree-shake friendly.Named exports for components and
export type
re-exports align with our bundling and typings strategy. No issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great here!
Description
Partially fixes BILL-1181
Checklist
pnpm test
runs as expected.pnpm build
runs as expected.Type of change
Summary by CodeRabbit