diff --git a/Sources/ShopifyCheckout/CheckoutView.swift b/Sources/ShopifyCheckout/CheckoutView.swift index e17a153f..12fb0dc9 100644 --- a/Sources/ShopifyCheckout/CheckoutView.swift +++ b/Sources/ShopifyCheckout/CheckoutView.swift @@ -37,7 +37,7 @@ class CheckoutView: WKWebView { private static var cache: CacheEntry? static func `for`(checkout url: URL) -> CheckoutView { - guard ShopifyCheckout.configuration.preloading.enabled else { + guard ShopifyCheckout.configuration.preloading.enabled && ShopifyCheckout.configuration.preloading.preloadCalledAtLeastOnce else { CheckoutView.cache = nil return CheckoutView() } diff --git a/Sources/ShopifyCheckout/Configuration.swift b/Sources/ShopifyCheckout/Configuration.swift index 4941d790..9192140d 100644 --- a/Sources/ShopifyCheckout/Configuration.swift +++ b/Sources/ShopifyCheckout/Configuration.swift @@ -67,5 +67,6 @@ extension Configuration { extension Configuration { public struct Preloading { public var enabled: Bool = false + internal var preloadCalledAtLeastOnce: Bool = false } } diff --git a/Sources/ShopifyCheckout/ShopifyCheckout.swift b/Sources/ShopifyCheckout/ShopifyCheckout.swift index 5c139ff9..3240434a 100644 --- a/Sources/ShopifyCheckout/ShopifyCheckout.swift +++ b/Sources/ShopifyCheckout/ShopifyCheckout.swift @@ -40,6 +40,7 @@ public func configure(_ block: (inout Configuration) -> Void) { /// Preloads the checkout for faster presentation. public func preload(checkout url: URL) { + ShopifyCheckout.configuration.preloading.preloadCalledAtLeastOnce = true guard configuration.preloading.enabled else { return } CheckoutView.for(checkout: url).load(checkout: url) }