Skip to content

Commit

Permalink
fix: stylesheet loading
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminrobinet committed Nov 13, 2024
1 parent bc2e7cd commit 16cc938
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/mergeHeadContents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,19 @@ export default function mergeHeadContents(
.forEach(({ el }) => currentHead.removeChild(el));

// Insert tag *after* previous version of itself to preserve JS variable scope and CSS cascade
addTags
.filter(({ el }) => shouldManageTag(el))
.forEach(({ el, index = 0 }) => {
currentHead.insertBefore(el.cloneNode(true), currentHead.children[index + 1] || null);
});
const newAddTags = addTags
.filter(({ el }) => shouldManageTag(el))
.map((tag) => {
let newEl = tag.el.cloneNode(true) as Element;
currentHead.insertBefore(newEl, currentHead.children[(tag.index || 0) + 1] || null);

return { ...tag, el: newEl };
});


return {
removed: removeTags.map(({ el }) => el),
added: addTags.map(({ el }) => el)
added: newAddTags.map(({ el }) => el)
};
}

Expand Down

0 comments on commit 16cc938

Please sign in to comment.