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) await addViteStyleTarget(shadowRoot)
} else { } else {
cssPaths.forEach((cssPath: string) => { const fragment = document.createDocumentFragment()
const styleEl = document.createElement("link") await Promise.all(
styleEl.setAttribute("rel", "stylesheet") cssPaths.map((cssPath: string) => {
styleEl.setAttribute("href", browser.runtime.getURL(cssPath)) return new Promise((resolve, reject) => {
shadowRoot.appendChild(styleEl) const styleEl = document.createElement("link")
}) styleEl.setAttribute("rel", "stylesheet")
styleEl.setAttribute("href", browser.runtime.getURL(cssPath))
styleEl.onload = resolve
styleEl.onerror = reject
fragment.appendChild(styleEl)
})
})
)
shadowRoot.appendChild(fragment)
} }
shadowRoot.appendChild(appRoot) shadowRoot.appendChild(appRoot)