fix: fix duplicated load bug of custom JS (#2771)

This commit is contained in:
DacongDA 2024-03-05 00:09:37 +08:00 committed by GitHub
parent 19942a8bd4
commit 11dbd5ba9a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -16,6 +16,7 @@ import {useEffect} from "react";
function CustomHead(props) {
useEffect(() => {
if (!sessionStorage.getItem("customHead")) {
const suffix = new Date().getTime().toString();
if (!props.headerHtml) {return;}
@ -39,14 +40,8 @@ function CustomHead(props) {
}
document.head.appendChild(innerNode);
});
return () => {
for (const el of document.head.children) {
if (el.getAttribute("app-custom-head" + suffix) !== null) {
document.head.removeChild(el);
sessionStorage.setItem("customHead", "true");
}
}
};
});
}