diff --git a/assets/global.js b/assets/global.js index b4b3f82b16d..0fc7a7c24ad 100644 --- a/assets/global.js +++ b/assets/global.js @@ -840,10 +840,14 @@ class VariantSelects extends HTMLElement { } renderProductInfo() { + const requestedVariantId = this.currentVariant.id; const activeElementId = document.activeElement.id; - fetch(`${this.dataset.url}?variant=${this.currentVariant.id}§ion_id=${this.dataset.originalSection ? this.dataset.originalSection : this.dataset.section}`) + fetch(`${this.dataset.url}?variant=${requestedVariantId}§ion_id=${this.dataset.originalSection ? this.dataset.originalSection : this.dataset.section}`) .then((response) => response.text()) .then((responseText) => { + // prevent unnecessary ui changes from abandoned selections + if (this.currentVariant.id !== requestedVariantId) return; + const html = new DOMParser().parseFromString(responseText, 'text/html') const destination = document.getElementById(`price-${this.dataset.section}`); const source = html.getElementById(`price-${this.dataset.originalSection ? this.dataset.originalSection : this.dataset.section}`); @@ -857,7 +861,7 @@ class VariantSelects extends HTMLElement { if (price) price.classList.remove('visibility-hidden'); this.toggleAddButton(!this.currentVariant.available, window.variantStrings.soldOut); - + document.querySelector('variant-radios') ? this.querySelector(`[for="${activeElementId}"]`).focus() : this.querySelector(`#${activeElementId}`).focus(); }); }