Skip to content

Commit a34cba4

Browse files
committed
feat(checkout): CHECKOUT-9388 Lazy load customer strategies by importing them on demand
1 parent a8d124d commit a34cba4

File tree

26 files changed

+190
-15
lines changed

26 files changed

+190
-15
lines changed

packages/amazon-pay-v2-integration/src/AmazonPayV2Button.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { createAmazonPayV2CustomerStrategy } from '@bigcommerce/checkout-sdk/integrations/amazon-pay';
12
import React, { type FunctionComponent, useEffect } from 'react';
23

34
import { CheckoutButton } from '@bigcommerce/checkout/checkout-button-integration';
@@ -33,9 +34,16 @@ const AmazonPayV2Button: FunctionComponent<CheckoutButtonProps> = (props) => {
3334
beautifyAmazonButton();
3435
}, []);
3536

37+
const additionalInitializationOptions = {
38+
integrations: [createAmazonPayV2CustomerStrategy],
39+
};
40+
3641
return (
3742
<div className="AmazonPayContainer">
38-
<CheckoutButton {...props} />
43+
<CheckoutButton
44+
additionalInitializationOptions={additionalInitializationOptions}
45+
{...props}
46+
/>
3947
</div>
4048
);
4149
};

packages/bigcommerce-payments-integration/src/BigCommercePayments/BigCommercePaymentsButton.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
createCheckoutService,
55
createLanguageService,
66
} from '@bigcommerce/checkout-sdk';
7+
import { createBigCommercePaymentsCustomerStrategy } from '@bigcommerce/checkout-sdk/integrations';
78
import React from 'react';
89

910
import { type CheckoutButtonProps } from '@bigcommerce/checkout/payment-integration-api';
@@ -39,6 +40,7 @@ describe('BigCommercePaymentsButton', () => {
3940

4041
expect(checkoutService.initializeCustomer).toHaveBeenCalledWith({
4142
methodId: defaultProps.methodId,
43+
integrations: [createBigCommercePaymentsCustomerStrategy],
4244
bigcommerce_payments: {
4345
container: 'bigcommerce-payments-button-container',
4446
onClick: expect.any(Function),

packages/bigcommerce-payments-integration/src/BigCommercePayments/BigCommercePaymentsButton.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { createBigCommercePaymentsCustomerStrategy } from '@bigcommerce/checkout-sdk/integrations/bigcommerce-payments';
12
import React, { type FunctionComponent } from 'react';
23

34
import { CheckoutButton } from '@bigcommerce/checkout/checkout-button-integration';
@@ -12,6 +13,7 @@ const BigCommercePaymentsButton: FunctionComponent<CheckoutButtonProps> = (props
1213
const additionalInitializationOptions = {
1314
onComplete: navigateToOrderConfirmation,
1415
onError: props.onUnhandledError,
16+
integrations: [createBigCommercePaymentsCustomerStrategy],
1517
};
1618

1719
return (

packages/bigcommerce-payments-integration/src/BigCommercePaymentsPayLater/BigcommercePaymentsPayLaterButton.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
createCheckoutService,
55
createLanguageService,
66
} from '@bigcommerce/checkout-sdk';
7+
import { createBigCommercePaymentsPayLaterCustomerStrategy } from '@bigcommerce/checkout-sdk/integrations';
78
import React from 'react';
89

910
import { type CheckoutButtonProps } from '@bigcommerce/checkout/payment-integration-api';
@@ -39,6 +40,7 @@ describe('BigcommercePaymentsPayLaterButton', () => {
3940

4041
expect(checkoutService.initializeCustomer).toHaveBeenCalledWith({
4142
methodId: defaultProps.methodId,
43+
integrations: [createBigCommercePaymentsPayLaterCustomerStrategy],
4244
bigcommerce_payments_paylater: {
4345
container: 'bigcommerce-payments-paylater-button-container',
4446
onClick: expect.any(Function),

packages/bigcommerce-payments-integration/src/BigCommercePaymentsPayLater/BigcommercePaymentsPayLaterButton.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { createBigCommercePaymentsPayLaterCustomerStrategy } from '@bigcommerce/checkout-sdk/integrations/bigcommerce-payments';
12
import React, { type FunctionComponent } from 'react';
23

34
import { CheckoutButton } from '@bigcommerce/checkout/checkout-button-integration';
@@ -12,6 +13,7 @@ const BigcommercePaymentsPayLaterButton: FunctionComponent<CheckoutButtonProps>
1213
const additionalInitializationOptions = {
1314
onComplete: navigateToOrderConfirmation,
1415
onError: props.onUnhandledError,
16+
integrations: [createBigCommercePaymentsPayLaterCustomerStrategy],
1517
};
1618

1719
return (

packages/bolt-integration/src/BoltEmbeddedPaymentMethod.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { createBoltPaymentStrategy } from '@bigcommerce/checkout-sdk/integrations/bolt';
1+
import { type CustomerInitializeOptions } from '@bigcommerce/checkout-sdk';
2+
import {
3+
createBoltCustomerStrategy,
4+
createBoltPaymentStrategy,
5+
} from '@bigcommerce/checkout-sdk/integrations/bolt';
26
import React, { type FunctionComponent, useCallback, useState } from 'react';
37

48
import { HostedWidgetPaymentComponent } from '@bigcommerce/checkout/hosted-widget-integration';
@@ -49,6 +53,16 @@ const BoltEmbeddedPaymentMethod: FunctionComponent<PaymentMethodProps> = ({
4953
[checkoutService, boltEmbeddedContainerId, setFieldValue],
5054
);
5155

56+
const initializeBoltCustomer = useCallback(
57+
(options: CustomerInitializeOptions) => {
58+
return checkoutService.initializeCustomer({
59+
...options,
60+
integrations: [createBoltCustomerStrategy],
61+
});
62+
},
63+
[checkoutService],
64+
);
65+
5266
const renderCustomPaymentForm = useCallback(
5367
() => (
5468
<BoltCustomForm
@@ -73,6 +87,7 @@ const BoltEmbeddedPaymentMethod: FunctionComponent<PaymentMethodProps> = ({
7387
deinitializePayment={checkoutService.deinitializePayment}
7488
disableSubmit={disableSubmit}
7589
hidePaymentSubmitButton={hidePaymentSubmitButton}
90+
initializeCustomer={initializeBoltCustomer}
7691
initializePayment={initializeBoltPayment}
7792
instruments={instruments}
7893
isInitializing={isInitializingPayment()}

packages/checkout-button-integration/src/CheckoutButton.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ const CheckoutButton: FunctionComponent<CheckoutButtonProps> = ({
1414
onUnhandledError,
1515
onWalletButtonClick,
1616
additionalInitializationOptions,
17+
integrations,
1718
}) => {
1819
const initializeCustomerStrategyOrThrow = async () => {
1920
try {
2021
await initializeCustomer({
2122
methodId,
23+
integrations,
2224
[methodId]: {
2325
container: containerId,
2426
onUnhandledError,

packages/core/src/app/customer/CheckoutButtonContainer.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { type CheckoutSelectors, type CheckoutService } from '@bigcommerce/checkout-sdk';
22
import classNames from 'classnames';
3-
import React, { type FunctionComponent, memo, Suspense } from 'react';
3+
import React, { type FunctionComponent, lazy, memo, Suspense } from 'react';
44

55
import { TranslatedString, useLocale } from '@bigcommerce/checkout/locale';
66
import { type CheckoutContextProps } from '@bigcommerce/checkout/payment-integration-api';
@@ -10,7 +10,8 @@ import { withCheckout } from '../checkout';
1010

1111
import { getSupportedMethodIds } from './getSupportedMethods';
1212
import resolveCheckoutButton from './resolveCheckoutButton';
13-
import CheckoutButtonV1Resolver from './WalletButtonV1Resolver';
13+
14+
const CheckoutButtonV1Resolver = lazy(() => import(/* webpackChunkName: "wallet-button-v1-resolver" */'./WalletButtonV1Resolver'));
1415

1516
interface CheckoutButtonContainerProps {
1617
isPaymentStepActive: boolean;

packages/core/src/app/customer/CheckoutButtonList.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
type CustomerRequestOptions,
66
} from '@bigcommerce/checkout-sdk';
77
import { noop } from 'lodash';
8-
import React, { type FunctionComponent, memo } from 'react';
8+
import React, { type FunctionComponent, lazy, memo } from 'react';
99

1010
import { TranslatedString, useLocale } from '@bigcommerce/checkout/locale';
1111
import { type CheckoutContextProps } from '@bigcommerce/checkout/payment-integration-api';
@@ -15,7 +15,8 @@ import { withCheckout } from '../checkout';
1515

1616
import { getSupportedMethodIds } from './getSupportedMethods';
1717
import resolveCheckoutButton from './resolveCheckoutButton';
18-
import CheckoutButtonV1Resolver from './WalletButtonV1Resolver';
18+
19+
const CheckoutButtonV1Resolver = lazy(() => import(/* webpackChunkName: "wallet-button-v1-resolver" */'./WalletButtonV1Resolver'));
1920

2021
export interface CheckoutButtonListProps {
2122
hideText?: boolean;

packages/core/src/app/customer/Customer.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ import {
99
type FormField,
1010
type GuestCredentials,
1111
type SignInEmail,
12-
type StoreConfig,
1312
} from '@bigcommerce/checkout-sdk';
13+
import { createBigCommercePaymentsFastlaneCustomerStrategy } from '@bigcommerce/checkout-sdk/integrations/bigcommerce-payments';
14+
import { createBoltCustomerStrategy } from '@bigcommerce/checkout-sdk/integrations/bolt';
15+
import { createBraintreeFastlaneCustomerStrategy } from '@bigcommerce/checkout-sdk/integrations/braintree';
16+
import { createPayPalCommerceFastlaneCustomerStrategy } from '@bigcommerce/checkout-sdk/integrations/paypal-commerce';
17+
import { createStripeLinkV2CustomerStrategy, createStripeUPECustomerStrategy } from '@bigcommerce/checkout-sdk/integrations/stripe';
1418
import { noop } from 'lodash';
1519
import React, { Component, type ReactNode } from 'react';
1620

@@ -128,7 +132,18 @@ class Customer extends Component<CustomerProps & WithCheckoutCustomerProps & Ana
128132

129133
try {
130134
if (providerWithCustomCheckout && providerWithCustomCheckout !== PaymentMethodId.StripeUPE) {
131-
await initializeCustomer({ methodId: providerWithCustomCheckout });
135+
// TODO: Split out into separate chunks so they can be lazy loaded
136+
await initializeCustomer({
137+
methodId: providerWithCustomCheckout,
138+
integrations: [
139+
createBigCommercePaymentsFastlaneCustomerStrategy,
140+
createBraintreeFastlaneCustomerStrategy,
141+
createPayPalCommerceFastlaneCustomerStrategy,
142+
createBoltCustomerStrategy,
143+
createStripeUPECustomerStrategy,
144+
createStripeLinkV2CustomerStrategy,
145+
],
146+
});
132147
}
133148
} catch (error) {
134149
onUnhandledError(error);
@@ -589,7 +604,7 @@ export function mapToWithCheckoutCustomerProps({
589604
isExpressPrivacyPolicy,
590605
shouldRedirectToStorefrontForAuth
591606
},
592-
} = config as StoreConfig & { checkoutSettings: { isAccountCreationEnabled: boolean } };
607+
} = config;
593608

594609
const providerWithCustomCheckout = getProviderWithCustomCheckout(
595610
config.checkoutSettings.providerWithCustomCheckout,

0 commit comments

Comments
 (0)