Skip to content

Commit

Permalink
Merge pull request #288 from django-stars/next-generation-upgrade
Browse files Browse the repository at this point in the history
fix insert option in style-loader
  • Loading branch information
legendar authored Nov 22, 2024
2 parents 5b3f934 + d7e2059 commit f5964d6
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion presets/styles.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default function(config) {
match(['*node_modules*.css'], [
css({
styleLoader: {
insertAt: 'top',
insert: insertAtTop,
},
}),
]),
Expand Down Expand Up @@ -40,3 +40,18 @@ export default function(config) {
]),
])
}

function insertAtTop(element) {
const parent = document.querySelector('head')
const lastInsertedElement = window._lastElementInsertedByStyleLoader

if(!lastInsertedElement) {
parent.insertBefore(element, parent.firstChild)
} else if(lastInsertedElement.nextSibling) {
parent.insertBefore(element, lastInsertedElement.nextSibling)
} else {
parent.appendChild(element)
}

window._lastElementInsertedByStyleLoader = element
}

0 comments on commit f5964d6

Please sign in to comment.