-
Notifications
You must be signed in to change notification settings - Fork 419
chore(clerk-js,types): Replace redirectUrl with navigate in checkout.finalize() #6586
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
chore(clerk-js,types): Replace redirectUrl with navigate in checkout.finalize() #6586
Conversation
🦋 Changeset detectedLatest commit: b5757de The changes in this PR will be included in the next version bump. This PR includes changesets to release 22 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.
|
@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: |
📝 WalkthroughWalkthroughThe Billing Beta checkout finalization API was changed from a redirectUrl-based parameter to a programmatic navigate callback. The __experimental_CheckoutInstance.finalize signature now accepts params?: { navigate?: SetActiveNavigate } instead of { redirectUrl: string }. Implementation and hook/type definitions were updated to pass and expose the new navigate callback (SetActiveNavigate) across packages (clerk-js, shared, types). Tests and imports were adjusted accordingly. A changeset records minor package version bumps for @clerk/clerk-js, @clerk/shared, and @clerk/types. Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
🪧 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
CodeRabbit Configuration File (
|
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: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/shared/src/react/hooks/useCheckout.ts (1)
55-66: Finalize return type should be Promise (align with __experimental_CheckoutInstance).Typing finalize as returning void prevents consumers from awaiting it, while the implementation returns a Promise. Align with the public type to avoid breaking DX.
- finalize: (params?: { navigate?: SetActiveNavigate }) => void; + finalize: __experimental_CheckoutInstance['finalize'];If you apply this change, the SetActiveNavigate import will no longer be needed in this file.
🧹 Nitpick comments (5)
.changeset/tall-dryers-hide.md (1)
7-7: Add a brief migration note with example.Clarify the API change with a short “Before/After” so consumers can migrate quickly.
[Billing Beta] Replace `redirectUrl` with `navigate` in `checkout.finalize()` + +Migration (Beta): +- Before: + ```ts + await checkout.finalize({ redirectUrl: '/dashboard' }); + ``` +- After: + ```ts + await checkout.finalize({ + navigate: async ({ session }) => { + // Optional: use session to decide where to go + await router.push('/dashboard'); + }, + }); + ```packages/clerk-js/src/core/modules/checkout/instance.ts (1)
66-69: Annotate finalize with the public interface type for consistency and explicit return type.Matches the style used for start/confirm and satisfies our guideline for explicit return types on public APIs.
- const finalize = (params?: { navigate?: SetActiveNavigate }) => { - const { navigate } = params || {}; - return clerk.setActive({ session: clerk.session?.id, navigate }); - }; + const finalize: __experimental_CheckoutInstance['finalize'] = params => { + const { navigate } = params || {}; + return clerk.setActive({ session: clerk.session?.id, navigate }); + };packages/shared/src/react/hooks/useCheckout.ts (1)
1-6: Remove unused SetActiveNavigate import if you adopt the finalize type alias.After switching finalize’s type to __experimental_CheckoutInstance['finalize'], SetActiveNavigate is unused in this module.
import type { __experimental_CheckoutCacheState, __experimental_CheckoutInstance, CommerceCheckoutResource, - SetActiveNavigate, } from '@clerk/types';packages/types/src/clerk.ts (2)
91-98: Document navigate on finalize for the experimental API.Add concise JSDoc to set expectations (no navigation by default) and show the intended usage.
export type __experimental_CheckoutInstance = { confirm: (params: ConfirmCheckoutParams) => Promise<CheckoutResult>; start: () => Promise<CheckoutResult>; clear: () => void; + /** + * Finalizes checkout by setting the active session. + * If `navigate` is provided, it will be invoked just before switching the active session + * to let the host app perform navigation. If omitted, no navigation is performed by default. + */ finalize: (params?: { navigate?: SetActiveNavigate }) => Promise<void>; subscribe: (listener: (state: __experimental_CheckoutCacheState) => void) => () => void; getState: () => __experimental_CheckoutCacheState; };
120-125: Add a brief description for SetActiveNavigate.Clarifies when and how this callback is used.
export type BeforeEmitCallback = (session?: SignedInSessionResource | null) => void | Promise<any>; -export type SetActiveNavigate = ({ session }: { session: SessionResource }) => Promise<unknown>; +/** + * Function invoked right before Clerk switches the active session. + * Use it to commit app navigation based on the (soon-to-be) active session. + */ +export type SetActiveNavigate = ({ session }: { session: SessionResource }) => Promise<unknown>;
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (4)
.changeset/tall-dryers-hide.md(1 hunks)packages/clerk-js/src/core/modules/checkout/instance.ts(2 hunks)packages/shared/src/react/hooks/useCheckout.ts(2 hunks)packages/types/src/clerk.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (8)
**/*.{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:
packages/types/src/clerk.tspackages/clerk-js/src/core/modules/checkout/instance.tspackages/shared/src/react/hooks/useCheckout.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:
packages/types/src/clerk.tspackages/clerk-js/src/core/modules/checkout/instance.tspackages/shared/src/react/hooks/useCheckout.ts
packages/**/*.{ts,tsx}
📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
packages/types/src/clerk.tspackages/clerk-js/src/core/modules/checkout/instance.tspackages/shared/src/react/hooks/useCheckout.ts
packages/**/*.{ts,tsx,d.ts}
📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)
Packages should export TypeScript types alongside runtime code
Files:
packages/types/src/clerk.tspackages/clerk-js/src/core/modules/checkout/instance.tspackages/shared/src/react/hooks/useCheckout.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
Avoidanytype - preferunknownwhen type is uncertain, then narrow with type guards
Useinterfacefor object shapes that might be extended
Usetypefor unions, primitives, and computed types
Preferreadonlyproperties for immutable data structures
Useprivatefor internal implementation details
Useprotectedfor inheritance hierarchies
Usepublicexplicitly for clarity in public APIs
Preferreadonlyfor 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 assertionsfor literal types:as const
Usesatisfiesoperator 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 ...
Noanytypes without justification
Proper error handling with typed errors
Consistent use ofreadonlyfor 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:
packages/types/src/clerk.tspackages/clerk-js/src/core/modules/checkout/instance.tspackages/shared/src/react/hooks/useCheckout.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:
packages/types/src/clerk.tspackages/clerk-js/src/core/modules/checkout/instance.tspackages/shared/src/react/hooks/useCheckout.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.
Files:
packages/types/src/clerk.tspackages/clerk-js/src/core/modules/checkout/instance.tspackages/shared/src/react/hooks/useCheckout.ts
.changeset/**
📄 CodeRabbit Inference Engine (.cursor/rules/monorepo.mdc)
Automated releases must use Changesets.
Files:
.changeset/tall-dryers-hide.md
🧬 Code Graph Analysis (2)
packages/clerk-js/src/core/modules/checkout/instance.ts (1)
packages/types/src/clerk.ts (1)
SetActiveNavigate(123-123)
packages/shared/src/react/hooks/useCheckout.ts (1)
packages/types/src/clerk.ts (1)
SetActiveNavigate(123-123)
⏰ 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). (5)
- GitHub Check: Integration Tests (nextjs, chrome, 14)
- GitHub Check: Integration Tests (billing, chrome)
- GitHub Check: Integration Tests (nextjs, chrome, 15)
- GitHub Check: Integration Tests (react-router, chrome)
- GitHub Check: Integration Tests (generic, chrome)
🔇 Additional comments (3)
packages/clerk-js/src/core/modules/checkout/instance.ts (1)
66-69: LGTM: redirectUrl → navigate behavior is correctly wired to setActive.The optional navigate callback is passed through to setActive and defaults to no navigation when omitted.
packages/shared/src/react/hooks/useCheckout.ts (2)
127-139: Asyncfinalizeis correctly exposed and no lingering sync usages foundThe hook now returns
manager.finalize(anasyncfunction returning aPromise), so consumers canawait checkout.finalize(). Verification shows:• No calls passing a now-removed
redirectUrlparameter
• No remaining call sites assuming a synchronousfinalize
• Hook return already exposes the async signature viamanager.finalizeLooks good to merge.
133-136: Ensure finalize remains passthrough to manager.finalize (awaitable).Returning the awaitable function preserves sequencing for consumers that depend on it.
…-finalize-from-usecheckout
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: 0
🧹 Nitpick comments (1)
packages/shared/src/react/hooks/__tests__/useCheckout.type.spec.ts (1)
93-94: Finalize params type assertion is correct; add return-type assertion and a couple of negative cases.You already assert the parameter shape. Add a return-type check and lightweight negative cases to guard against regressions (legacy redirectUrl and wrong navigate type).
Apply this minimal diff to assert the return type:
- expectTypeOf<FinalizeMethod>().parameter(0).toEqualTypeOf<{ navigate?: SetActiveNavigate } | undefined>(); + expectTypeOf<FinalizeMethod>().parameter(0).toEqualTypeOf<{ navigate?: SetActiveNavigate } | undefined>(); + expectTypeOf<FinalizeMethod>().returns.toBeVoid();Optionally, add these additional type assertions to make the intent explicit:
// Add near the same "has correct method signatures" test block type FinalizeParam = Parameters<FinalizeMethod>[0]; // legacy prop should not be accepted expectTypeOf<FinalizeParam>().not.toEqualTypeOf<{ redirectUrl: string }>(); // wrong type for navigate should not be accepted expectTypeOf<FinalizeParam>().not.toEqualTypeOf<{ navigate: string }>();
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
packages/shared/src/react/hooks/__tests__/useCheckout.type.spec.ts(3 hunks)
🧰 Additional context used
📓 Path-based instructions (9)
**/*.{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:
packages/shared/src/react/hooks/__tests__/useCheckout.type.spec.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:
packages/shared/src/react/hooks/__tests__/useCheckout.type.spec.ts
packages/**/*.{ts,tsx}
📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
packages/shared/src/react/hooks/__tests__/useCheckout.type.spec.ts
packages/**/*.{ts,tsx,d.ts}
📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)
Packages should export TypeScript types alongside runtime code
Files:
packages/shared/src/react/hooks/__tests__/useCheckout.type.spec.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
Avoidanytype - preferunknownwhen type is uncertain, then narrow with type guards
Useinterfacefor object shapes that might be extended
Usetypefor unions, primitives, and computed types
Preferreadonlyproperties for immutable data structures
Useprivatefor internal implementation details
Useprotectedfor inheritance hierarchies
Usepublicexplicitly for clarity in public APIs
Preferreadonlyfor 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 assertionsfor literal types:as const
Usesatisfiesoperator 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 ...
Noanytypes without justification
Proper error handling with typed errors
Consistent use ofreadonlyfor 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:
packages/shared/src/react/hooks/__tests__/useCheckout.type.spec.ts
packages/**/*.{test,spec}.{js,jsx,ts,tsx}
📄 CodeRabbit Inference Engine (.cursor/rules/monorepo.mdc)
Unit tests should use Jest or Vitest as the test runner.
Files:
packages/shared/src/react/hooks/__tests__/useCheckout.type.spec.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:
packages/shared/src/react/hooks/__tests__/useCheckout.type.spec.ts
**/__tests__/**/*.{ts,tsx}
📄 CodeRabbit Inference Engine (.cursor/rules/typescript.mdc)
**/__tests__/**/*.{ts,tsx}: Create type-safe test builders/factories
Use branded types for test isolation
Implement proper mock types that match interfaces
Files:
packages/shared/src/react/hooks/__tests__/useCheckout.type.spec.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.
Files:
packages/shared/src/react/hooks/__tests__/useCheckout.type.spec.ts
🧬 Code Graph Analysis (1)
packages/shared/src/react/hooks/__tests__/useCheckout.type.spec.ts (1)
packages/types/src/clerk.ts (1)
SetActiveNavigate(123-123)
⏰ 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). (6)
- GitHub Check: Formatting | Dedupe | Changeset
- GitHub Check: Build Packages
- GitHub Check: semgrep/ci
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (2)
packages/shared/src/react/hooks/__tests__/useCheckout.type.spec.ts (2)
8-9: Type-only import of SetActiveNavigate is correct and aligns with the new public API.Importing as a type keeps bundles clean and matches the updated type in @clerk/types.
249-251: No lingeringredirectUrlinfinalizeAPI
TheexpectTypeOf<CheckoutObject['finalize']>()assertion correctly reflects the new signature(params?: { navigate?: SetActiveNavigate }) => void. A grep over the codebase confirms no remainingredirectUrlreferences in calls, types/interfaces, or docs forfinalize.
Description
Checklist
pnpm testruns as expected.pnpm buildruns as expected.Type of change
Summary by CodeRabbit
New Features
Chores