Skip to content

Commit a03dcca

Browse files
committed
chore: tweaks
1 parent c953666 commit a03dcca

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

packages/runtime-dom/__tests__/customElement.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -799,13 +799,13 @@ describe('defineCustomElement', () => {
799799
return 'bar'
800800
},
801801
})
802-
const WarpperBar = defineComponent({
802+
const WrapperBar = defineComponent({
803803
styles: [`div { color: blue; }`],
804804
render() {
805805
return h(Baz)
806806
},
807807
})
808-
const WBaz = () => h(WarpperBar)
808+
const WBaz = () => h(WrapperBar)
809809
const Foo = defineCustomElement({
810810
styles: [`div { color: red; }`],
811811
render() {

packages/runtime-dom/src/apiCustomElement.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -581,17 +581,16 @@ export class VueElement
581581
owner?: ConcreteComponent,
582582
) {
583583
if (!styles) return
584-
const styleList: HTMLStyleElement[] = []
584+
const styleElements: HTMLStyleElement[] = []
585585
if (owner) {
586-
if (owner === this._def) {
586+
if (owner === this._def) return
587+
const existingStyles = this._styleChildren.get(owner)
588+
if (existingStyles) {
589+
// move existing styles to the top
590+
this.shadowRoot!.prepend(...existingStyles)
587591
return
588592
}
589-
const styleChild = this._styleChildren.get(owner)
590-
if (styleChild) {
591-
this.shadowRoot!.prepend(...styleChild)
592-
return
593-
}
594-
this._styleChildren.set(owner, styleList)
593+
this._styleChildren.set(owner, styleElements)
595594
}
596595

597596
const nonce = this._nonce
@@ -600,9 +599,7 @@ export class VueElement
600599
if (nonce) s.setAttribute('nonce', nonce)
601600
s.textContent = styles[i]
602601
this.shadowRoot!.prepend(s)
603-
if (owner) {
604-
styleList.unshift(s)
605-
}
602+
if (owner) styleElements.unshift(s)
606603
// record for HMR
607604
if (__DEV__) {
608605
if (owner) {

0 commit comments

Comments
 (0)