Skip to content

Commit

Permalink
Dedupe IDs prior to injecting the new content
Browse files Browse the repository at this point in the history
  • Loading branch information
lhoffbeck committed May 30, 2024
1 parent 1f5fff2 commit eca1902
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions assets/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ class HTMLUpdateUtility {
const newNodeWrapper = document.createElement('div');
HTMLUpdateUtility.setInnerHTML(newNodeWrapper, newContent.outerHTML);
const newNode = newNodeWrapper.firstChild;
oldNode.parentNode.insertBefore(newNode, oldNode);
oldNode.style.display = 'none';

// dedupe IDs
const uniqueKey = Date.now();
Expand All @@ -61,6 +59,9 @@ class HTMLUpdateUtility {
element.form && element.setAttribute('form', `${element.form.getAttribute('id')}-${uniqueKey}`);
});

oldNode.parentNode.insertBefore(newNode, oldNode);
oldNode.style.display = 'none';

this.#postProcessCallbacks.forEach((callback) => callback(newNode));

setTimeout(() => oldNode.remove(), 500);
Expand Down

0 comments on commit eca1902

Please sign in to comment.