Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
fix: styles not working as expected in plugin (#322)
Browse files Browse the repository at this point in the history
* fix link elements not being in head

* Revert script code

* Remove unused code, reorder functions

* updates based on review

* update based on review
  • Loading branch information
KaWaite authored and rot1024 committed Oct 3, 2022
1 parent 747dac6 commit 21329d8
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/components/atoms/Plugin/IFrame/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ export default function useHook({

doc.body.innerHTML = html;

linksToHead(doc, doc.body.querySelectorAll("link"));

const onScriptsLoaded = () => {
// post pending messages
if (pendingMesages.current.length) {
Expand Down Expand Up @@ -228,3 +230,17 @@ function runScript(oldScript: HTMLScriptElement) {
}
});
}

function linksToHead(doc: Document, links: NodeListOf<HTMLLinkElement>) {
for (const link of links) {
const newLink = document.createElement("link");
for (const attr of link.attributes) {
newLink.setAttribute(attr.name, attr.value);
}
if (link.innerText) {
newLink.appendChild(document.createTextNode(link.innerText));
}
doc.head.appendChild(newLink);
doc.body.removeChild(link);
}
}

0 comments on commit 21329d8

Please sign in to comment.