Skip to content

Commit

Permalink
flag for checking if preload is called at least once. Else do not cac…
Browse files Browse the repository at this point in the history
…he checkout
  • Loading branch information
cianbuckley committed Oct 12, 2023
1 parent 49731e8 commit ea20e16
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/ShopifyCheckout/CheckoutView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
1 change: 1 addition & 0 deletions Sources/ShopifyCheckout/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,6 @@ extension Configuration {
extension Configuration {
public struct Preloading {
public var enabled: Bool = false
internal var preloadCalledAtLeastOnce: Bool = false
}
}
1 change: 1 addition & 0 deletions Sources/ShopifyCheckout/ShopifyCheckout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit ea20e16

Please sign in to comment.