Revert "Guarantee execution order of <script> elements (#1574)"

This reverts commit 36e20fd110.

Reverting until this can be investigated:

36e20fd110 (commitcomment-62861929)
This commit is contained in:
Damien Elmes 2022-01-04 10:43:56 +10:00
parent 36e20fd110
commit 349d5d0862

View file

@ -59,16 +59,7 @@ export function _queueAction(action: Callback): void {
_updatingQueue = _updatingQueue.then(action); _updatingQueue = _updatingQueue.then(action);
} }
function replaceScriptPromise(script: HTMLScriptElement): Promise<void> { function setInnerHTML(element: Element, html: string): void {
return new Promise((resolve) => {
const newScript = script.cloneNode(true);
newScript.addEventListener("load", () => resolve());
newScript.addEventListener("error", () => resolve());
script.replaceWith(newScript);
});
}
async function setInnerHTML(element: Element, html: string): Promise<void> {
for (const oldVideo of element.getElementsByTagName("video")) { for (const oldVideo of element.getElementsByTagName("video")) {
oldVideo.pause(); oldVideo.pause();
@ -82,11 +73,14 @@ async function setInnerHTML(element: Element, html: string): Promise<void> {
element.innerHTML = html; element.innerHTML = html;
for (const oldScript of element.getElementsByTagName("script")) { for (const oldScript of element.getElementsByTagName("script")) {
if (oldScript.src) { const newScript = document.createElement("script");
await replaceScriptPromise(oldScript);
} else { for (const attribute of oldScript.attributes) {
oldScript.replaceWith(oldScript.cloneNode(true)); newScript.setAttribute(attribute.name, attribute.value);
} }
newScript.appendChild(document.createTextNode(oldScript.innerHTML));
oldScript.parentNode!.replaceChild(newScript, oldScript);
} }
} }