Skip to content

Commit

Permalink
Prevent ui changes from variant selection queues (#2030)
Browse files Browse the repository at this point in the history
  • Loading branch information
kmeleta committed Oct 18, 2022
1 parent 6a9a631 commit 147c21e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions assets/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}&section_id=${this.dataset.originalSection ? this.dataset.originalSection : this.dataset.section}`)
fetch(`${this.dataset.url}?variant=${requestedVariantId}&section_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}`);
Expand All @@ -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();
});
}
Expand Down

0 comments on commit 147c21e

Please sign in to comment.