From b51421c33ddedeb9505e71ed128b2e8cd600b4e8 Mon Sep 17 00:00:00 2001 From: Mark Murray Date: Thu, 14 May 2026 10:16:35 +0100 Subject: [PATCH 1/3] Make preloading internal until supported --- .../Sources/App/CartManager.swift | 8 ++++---- .../Sources/Scenes/Cart/CartView.swift | 6 +++--- .../Sources/Scenes/Cart/CartViewController.swift | 12 ++++++------ .../ShopifyCheckoutKit/ShopifyCheckoutKit.swift | 4 ++-- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/platforms/swift/Samples/MobileBuyIntegration/MobileBuyIntegration/Sources/App/CartManager.swift b/platforms/swift/Samples/MobileBuyIntegration/MobileBuyIntegration/Sources/App/CartManager.swift index de959554..1af9ee47 100644 --- a/platforms/swift/Samples/MobileBuyIntegration/MobileBuyIntegration/Sources/App/CartManager.swift +++ b/platforms/swift/Samples/MobileBuyIntegration/MobileBuyIntegration/Sources/App/CartManager.swift @@ -53,10 +53,10 @@ class CartManager: ObservableObject { init() {} public func preloadCheckout() { - if let url = cart?.checkoutURL, isDirty { - ShopifyCheckoutKit.preload(checkout: url) - markCartAsReady() - } + // if let url = cart?.checkoutURL, isDirty { + // ShopifyCheckoutKit.preload(checkout: url) + // markCartAsReady() + // } } func markCartAsReady() { diff --git a/platforms/swift/Samples/MobileBuyIntegration/MobileBuyIntegration/Sources/Scenes/Cart/CartView.swift b/platforms/swift/Samples/MobileBuyIntegration/MobileBuyIntegration/Sources/Scenes/Cart/CartView.swift index ecb48075..92a92e92 100644 --- a/platforms/swift/Samples/MobileBuyIntegration/MobileBuyIntegration/Sources/Scenes/Cart/CartView.swift +++ b/platforms/swift/Samples/MobileBuyIntegration/MobileBuyIntegration/Sources/Scenes/Cart/CartView.swift @@ -275,9 +275,9 @@ struct CartLines: View { CartManager.shared.cart = cart updating = nil - if let checkoutUrl = cart.checkoutURL { - ShopifyCheckoutKit.preload(checkout: checkoutUrl) - } + // if let checkoutUrl = cart.checkoutURL { + // ShopifyCheckoutKit.preload(checkout: checkoutUrl) + // } } }, label: { diff --git a/platforms/swift/Samples/MobileBuyIntegration/MobileBuyIntegration/Sources/Scenes/Cart/CartViewController.swift b/platforms/swift/Samples/MobileBuyIntegration/MobileBuyIntegration/Sources/Scenes/Cart/CartViewController.swift index d4a1e012..4c44c8d1 100644 --- a/platforms/swift/Samples/MobileBuyIntegration/MobileBuyIntegration/Sources/Scenes/Cart/CartViewController.swift +++ b/platforms/swift/Samples/MobileBuyIntegration/MobileBuyIntegration/Sources/Scenes/Cart/CartViewController.swift @@ -339,9 +339,9 @@ class CartViewController: UIViewController, UITableViewDelegate, UITableViewData tableView.reloadData() - if let url = CartManager.shared.cart?.checkoutURL { - ShopifyCheckoutKit.preload(checkout: url) - } + // if let url = CartManager.shared.cart?.checkoutURL { + // ShopifyCheckoutKit.preload(checkout: url) + // } } // MARK: UITableViewDataSource @@ -375,9 +375,9 @@ class CartViewController: UIViewController, UITableViewDelegate, UITableViewData self.setupCheckoutButtonContent() cell.quantityLabel.text = "\(cart.lines.nodes[indexPath.item].quantity)" - if let checkoutUrl = cart.checkoutURL { - ShopifyCheckoutKit.preload(checkout: checkoutUrl) - } + // if let checkoutUrl = cart.checkoutURL { + // ShopifyCheckoutKit.preload(checkout: checkoutUrl) + // } } } return cell diff --git a/platforms/swift/Sources/ShopifyCheckoutKit/ShopifyCheckoutKit.swift b/platforms/swift/Sources/ShopifyCheckoutKit/ShopifyCheckoutKit.swift index b6da73a9..599a7a2d 100644 --- a/platforms/swift/Sources/ShopifyCheckoutKit/ShopifyCheckoutKit.swift +++ b/platforms/swift/Sources/ShopifyCheckoutKit/ShopifyCheckoutKit.swift @@ -46,8 +46,8 @@ public func configure(_ block: (inout Configuration) -> Void) { block(&configuration) } -/// Preloads the checkout for faster presentation. -public func preload(checkout url: URL) { +/// Public preload support is coming soon. +internal func preload(checkout url: URL) { guard configuration.preloading.enabled else { return } From 9e4ef2f05bf9a8d5a2b9cf5098383c4bd0244a9b Mon Sep 17 00:00:00 2001 From: Mark Murray Date: Thu, 14 May 2026 10:46:40 +0100 Subject: [PATCH 2/3] [Android] Hide preload from public API --- platforms/android/lib/api/lib.api | 1 - .../com/shopify/checkoutkit/ShopifyCheckoutKit.kt | 4 +++- .../cart/CartViewModel.kt | 14 +++++++------- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/platforms/android/lib/api/lib.api b/platforms/android/lib/api/lib.api index 268dcabb..50391ee4 100644 --- a/platforms/android/lib/api/lib.api +++ b/platforms/android/lib/api/lib.api @@ -3933,7 +3933,6 @@ public final class com/shopify/checkoutkit/ShopifyCheckoutKit { public static final fun configure (Lcom/shopify/checkoutkit/ConfigurationUpdater;)V public static final fun getConfiguration ()Lcom/shopify/checkoutkit/Configuration; public static final fun invalidate ()V - public static final fun preload (Ljava/lang/String;Landroidx/activity/ComponentActivity;)V public static final fun present (Ljava/lang/String;Landroidx/activity/ComponentActivity;Lcom/shopify/checkoutkit/DefaultCheckoutEventProcessor;)Lcom/shopify/checkoutkit/CheckoutKitDialog; public static final fun present (Ljava/lang/String;Landroidx/activity/ComponentActivity;Lcom/shopify/checkoutkit/DefaultCheckoutEventProcessor;Lcom/shopify/checkoutkit/CheckoutCommunicationClient;)Lcom/shopify/checkoutkit/CheckoutKitDialog; public static synthetic fun present$default (Ljava/lang/String;Landroidx/activity/ComponentActivity;Lcom/shopify/checkoutkit/DefaultCheckoutEventProcessor;Lcom/shopify/checkoutkit/CheckoutCommunicationClient;ILjava/lang/Object;)Lcom/shopify/checkoutkit/CheckoutKitDialog; diff --git a/platforms/android/lib/src/main/java/com/shopify/checkoutkit/ShopifyCheckoutKit.kt b/platforms/android/lib/src/main/java/com/shopify/checkoutkit/ShopifyCheckoutKit.kt index f01dffb1..3ba11ce1 100644 --- a/platforms/android/lib/src/main/java/com/shopify/checkoutkit/ShopifyCheckoutKit.kt +++ b/platforms/android/lib/src/main/java/com/shopify/checkoutkit/ShopifyCheckoutKit.kt @@ -89,9 +89,11 @@ public object ShopifyCheckoutKit { * * @param checkoutUrl The URL of the checkout to be loaded, this can be obtained via the Storefront API * @param context The context the checkout is being presented from + * + * Public preload support is coming soon. */ @JvmStatic - public fun preload(checkoutUrl: String, context: ComponentActivity) { + internal fun preload(checkoutUrl: String, context: ComponentActivity) { log.d("ShopifyCheckoutKit", "Preload called. Preloading enabled ${configuration.preloading.enabled}.") if (!configuration.preloading.enabled) return diff --git a/platforms/android/samples/MobileBuyIntegration/app/src/main/java/com/shopify/checkout_kit_mobile_buy_integration_sample/cart/CartViewModel.kt b/platforms/android/samples/MobileBuyIntegration/app/src/main/java/com/shopify/checkout_kit_mobile_buy_integration_sample/cart/CartViewModel.kt index dbe85084..56491617 100644 --- a/platforms/android/samples/MobileBuyIntegration/app/src/main/java/com/shopify/checkout_kit_mobile_buy_integration_sample/cart/CartViewModel.kt +++ b/platforms/android/samples/MobileBuyIntegration/app/src/main/java/com/shopify/checkout_kit_mobile_buy_integration_sample/cart/CartViewModel.kt @@ -127,13 +127,13 @@ class CartViewModel( fun preloadCheckout( activity: ComponentActivity, ) { - val state = _cartState.value - if (state is CartState.Cart) { - Timber.i("Preloading checkout with url ${state.checkoutUrl}") - ShopifyCheckoutKit.preload(state.checkoutUrl, activity) - } else { - Timber.i("Skipping checkout preload, cart is empty") - } + // val state = _cartState.value + // if (state is CartState.Cart) { + // Timber.i("Preloading checkout with url ${state.checkoutUrl}") + // ShopifyCheckoutKit.preload(state.checkoutUrl, activity) + // } else { + // Timber.i("Skipping checkout preload, cart is empty") + // } } fun continueShopping(navController: NavController) { From b19e097e40558c7b17b0be212cd09722fd852b96 Mon Sep 17 00:00:00 2001 From: Mark Murray Date: Thu, 14 May 2026 11:02:10 +0100 Subject: [PATCH 3/3] Drop `preload` from React Native public API --- .../react-native/__mocks__/react-native.ts | 1 - .../checkoutkit/ShopifyCheckoutKitModule.java | 9 -- .../ios/ShopifyCheckoutKit.swift | 8 - .../checkout-kit-react-native/src/context.tsx | 13 +- .../checkout-kit-react-native/src/index.d.ts | 5 - .../checkout-kit-react-native/src/index.ts | 13 +- .../src/specs/NativeShopifyCheckoutKit.ts | 5 +- .../tests/context.test.tsx | 77 ++------- .../tests/index.test.ts | 153 +++++------------- .../ShopifyCheckoutKitModuleTest.java | 13 -- .../react-native/sample/src/context/Cart.tsx | 21 +-- 11 files changed, 65 insertions(+), 253 deletions(-) diff --git a/platforms/react-native/__mocks__/react-native.ts b/platforms/react-native/__mocks__/react-native.ts index fc2e5da6..7ecdf764 100644 --- a/platforms/react-native/__mocks__/react-native.ts +++ b/platforms/react-native/__mocks__/react-native.ts @@ -50,7 +50,6 @@ const exampleConfig = {preloading: true}; const ShopifyCheckoutKit = { version: '0.7.0', getConstants: jest.fn(() => ({version: '0.7.0'})), - preload: jest.fn(), present: jest.fn(), dismiss: jest.fn(), invalidateCache: jest.fn(), diff --git a/platforms/react-native/modules/@shopify/checkout-kit-react-native/android/src/main/java/com/shopify/reactnative/checkoutkit/ShopifyCheckoutKitModule.java b/platforms/react-native/modules/@shopify/checkout-kit-react-native/android/src/main/java/com/shopify/reactnative/checkoutkit/ShopifyCheckoutKitModule.java index 4061d0a3..5fc32c59 100644 --- a/platforms/react-native/modules/@shopify/checkout-kit-react-native/android/src/main/java/com/shopify/reactnative/checkoutkit/ShopifyCheckoutKitModule.java +++ b/platforms/react-native/modules/@shopify/checkout-kit-react-native/android/src/main/java/com/shopify/reactnative/checkoutkit/ShopifyCheckoutKitModule.java @@ -99,15 +99,6 @@ public void dismiss() { } } - @ReactMethod - public void preload(String checkoutURL) { - Activity currentActivity = getCurrentActivity(); - - if (currentActivity instanceof ComponentActivity) { - ShopifyCheckoutSheetKit.preload(checkoutURL, (ComponentActivity) currentActivity); - } - } - @ReactMethod public void invalidateCache() { ShopifyCheckoutSheetKit.invalidate(); diff --git a/platforms/react-native/modules/@shopify/checkout-kit-react-native/ios/ShopifyCheckoutKit.swift b/platforms/react-native/modules/@shopify/checkout-kit-react-native/ios/ShopifyCheckoutKit.swift index c500f0e4..72d6508f 100644 --- a/platforms/react-native/modules/@shopify/checkout-kit-react-native/ios/ShopifyCheckoutKit.swift +++ b/platforms/react-native/modules/@shopify/checkout-kit-react-native/ios/ShopifyCheckoutKit.swift @@ -153,14 +153,6 @@ class RCTShopifyCheckoutKit: RCTEventEmitter, CheckoutDelegate { } } - @objc func preload(_ checkoutURL: String) { - DispatchQueue.main.async { - if let url = URL(string: checkoutURL) { - ShopifyCheckoutSheetKit.preload(checkout: url) - } - } - } - private func getColorScheme(_ colorScheme: String) -> ShopifyCheckoutSheetKit.Configuration.ColorScheme { switch colorScheme { case "web_default": diff --git a/platforms/react-native/modules/@shopify/checkout-kit-react-native/src/context.tsx b/platforms/react-native/modules/@shopify/checkout-kit-react-native/src/context.tsx index a75c1874..ef903160 100644 --- a/platforms/react-native/modules/@shopify/checkout-kit-react-native/src/context.tsx +++ b/platforms/react-native/modules/@shopify/checkout-kit-react-native/src/context.tsx @@ -41,7 +41,6 @@ interface Context { getConfig: () => Configuration | undefined; setConfig: (config: Configuration) => void; removeEventListeners: RemoveEventListeners; - preload: (checkoutUrl: string) => void; present: (checkoutUrl: string) => void; dismiss: () => void; invalidate: () => void; @@ -80,8 +79,8 @@ export function ShopifyCheckoutProvider({ // eslint-disable-next-line no-console console.warn( '[ShopifyCheckoutKit] Providing accessToken with contactFields (email / phoneNumber) is deprecated and will become an error in v4.' + - 'When the user is authenticated with Customer Accounts, provide accessToken' + - 'When the user is otherwise authenticated, provide email/phoneNumber.', + 'When the user is authenticated with Customer Accounts, provide accessToken' + + 'When the user is otherwise authenticated, provide email/phoneNumber.', ); } @@ -108,12 +107,6 @@ export function ShopifyCheckoutProvider({ } }, []); - const preload = useCallback((checkoutUrl: string) => { - if (checkoutUrl) { - instance.current?.preload(checkoutUrl); - } - }, []); - const invalidate = useCallback(() => { instance.current?.invalidate(); }, []); @@ -137,7 +130,6 @@ export function ShopifyCheckoutProvider({ dismiss, setConfig, getConfig, - preload, present, invalidate, removeEventListeners, @@ -150,7 +142,6 @@ export function ShopifyCheckoutProvider({ removeEventListeners, getConfig, setConfig, - preload, present, invalidate, ]); diff --git a/platforms/react-native/modules/@shopify/checkout-kit-react-native/src/index.d.ts b/platforms/react-native/modules/@shopify/checkout-kit-react-native/src/index.d.ts index 132d741a..7d0c38d4 100644 --- a/platforms/react-native/modules/@shopify/checkout-kit-react-native/src/index.d.ts +++ b/platforms/react-native/modules/@shopify/checkout-kit-react-native/src/index.d.ts @@ -305,11 +305,6 @@ export interface ShopifyCheckoutKit { * The version number of the Shopify Checkout SDK. */ readonly version: string; - /** - * Preload the checkout for faster presentation. - */ - preload(checkoutURL: string): void; - /** * Invalidate preload cache. */ diff --git a/platforms/react-native/modules/@shopify/checkout-kit-react-native/src/index.ts b/platforms/react-native/modules/@shopify/checkout-kit-react-native/src/index.ts index 4ecc9371..063909bf 100644 --- a/platforms/react-native/modules/@shopify/checkout-kit-react-native/src/index.ts +++ b/platforms/react-native/modules/@shopify/checkout-kit-react-native/src/index.ts @@ -54,7 +54,10 @@ import { import {CheckoutErrorCode} from './errors.d'; import type {CheckoutCompletedEvent} from './events.d'; import type {CustomEvent, PixelEvent, StandardEvent} from './pixels.d'; -import {ApplePayLabel, ApplePayStyle} from './components/AcceleratedCheckoutButtons'; +import { + ApplePayLabel, + ApplePayStyle, +} from './components/AcceleratedCheckoutButtons'; import type { AcceleratedCheckoutButtonsProps, RenderStateChangeEvent, @@ -133,14 +136,6 @@ class ShopifyCheckout implements ShopifyCheckoutKit { RNShopifyCheckoutKit.invalidateCache(); } - /** - * Preloads checkout for a given URL to improve performance - * @param checkoutUrl The URL of the checkout to preload - */ - public preload(checkoutUrl: string): void { - RNShopifyCheckoutKit.preload(checkoutUrl); - } - /** * Presents the checkout sheet for a given checkout URL * @param checkoutUrl The URL of the checkout to display diff --git a/platforms/react-native/modules/@shopify/checkout-kit-react-native/src/specs/NativeShopifyCheckoutKit.ts b/platforms/react-native/modules/@shopify/checkout-kit-react-native/src/specs/NativeShopifyCheckoutKit.ts index d217aa57..605c4831 100644 --- a/platforms/react-native/modules/@shopify/checkout-kit-react-native/src/specs/NativeShopifyCheckoutKit.ts +++ b/platforms/react-native/modules/@shopify/checkout-kit-react-native/src/specs/NativeShopifyCheckoutKit.ts @@ -73,7 +73,6 @@ type ConfigurationResultSpec = { export interface Spec extends TurboModule { present(checkoutUrl: string): void; - preload(checkoutUrl: string): void; dismiss(): void; invalidateCache(): void; setConfig(configuration: ConfigurationSpec): void; @@ -96,6 +95,4 @@ export interface Spec extends TurboModule { getConstants(): {version: string}; } -export default TurboModuleRegistry.getEnforcing( - 'ShopifyCheckoutKit', -); +export default TurboModuleRegistry.getEnforcing('ShopifyCheckoutKit'); diff --git a/platforms/react-native/modules/@shopify/checkout-kit-react-native/tests/context.test.tsx b/platforms/react-native/modules/@shopify/checkout-kit-react-native/tests/context.test.tsx index 8de11f4f..0462d21b 100644 --- a/platforms/react-native/modules/@shopify/checkout-kit-react-native/tests/context.test.tsx +++ b/platforms/react-native/modules/@shopify/checkout-kit-react-native/tests/context.test.tsx @@ -1,10 +1,7 @@ import React from 'react'; import {render, act} from '@testing-library/react-native'; import {NativeModules, Platform} from 'react-native'; -import { - ShopifyCheckoutProvider, - useShopifyCheckout, -} from '../src/context'; +import {ShopifyCheckoutProvider, useShopifyCheckout} from '../src/context'; import {ApplePayContactField, ColorScheme, type Configuration} from '../src'; const checkoutUrl = 'https://shopify.com/checkout'; @@ -54,9 +51,9 @@ describe('ShopifyCheckoutProvider', () => { , ); - expect( - NativeModules.ShopifyCheckoutKit.setConfig, - ).toHaveBeenCalledWith(config); + expect(NativeModules.ShopifyCheckoutKit.setConfig).toHaveBeenCalledWith( + config, + ); }); it('skips configuration when no configuration is provided', () => { @@ -66,9 +63,7 @@ describe('ShopifyCheckoutProvider', () => { , ); - expect( - NativeModules.ShopifyCheckoutKit.setConfig, - ).not.toHaveBeenCalled(); + expect(NativeModules.ShopifyCheckoutKit.setConfig).not.toHaveBeenCalled(); expect( NativeModules.ShopifyCheckoutKit.configureAcceleratedCheckouts, ).not.toHaveBeenCalled(); @@ -137,9 +132,9 @@ describe('ShopifyCheckoutProvider', () => { , ); - expect( - NativeModules.ShopifyCheckoutKit.setConfig.mock.calls, - ).toHaveLength(2); + expect(NativeModules.ShopifyCheckoutKit.setConfig.mock.calls).toHaveLength( + 2, + ); }); }); @@ -226,51 +221,7 @@ describe('useShopifyCheckout', () => { hookValue.present(''); }); - expect( - NativeModules.ShopifyCheckoutKit.present, - ).not.toHaveBeenCalled(); - }); - - it('provides preload function and calls it with checkoutUrl', () => { - let hookValue: any; - const onHookValue = (value: any) => { - hookValue = value; - }; - - render( - - - , - ); - - act(() => { - hookValue.preload(checkoutUrl); - }); - - expect(NativeModules.ShopifyCheckoutKit.preload).toHaveBeenCalledWith( - checkoutUrl, - ); - }); - - it('does not call preload with empty checkoutUrl', () => { - let hookValue: any; - const onHookValue = (value: any) => { - hookValue = value; - }; - - render( - - - , - ); - - act(() => { - hookValue.preload(''); - }); - - expect( - NativeModules.ShopifyCheckoutKit.preload, - ).not.toHaveBeenCalled(); + expect(NativeModules.ShopifyCheckoutKit.present).not.toHaveBeenCalled(); }); it('provides invalidate function', () => { @@ -289,9 +240,7 @@ describe('useShopifyCheckout', () => { hookValue.invalidate(); }); - expect( - NativeModules.ShopifyCheckoutKit.invalidateCache, - ).toHaveBeenCalled(); + expect(NativeModules.ShopifyCheckoutKit.invalidateCache).toHaveBeenCalled(); }); it('provides dismiss function', () => { @@ -331,9 +280,9 @@ describe('useShopifyCheckout', () => { hookValue.setConfig(newConfig); }); - expect( - NativeModules.ShopifyCheckoutKit.setConfig, - ).toHaveBeenCalledWith(newConfig); + expect(NativeModules.ShopifyCheckoutKit.setConfig).toHaveBeenCalledWith( + newConfig, + ); }); it('provides getConfig function', async () => { diff --git a/platforms/react-native/modules/@shopify/checkout-kit-react-native/tests/index.test.ts b/platforms/react-native/modules/@shopify/checkout-kit-react-native/tests/index.test.ts index b04722e6..b5635772 100644 --- a/platforms/react-native/modules/@shopify/checkout-kit-react-native/tests/index.test.ts +++ b/platforms/react-native/modules/@shopify/checkout-kit-react-native/tests/index.test.ts @@ -75,16 +75,12 @@ describe('ShopifyCheckoutKit', () => { describe('instantiation', () => { it('calls `setConfig` with the specified config on instantiation', () => { new ShopifyCheckout(config); - expect( - NativeModule.setConfig, - ).toHaveBeenCalledWith(config); + expect(NativeModule.setConfig).toHaveBeenCalledWith(config); }); it('does not call `setConfig` if no config was specified on instantiation', () => { new ShopifyCheckout(); - expect( - NativeModule.setConfig, - ).not.toHaveBeenCalled(); + expect(NativeModule.setConfig).not.toHaveBeenCalled(); }); }); @@ -92,12 +88,8 @@ describe('ShopifyCheckoutKit', () => { it('calls the `setConfig` on the Native Module', () => { const instance = new ShopifyCheckout(); instance.setConfig(config); - expect( - NativeModule.setConfig, - ).toHaveBeenCalledTimes(1); - expect( - NativeModule.setConfig, - ).toHaveBeenCalledWith(config); + expect(NativeModule.setConfig).toHaveBeenCalledTimes(1); + expect(NativeModule.setConfig).toHaveBeenCalledWith(config); }); it('calls `setConfig` with logLevel configuration', () => { @@ -107,22 +99,7 @@ describe('ShopifyCheckoutKit', () => { logLevel: LogLevel.debug, }; instance.setConfig(configWithLogLevel); - expect( - NativeModule.setConfig, - ).toHaveBeenCalledWith(configWithLogLevel); - }); - }); - - describe('preload', () => { - it('calls `preload` with a checkout URL', () => { - const instance = new ShopifyCheckout(); - instance.preload(checkoutUrl); - expect( - NativeModule.preload, - ).toHaveBeenCalledTimes(1); - expect( - NativeModule.preload, - ).toHaveBeenCalledWith(checkoutUrl); + expect(NativeModule.setConfig).toHaveBeenCalledWith(configWithLogLevel); }); }); @@ -130,9 +107,7 @@ describe('ShopifyCheckoutKit', () => { it('calls `invalidateCache`', () => { const instance = new ShopifyCheckout(); instance.invalidate(); - expect( - NativeModule.invalidateCache, - ).toHaveBeenCalledTimes(1); + expect(NativeModule.invalidateCache).toHaveBeenCalledTimes(1); }); }); @@ -140,12 +115,8 @@ describe('ShopifyCheckoutKit', () => { it('calls `present` with a checkout URL', () => { const instance = new ShopifyCheckout(); instance.present(checkoutUrl); - expect( - NativeModule.present, - ).toHaveBeenCalledTimes(1); - expect( - NativeModule.present, - ).toHaveBeenCalledWith(checkoutUrl); + expect(NativeModule.present).toHaveBeenCalledTimes(1); + expect(NativeModule.present).toHaveBeenCalledWith(checkoutUrl); }); }); @@ -153,9 +124,7 @@ describe('ShopifyCheckoutKit', () => { it('calls `dismiss`', () => { const instance = new ShopifyCheckout(); instance.dismiss(); - expect( - NativeModule.dismiss, - ).toHaveBeenCalledTimes(1); + expect(NativeModule.dismiss).toHaveBeenCalledTimes(1); }); }); @@ -167,9 +136,7 @@ describe('ShopifyCheckoutKit', () => { colorScheme: ColorScheme.automatic, logLevel: LogLevel.error, }); - expect( - NativeModule.getConfig, - ).toHaveBeenCalledTimes(1); + expect(NativeModule.getConfig).toHaveBeenCalledTimes(1); }); }); @@ -191,10 +158,7 @@ describe('ShopifyCheckoutKit', () => { const eventName = 'pixel'; const callback = jest.fn(); instance.addEventListener(eventName, callback); - NativeModule.addEventListener( - eventName, - callback, - ); + NativeModule.addEventListener(eventName, callback); expect(eventEmitter.addListener).toHaveBeenCalledWith( 'pixel', expect.any(Function), @@ -214,10 +178,7 @@ describe('ShopifyCheckoutKit', () => { const eventName = 'pixel'; const callback = jest.fn(); instance.addEventListener(eventName, callback); - NativeModule.addEventListener( - eventName, - callback, - ); + NativeModule.addEventListener(eventName, callback); expect(eventEmitter.addListener).toHaveBeenCalledWith( 'pixel', expect.any(Function), @@ -242,10 +203,7 @@ describe('ShopifyCheckoutKit', () => { const eventName = 'pixel'; const callback = jest.fn(); instance.addEventListener(eventName, callback); - NativeModule.addEventListener( - eventName, - callback, - ); + NativeModule.addEventListener(eventName, callback); expect(eventEmitter.addListener).toHaveBeenCalledWith( 'pixel', expect.any(Function), @@ -271,10 +229,7 @@ describe('ShopifyCheckoutKit', () => { const eventName = 'pixel'; const callback = jest.fn(); instance.addEventListener(eventName, callback); - NativeModule.addEventListener( - eventName, - callback, - ); + NativeModule.addEventListener(eventName, callback); expect(eventEmitter.addListener).toHaveBeenCalledWith( 'pixel', expect.any(Function), @@ -295,10 +250,7 @@ describe('ShopifyCheckoutKit', () => { throw new Error('Callback error'); }); instance.addEventListener(eventName, callback); - NativeModule.addEventListener( - eventName, - callback, - ); + NativeModule.addEventListener(eventName, callback); expect(eventEmitter.addListener).toHaveBeenCalledWith( 'pixel', expect.any(Function), @@ -325,10 +277,7 @@ describe('ShopifyCheckoutKit', () => { const eventName = 'completed'; const callback = jest.fn(); instance.addEventListener(eventName, callback); - NativeModule.addEventListener( - eventName, - callback, - ); + NativeModule.addEventListener(eventName, callback); expect(eventEmitter.addListener).toHaveBeenCalledWith( 'completed', expect.any(Function), @@ -345,10 +294,7 @@ describe('ShopifyCheckoutKit', () => { const eventName = 'completed'; const callback = jest.fn(); instance.addEventListener(eventName, callback); - NativeModule.addEventListener( - eventName, - callback, - ); + NativeModule.addEventListener(eventName, callback); expect(eventEmitter.addListener).toHaveBeenCalledWith( 'completed', expect.any(Function), @@ -363,10 +309,7 @@ describe('ShopifyCheckoutKit', () => { const eventName = 'completed'; const callback = jest.fn(); instance.addEventListener(eventName, callback); - NativeModule.addEventListener( - eventName, - callback, - ); + NativeModule.addEventListener(eventName, callback); expect(eventEmitter.addListener).toHaveBeenCalledWith( 'completed', expect.any(Function), @@ -436,10 +379,7 @@ describe('ShopifyCheckoutKit', () => { const eventName = 'error'; const callback = jest.fn(); instance.addEventListener(eventName, callback); - NativeModule.addEventListener( - eventName, - callback, - ); + NativeModule.addEventListener(eventName, callback); expect(eventEmitter.addListener).toHaveBeenCalledWith( 'error', expect.any(Function), @@ -459,10 +399,7 @@ describe('ShopifyCheckoutKit', () => { const eventName = 'error'; const callback = jest.fn(); instance.addEventListener(eventName, callback); - NativeModule.addEventListener( - eventName, - callback, - ); + NativeModule.addEventListener(eventName, callback); const error = { __typename: 'UnknownError', message: 'Something went wrong', @@ -552,9 +489,9 @@ describe('ShopifyCheckoutKit', () => { 'android.permission.ACCESS_COARSE_LOCATION', 'android.permission.ACCESS_FINE_LOCATION', ]); - expect( - NativeModule.initiateGeolocationRequest, - ).toHaveBeenCalledWith(true); + expect(NativeModule.initiateGeolocationRequest).toHaveBeenCalledWith( + true, + ); }); it('handles geolocation permission denial correctly', async () => { @@ -577,9 +514,9 @@ describe('ShopifyCheckoutKit', () => { 'android.permission.ACCESS_COARSE_LOCATION', 'android.permission.ACCESS_FINE_LOCATION', ]); - expect( - NativeModule.initiateGeolocationRequest, - ).toHaveBeenCalledWith(false); + expect(NativeModule.initiateGeolocationRequest).toHaveBeenCalledWith( + false, + ); }); it('cleans up geolocation callback on teardown', () => { @@ -622,9 +559,7 @@ describe('ShopifyCheckoutKit', () => { await emitGeolocationRequest(); - expect( - NativeModule.initiateGeolocationRequest, - ).not.toHaveBeenCalled(); + expect(NativeModule.initiateGeolocationRequest).not.toHaveBeenCalled(); }); it('tears down gracefully', () => { @@ -735,9 +670,7 @@ describe('ShopifyCheckoutKit', () => { instance.configureAcceleratedCheckouts(acceleratedConfig); expect(result).toBe(true); - expect( - NativeModule.configureAcceleratedCheckouts, - ).toHaveBeenCalledWith( + expect(NativeModule.configureAcceleratedCheckouts).toHaveBeenCalledWith( 'test-shop.myshopify.com', 'shpat_test_token', 'test@example.com', @@ -759,9 +692,7 @@ describe('ShopifyCheckoutKit', () => { instance.configureAcceleratedCheckouts(minimalConfig); - expect( - NativeModule.configureAcceleratedCheckouts, - ).toHaveBeenCalledWith( + expect(NativeModule.configureAcceleratedCheckouts).toHaveBeenCalledWith( 'test-shop.myshopify.com', 'shpat_test_token', null, @@ -794,9 +725,9 @@ describe('ShopifyCheckoutKit', () => { }; const expectedError = new Error('`storefrontDomain` is required'); - expect( - instance.configureAcceleratedCheckouts(invalidConfig), - ).toBe(false); + expect(instance.configureAcceleratedCheckouts(invalidConfig)).toBe( + false, + ); expect(console.error).toHaveBeenCalledWith( '[ShopifyCheckoutKit] Failed to configure accelerated checkouts with', expectedError, @@ -812,9 +743,9 @@ describe('ShopifyCheckoutKit', () => { const expectedError = new Error('`storefrontAccessToken` is required'); - expect( - instance.configureAcceleratedCheckouts(invalidConfig), - ).toBe(false); + expect(instance.configureAcceleratedCheckouts(invalidConfig)).toBe( + false, + ); expect(console.error).toHaveBeenCalledWith( '[ShopifyCheckoutKit] Failed to configure accelerated checkouts with', expectedError, @@ -837,9 +768,9 @@ describe('ShopifyCheckoutKit', () => { '`wallets.applePay.merchantIdentifier` is required', ); - expect( - instance.configureAcceleratedCheckouts(invalidConfig), - ).toBe(false); + expect(instance.configureAcceleratedCheckouts(invalidConfig)).toBe( + false, + ); expect(console.error).toHaveBeenCalledWith( '[ShopifyCheckoutKit] Failed to configure accelerated checkouts with', expectedError, @@ -923,9 +854,7 @@ describe('ShopifyCheckoutKit', () => { }, }); - expect( - NativeModule.configureAcceleratedCheckouts, - ).toHaveBeenCalledWith( + expect(NativeModule.configureAcceleratedCheckouts).toHaveBeenCalledWith( 'test-shop.myshopify.com', 'shpat_test_token', 'test@example.com', @@ -951,9 +880,7 @@ describe('ShopifyCheckoutKit', () => { }, }); - expect( - NativeModule.configureAcceleratedCheckouts, - ).toHaveBeenCalledWith( + expect(NativeModule.configureAcceleratedCheckouts).toHaveBeenCalledWith( 'test-shop.myshopify.com', 'shpat_test_token', 'test@example.com', diff --git a/platforms/react-native/sample/android/app/src/test/java/com/shopify/checkoutkitreactnative/ShopifyCheckoutKitModuleTest.java b/platforms/react-native/sample/android/app/src/test/java/com/shopify/checkoutkitreactnative/ShopifyCheckoutKitModuleTest.java index e1456698..772db9df 100644 --- a/platforms/react-native/sample/android/app/src/test/java/com/shopify/checkoutkitreactnative/ShopifyCheckoutKitModuleTest.java +++ b/platforms/react-native/sample/android/app/src/test/java/com/shopify/checkoutkitreactnative/ShopifyCheckoutKitModuleTest.java @@ -138,19 +138,6 @@ public void testCanPresentCheckout() { } } - @Test - public void testCanPreloadCheckout() { - try (MockedStatic mockedShopifyCheckoutKit = Mockito - .mockStatic(ShopifyCheckoutSheetKit.class)) { - String checkoutUrl = "https://shopify.com"; - shopifyCheckoutKitModule.preload(checkoutUrl); - - mockedShopifyCheckoutKit.verify(() -> { - ShopifyCheckoutSheetKit.preload(eq(checkoutUrl), any()); - }); - } - } - /** * Module name and version */ diff --git a/platforms/react-native/sample/src/context/Cart.tsx b/platforms/react-native/sample/src/context/Cart.tsx index bdf6990c..9b1c13af 100644 --- a/platforms/react-native/sample/src/context/Cart.tsx +++ b/platforms/react-native/sample/src/context/Cart.tsx @@ -118,17 +118,9 @@ export const CartProvider: React.FC = ({children}) => { } }, [cartId, fetchCart, setTotalQuantity]); - const preloadCheckout = useCallback( - (checkoutURL: string) => { - if (checkoutURL) { - const config = shopify.getConfig(); - if (config?.preloading) { - shopify.preload(checkoutURL); - } - } - }, - [shopify], - ); + const preloadCheckout = useCallback((_checkoutURL: string) => { + // Public preload support is coming soon. + }, []); const addToCart = useCallback( async (variantId: string) => { @@ -151,11 +143,8 @@ export const CartProvider: React.FC = ({children}) => { if (!id) { let customerAccessToken: string | undefined; - if ( - appConfig.buyerIdentityMode === BuyerIdentityMode.CustomerAccount - ) { - customerAccessToken = - (await getValidAccessToken()) ?? undefined; + if (appConfig.buyerIdentityMode === BuyerIdentityMode.CustomerAccount) { + customerAccessToken = (await getValidAccessToken()) ?? undefined; } const cartInput = createBuyerIdentityCartInput( appConfig,