File tree 2 files changed +37
-2
lines changed
2 files changed +37
-2
lines changed Original file line number Diff line number Diff line change 4
4
ContextualRenderFn ,
5
5
currentRenderingInstance
6
6
} from '../componentRenderContext'
7
- import { Comment , isVNode } from '../vnode'
8
7
import {
8
+ Comment ,
9
+ isVNode ,
9
10
VNodeArrayChildren ,
10
11
openBlock ,
11
12
createBlock ,
@@ -15,6 +16,7 @@ import {
15
16
import { PatchFlags , SlotFlags } from '@vue/shared'
16
17
import { warn } from '../warning'
17
18
import { createVNode } from '@vue/runtime-core'
19
+ import { isAsyncWrapper } from '../apiAsyncComponent'
18
20
19
21
/**
20
22
* Compiler runtime helper for rendering `<slot/>`
@@ -29,7 +31,12 @@ export function renderSlot(
29
31
fallback ?: ( ) => VNodeArrayChildren ,
30
32
noSlotted ?: boolean
31
33
) : VNode {
32
- if ( currentRenderingInstance ! . isCE ) {
34
+ if (
35
+ currentRenderingInstance ! . isCE ||
36
+ ( currentRenderingInstance ! . parent &&
37
+ isAsyncWrapper ( currentRenderingInstance ! . parent ) &&
38
+ currentRenderingInstance ! . parent . isCE )
39
+ ) {
33
40
return createVNode (
34
41
'slot' ,
35
42
name === 'default' ? null : { name } ,
Original file line number Diff line number Diff line change @@ -457,5 +457,33 @@ describe('defineCustomElement', () => {
457
457
const e = container . childNodes [ 0 ] as VueElement
458
458
expect ( e . shadowRoot ! . innerHTML ) . toBe ( `<div>20,number</div>` )
459
459
} )
460
+
461
+ test ( 'with slots' , async ( ) => {
462
+ const E = defineCustomElement (
463
+ defineAsyncComponent ( ( ) => {
464
+ return Promise . resolve ( {
465
+ render ( this : any ) {
466
+ return [
467
+ h ( 'div' , null , [
468
+ renderSlot ( this . $slots , 'default' , undefined , ( ) => [
469
+ h ( 'div' , 'fallback' )
470
+ ] )
471
+ ] ) ,
472
+ h ( 'div' , null , renderSlot ( this . $slots , 'named' ) )
473
+ ]
474
+ }
475
+ } )
476
+ } )
477
+ )
478
+ customElements . define ( 'my-el-async-slots' , E )
479
+ container . innerHTML = `<my-el-async-slots><span>hi</span></my-el-async-slots>`
480
+
481
+ await new Promise ( r => setTimeout ( r ) )
482
+
483
+ const e = container . childNodes [ 0 ] as VueElement
484
+ expect ( e . shadowRoot ! . innerHTML ) . toBe (
485
+ `<div><slot><div>fallback</div></slot></div><div><slot name="named"></slot></div>`
486
+ )
487
+ } )
460
488
} )
461
489
} )
You can’t perform that action at this time.
0 commit comments