Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/violet-jobs-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/clerk-js': patch
---

Invalidate cached checkout on checkout drawer unmount
2 changes: 1 addition & 1 deletion packages/clerk-js/bundlewatch.config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"files": [
{ "path": "./dist/clerk.js", "maxSize": "590kB" },
{ "path": "./dist/clerk.browser.js", "maxSize": "73.64KB" },
{ "path": "./dist/clerk.browser.js", "maxSize": "73.67KB" },
{ "path": "./dist/clerk.headless*.js", "maxSize": "55KB" },
{ "path": "./dist/ui-common*.js", "maxSize": "99KB" },
{ "path": "./dist/vendors*.js", "maxSize": "36KB" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export class __experimental_CommerceBilling implements __experimental_CommerceBi
})
)?.response as unknown as __experimental_CommerceCheckoutJSON;

return new __experimental_CommerceCheckout(json);
const checkout = new __experimental_CommerceCheckout(json);
checkout.pathRoot = orgId ? `/organizations/${orgId}/commerce/checkouts` : `/me/commerce/checkouts`;
return checkout;
};
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { __experimental_CheckoutProps, __experimental_CommerceCheckoutResource } from '@clerk/types';
import { useEffect } from 'react';

import { Alert, Spinner } from '../../customizables';
import { useCheckout } from '../../hooks';
Expand All @@ -8,12 +9,16 @@ import { CheckoutForm } from './CheckoutForm';
export const CheckoutPage = (props: __experimental_CheckoutProps) => {
const { planId, planPeriod, subscriberType, onSubscriptionComplete } = props;

const { checkout, updateCheckout, isLoading } = useCheckout({
const { checkout, isLoading, invalidate, updateCheckout } = useCheckout({
planId,
planPeriod,
subscriberType,
});

useEffect(() => {
return invalidate;
}, []);

const onCheckoutComplete = (newCheckout: __experimental_CommerceCheckoutResource) => {
updateCheckout(newCheckout);
onSubscriptionComplete?.();
Expand Down
20 changes: 15 additions & 5 deletions packages/clerk-js/src/ui/hooks/useCheckout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,20 @@ export const useCheckout = (props: __experimental_CheckoutProps) => {
const { organization } = useOrganization();
const [currentCheckout, setCurrentCheckout] = useState<__experimental_CommerceCheckoutResource | null>(null);

const { data: initialCheckout, isLoading } = useFetch(__experimental_commerce?.__experimental_billing.startCheckout, {
planId,
planPeriod,
...(subscriberType === 'org' ? { orgId: organization?.id } : {}),
});
const {
data: initialCheckout,
isLoading,
invalidate,
} = useFetch(
__experimental_commerce?.__experimental_billing.startCheckout,
{
planId,
planPeriod,
...(subscriberType === 'org' ? { orgId: organization?.id } : {}),
},
undefined,
'commerce-checkout',
);

useEffect(() => {
if (initialCheckout && !currentCheckout) {
Expand All @@ -30,5 +39,6 @@ export const useCheckout = (props: __experimental_CheckoutProps) => {
checkout: currentCheckout || initialCheckout,
updateCheckout,
isLoading,
invalidate,
};
};
Loading