feat: fix headerHtml script not running bug (#2749)

* fix: fix custom head not exec <script> tag

* fix: fix create element bug
This commit is contained in:
DacongDA 2024-02-26 20:21:07 +08:00 committed by GitHub
parent e4cf244cf8
commit 6a813a1f8c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -23,8 +23,21 @@ function CustomHead(props) {
node.innerHTML = props.headerHtml;
node.childNodes.forEach(el => {
el.setAttribute("app-custom-head" + suffix, "");
document.head.appendChild(el);
if (el.nodeName === "#text") {
return;
}
let innerNode = el;
innerNode.setAttribute("app-custom-head" + suffix, "");
if (innerNode.localName === "script") {
const scriptNode = document.createElement("script");
Array.from(innerNode.attributes).forEach(attr => {
scriptNode.setAttribute(attr.name, attr.value);
});
scriptNode.text = innerNode.textContent;
innerNode = scriptNode;
}
document.head.appendChild(innerNode);
});
return () => {