Hi! First time here
I’m dealing with a weird issue with a store.
When a customer adds a product to the cart, and goes back to the collection the item is removed.
I fixed that for Safari cache, on the pageshow event, but is not working for Chrome, and is only on the Desktop.
Any idea? or anyone with the same problem?
Reference: Back/forward cache | Articles | web.dev
Thanks!
Safar fix.
window.addEventListener("pageshow", async (event) => {
if (event.persisted) {
const cartData = await fetch(`/cart.js`).then((res) => res.json());
const section = await fetch(
window.Shopify.routes.root + "?sections=ajax-cart"
).then((res) => res.json());
cartData.sections = section;
if (cartData) {
updateAllCartData(cartData, "ajaxCart", true);
}
}
});