Skip to content

Commit ede66d6

Browse files
committed
fix(beasties): remove preload links when pruning source
1 parent d778943 commit ede66d6

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

packages/beasties/src/index.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,7 @@ export default class Beasties {
184184
}
185185

186186
checkInlineThreshold(link: Node, style: Node, sheet: string) {
187-
if (
188-
this.options.inlineThreshold
189-
&& sheet.length < this.options.inlineThreshold
190-
) {
187+
if (this.options.inlineThreshold && sheet.length < this.options.inlineThreshold) {
191188
const href = style.$$name
192189
style.$$reduce = false
193190
this.logger.info?.(
@@ -329,6 +326,7 @@ export default class Beasties {
329326
bodyLink.removeAttribute('id')
330327

331328
document.body.appendChild(bodyLink)
329+
style.$$links.push(bodyLink)
332330
updateLinkToPreload = true
333331
}
334332
}
@@ -361,24 +359,24 @@ export default class Beasties {
361359
// if external stylesheet would be below minimum size, just inline everything
362360
const minSize = this.options.minimumExternalSize
363361
const name = style.$$name
364-
if (minSize && sheetInverse.length < minSize) {
362+
const shouldInline = minSize && sheetInverse.length < minSize
363+
if (shouldInline) {
365364
this.logger.info?.(
366365
`\u001B[32mInlined all of ${name} (non-critical external stylesheet would have been ${sheetInverse.length}b, which was below the threshold of ${minSize})\u001B[39m`,
367366
)
367+
}
368+
if (shouldInline || !sheetInverse) {
368369
style.textContent = before
369370
// remove any associated external resources/loaders:
370371
if (style.$$links) {
371372
for (const link of style.$$links) {
372373
const parent = link.parentNode
373-
if (parent)
374-
parent.removeChild(link)
374+
parent?.removeChild(link)
375375
}
376376
}
377-
378-
return true
379377
}
380378

381-
return false
379+
return !!shouldInline
382380
}
383381

384382
/**

0 commit comments

Comments
 (0)