Bfcache Chrome - Cart cleanup issue

Hi! First time here :slight_smile:

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);
    }
  }
});

Hey,

If you try with a different theme (eg: fresh version of Dawn), does this still happen?

Hi! , yes the problem is the same in different themes and stores

Could you make a short video recording of this? I’m unable to replicate this on my test store.