Skip to content

Commit

Permalink
Fix(Runtime): Pregenerated <style> should not removed on destroy
Browse files Browse the repository at this point in the history
  • Loading branch information
BenSeage committed Feb 2, 2024
1 parent 37cfe68 commit 790934b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/runtime/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import './types/global'
export class RuntimeCSS extends MasterCSS {
readonly host: Element
readonly observing = false
readonly progressive = false
readonly container: HTMLElement | ShadowRoot
observer?: MutationObserver | null
constructor(
Expand Down Expand Up @@ -43,6 +44,8 @@ export class RuntimeCSS extends MasterCSS {
if (ownerNode && (ownerNode as HTMLStyleElement).id === 'master') {
// @ts-ignore
this.style = ownerNode
// @ts-ignore
this.progressive = true
break
}
}
Expand Down Expand Up @@ -391,9 +394,11 @@ export class RuntimeCSS extends MasterCSS {
sheet.deleteRule(i)
}
}
this.style?.remove()
// @ts-ignore
this.style = null
if (!this.progressive) {
this.style?.remove()
// @ts-ignore
this.style = null
}
return this
}

Expand Down
11 changes: 11 additions & 0 deletions packages/runtime/tests/progressive.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import initCSSRuntime from '../src/init-css-runtime'

test('progressive', () => {
const style = document.createElement('style')
style.id = 'master'
document.head.append(style)

const runtimeCSS = initCSSRuntime()
runtimeCSS.destroy()
expect(document.head.contains(style)).toBeTruthy()
})

0 comments on commit 790934b

Please sign in to comment.