Skip to content

Commit 75abdb8

Browse files
committed
feat(custom-element): Async component styles are lost for nested
1 parent d5a518a commit 75abdb8

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

packages/runtime-core/src/renderer.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,10 +1375,10 @@ function baseCreateRenderer(
13751375
// component of a custom element
13761376
if (instance && instance.parent) {
13771377
if (
1378-
!(instance.parent.type as ComponentOptions).__asyncLoader ||
1379-
((instance.parent.type as ComponentOptions).__asyncLoader &&
1380-
instance.parent.parent &&
1381-
instance.parent.parent.isCE)
1378+
!(
1379+
(instance.parent.type as ComponentOptions).__asyncLoader &&
1380+
instance.parent.isCE
1381+
)
13821382
) {
13831383
const styles =
13841384
(instance.isCEChild &&

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -658,11 +658,21 @@ describe('defineCustomElement', () => {
658658
})
659659

660660
test('child components in shadow dom should have styles & async & descendants', async () => {
661+
const Child2 = defineAsyncComponent(() => {
662+
return Promise.resolve({
663+
styles: [`.Child2 { color: pink; }`],
664+
render() {
665+
return h('div', { class: 'Child2' }, 'pink')
666+
}
667+
} as ComponentOptions)
668+
})
669+
661670
const Child = defineAsyncComponent(() => {
662671
return Promise.resolve({
672+
components: { Child2 },
663673
styles: [`.Child { color: blue; }`],
664674
render() {
665-
return h('div', { class: 'Child' }, 'hello')
675+
return h('div', { class: 'Child' }, ['hello', h(Child2)])
666676
}
667677
} as ComponentOptions)
668678
})
@@ -681,9 +691,10 @@ describe('defineCustomElement', () => {
681691

682692
const el = container.childNodes[0] as VueElement
683693
const style = el.shadowRoot?.querySelectorAll('style')!
684-
expect(style.length).toBe(2)
694+
expect(style.length).toBe(3)
685695
expect(style[0].textContent).toBe(`div { color: red; }`)
686696
expect(style[1].textContent).toBe(`.Child { color: blue; }`)
697+
expect(style[2].textContent).toBe(`.Child2 { color: pink; }`)
687698
})
688699

689700
test('set DOM property before resolve', async () => {

0 commit comments

Comments
 (0)