Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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/smooth-rats-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bigcommerce/catalyst-core": patch
---

Preconnect to checkout domain on cart page to improve checkout load time
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🍹 Would it be beneficial to use this anywhere else? Wondering if we generalize it CheckoutPreconnectPreconnectResource and add an optional param for options: PreconnectOptions

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I thought about that, and I don't think so - Next.js already has great defaults for this in the rest of the application, our situation here is special because we are redirecting externally. The other place where this might be useful is in areas where you're likely to proceed directly to checkout, but this is the only place in the Catalyst codebase where this is relevant right now.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use client';

import { preconnect } from 'react-dom';

export function CheckoutPreconnect({ url }: { url: string }) {
preconnect(url);

return null;
}
5 changes: 5 additions & 0 deletions core/app/[locale]/(default)/cart/page-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ const CartPageQuery = graphql(
`
query CartPageQuery($cartId: String) {
site {
settings {
url {
checkoutUrl
}
}
cart(entityId: $cartId) {
entityId
version
Expand Down
4 changes: 4 additions & 0 deletions core/app/[locale]/(default)/cart/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { updateCouponCode } from './_actions/update-coupon-code';
import { updateLineItem } from './_actions/update-line-item';
import { updateShippingInfo } from './_actions/update-shipping-info';
import { CartViewed } from './_components/cart-viewed';
import { CheckoutPreconnect } from './_components/checkout-preconnect';
import { getCart, getShippingCountries } from './page-data';

interface Props {
Expand Down Expand Up @@ -152,9 +153,12 @@ export default async function Cart({ params }: Props) {
const showShippingForm =
shippingConsignment?.address && !shippingConsignment.selectedShippingOption;

const checkoutUrl = data.site.settings?.url.checkoutUrl;

return (
<>
<CartAnalyticsProvider data={Streamable.from(() => getAnalyticsData(cartId))}>
{checkoutUrl ? <CheckoutPreconnect url={checkoutUrl} /> : null}
<CartComponent
cart={{
lineItems: formattedLineItems,
Expand Down
Loading