Choosing a selection results in a full page refresh.
Opens in a new window.
/**
* BFCache and Popstate Handler Script
*
* This script automatically detects when:
* 1. A page is restored from bfcache (pageshow event)
* 2. Browser navigation occurs via back/forward buttons (popstate event)
*
* Actions taken:
* 1. Checks for open cart drawers that should be closed or if user is on cart page
* 2. Refreshes the page to reactivate the Route scripts
*
*/
(function() {
// Prevent multiple event listeners from being added if script runs multiple times
if (window.bfcacheHandlerAdded) return;
window.bfcacheHandlerAdded = true;
// Checks if page cleanup is needed and refreshes if necessary
function checkAndCleanupIfNeeded() {
// Ensure the "openDrawers" CSS selector meets the criteria above
const openDrawers = document.querySelectorAll('cart-drawer[open]');
const isCartPage = window.location.pathname.endsWith('/cart');
if (openDrawers.length > 0 || isCartPage) {
window.location.reload();
}
}
// Fires when navigating through browser history (back/forward buttons)
window.addEventListener('pageshow', (e) => {
// e.persisted = true means page was restored from browser cache
if (e.persisted) {
checkAndCleanupIfNeeded();
}
});
/**
* Extra fallback: some browsers don't set `persisted`
* CAUTION
* Some themes will trigger a popstate when CWC is clicked which will cause CWC
* to simply refresh the page and not redirect to checkout
* If this happens, simply remove the following event listener
*/
window.addEventListener('popstate', (e) => {
// Small delay to allow DOM to update after navigation
setTimeout(() => {
checkAndCleanupIfNeeded();
}, 100);
});
})();