Skip to content

Commit

Permalink
perf: don't load duplicate styles for link tags with matching hrefs
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvxd committed Apr 16, 2024
1 parent d298f1b commit ad6452f
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/AutoFrameComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,21 @@ const CopyHostStyles = ({
const parentDocument = win!.parent.document;

const collectedStyles = collectStyles(parentDocument);
const hrefs: string[] = [];

Promise.all(
collectedStyles.map(async (styleNode) => {
collectedStyles.map(async (styleNode, i) => {
if (styleNode.nodeName === "LINK") {
const linkHref = (styleNode as HTMLLinkElement).href;

// Don't process link elements with identical hrefs more than once
if (hrefs.indexOf(linkHref) > -1) {
return;
}

hrefs.push(linkHref);
}

const mirror = await mirrorEl(styleNode);

if (!mirror) return;
Expand Down

0 comments on commit ad6452f

Please sign in to comment.