Made renderContent faster

This commit is contained in:
Lalle 2023-05-15 23:29:42 +02:00
parent 4d0253b0dd
commit 4b2b5b59af
No known key found for this signature in database
GPG Key ID: A6583D207A8F6B0D

View File

@ -17,12 +17,20 @@ export default async function renderContent(
await addViteStyleTarget(shadowRoot)
} else {
cssPaths.forEach((cssPath: string) => {
const fragment = document.createDocumentFragment()
await Promise.all(
cssPaths.map((cssPath: string) => {
return new Promise((resolve, reject) => {
const styleEl = document.createElement("link")
styleEl.setAttribute("rel", "stylesheet")
styleEl.setAttribute("href", browser.runtime.getURL(cssPath))
shadowRoot.appendChild(styleEl)
styleEl.onload = resolve
styleEl.onerror = reject
fragment.appendChild(styleEl)
})
})
)
shadowRoot.appendChild(fragment)
}
shadowRoot.appendChild(appRoot)