Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Fixed handling of lazy loaded frames on Safari, mainly the cart pane … (#13110)

Damian Legawiec86ddf0b3e599
diff --git a/storefront/app/helpers/spree/cart_helper.rb b/storefront/app/helpers/spree/cart_helper.rb
index c1795d48e4..8712d6a30c 100644
--- a/storefront/app/helpers/spree/cart_helper.rb
+++ b/storefront/app/helpers/spree/cart_helper.rb
@@ -48,7 +48,7 @@ module Spree
def cart_id(order)
return 'cart_contents' if order.blank? || order.id.blank? || order.updated_at.blank?
- "cart_contents_#{order.id}_#{order.updated_at.to_i}"
+ "cart_contents_#{order.id}"
end
end
end
diff --git a/storefront/app/javascript/spree/storefront/application.js b/storefront/app/javascript/spree/storefront/application.js
index 41633a22e6..555c6e92ec 100644
--- a/storefront/app/javascript/spree/storefront/application.js
+++ b/storefront/app/javascript/spree/storefront/application.js
@@ -140,6 +140,14 @@ document.addEventListener('turbo:submit-end', () => {
Turbo.navigator.delegate.adapter.progressBar.hide()
})
+// fix for Safari buggy behavior with lazy loaded turbo frames
+document.addEventListener("turbo:before-fetch-request", (event) => {
+ const frame = event.target.closest("turbo-frame");
+ if (frame && frame.id) {
+ event.detail.fetchOptions.headers["Turbo-Frame"] = frame.id;
+ }
+});
+
function replaceCsrfMetaTags() {
const csrfMetaTagsTemplate = document.querySelector('template#csrf_meta_tags')
if (!csrfMetaTagsTemplate) return
diff --git a/storefront/app/views/themes/default/spree/shared/_cart_pane.html.erb b/storefront/app/views/themes/default/spree/shared/_cart_pane.html.erb
index a440e27944..e305e13977 100644
--- a/storefront/app/views/themes/default/spree/shared/_cart_pane.html.erb
+++ b/storefront/app/views/themes/default/spree/shared/_cart_pane.html.erb
@@ -33,8 +33,8 @@
<span class='sr-only'><%= Spree.t('storefront.cart.items_in_cart') %>, <%= Spree.t('storefront.cart.view_bag') %></span>
</span>
</div>
- <div class='flex-1 h-0 overflow-y-auto'>
- <%= turbo_frame_tag cart_id(order), class: 'cart-contents', src: spree.cart_path, data: { turbo_permanent: true }, loading: :lazy %>
+ <div class='flex-1 h-0 overflow-y-auto' id="cart-pane-container" data-turbo-permanent>
+ <%= turbo_frame_tag cart_id(order), class: 'cart-contents', src: spree.cart_path, loading: :lazy %>
</div>
</div>
</div>