Clean up dynamically inserted assets when template is unmounted #274

This commit is contained in:
garronej
2023-04-19 03:20:22 +02:00
parent 2bf3296c0f
commit cf1e595ba2
3 changed files with 45 additions and 22 deletions

View File

@ -22,17 +22,24 @@ export default function LoginOtp(props: PageProps<Extract<KcContext, { pageId: "
useEffect(() => {
let isCleanedUp = false;
headInsert({
const { prLoaded, remove } = headInsert({
"type": "javascript",
"src": pathJoin(kcContext.url.resourcesCommonPath, "node_modules/jquery/dist/jquery.min.js")
}).then(() => {
if (isCleanedUp) return;
});
(async () => {
await prLoaded;
if (isCleanedUp) {
return;
}
evaluateInlineScript();
});
})();
return () => {
isCleanedUp = true;
remove();
};
}, []);