@@ -2,6 +2,7 @@ import type { MockedFunction } from 'vitest'
22import {
33 type HMRRuntime ,
44 type Ref ,
5+ Teleport ,
56 type VueElement ,
67 createApp ,
78 defineAsyncComponent ,
@@ -10,6 +11,7 @@ import {
1011 h ,
1112 inject ,
1213 nextTick ,
14+ onMounted ,
1315 provide ,
1416 ref ,
1517 render ,
@@ -975,6 +977,113 @@ describe('defineCustomElement', () => {
975977 `<span>default</span>text` + `<!---->` + `<div>fallback</div>` ,
976978 )
977979 } )
980+
981+ test ( 'render nested customElement w/ shadowRoot false' , async ( ) => {
982+ const calls : string [ ] = [ ]
983+
984+ const Child = defineCustomElement (
985+ {
986+ setup ( ) {
987+ calls . push ( 'child rendering' )
988+ onMounted ( ( ) => {
989+ calls . push ( 'child mounted' )
990+ } )
991+ } ,
992+ render ( ) {
993+ return renderSlot ( this . $slots , 'default' )
994+ } ,
995+ } ,
996+ { shadowRoot : false } ,
997+ )
998+ customElements . define ( 'my-child' , Child )
999+
1000+ const Parent = defineCustomElement (
1001+ {
1002+ setup ( ) {
1003+ calls . push ( 'parent rendering' )
1004+ onMounted ( ( ) => {
1005+ calls . push ( 'parent mounted' )
1006+ } )
1007+ } ,
1008+ render ( ) {
1009+ return renderSlot ( this . $slots , 'default' )
1010+ } ,
1011+ } ,
1012+ { shadowRoot : false } ,
1013+ )
1014+ customElements . define ( 'my-parent' , Parent )
1015+
1016+ const App = {
1017+ render ( ) {
1018+ return h ( 'my-parent' , null , {
1019+ default : ( ) => [
1020+ h ( 'my-child' , null , {
1021+ default : ( ) => [ h ( 'span' , null , 'default' ) ] ,
1022+ } ) ,
1023+ ] ,
1024+ } )
1025+ } ,
1026+ }
1027+ const app = createApp ( App )
1028+ app . mount ( container )
1029+ await nextTick ( )
1030+ const e = container . childNodes [ 0 ] as VueElement
1031+ expect ( e . innerHTML ) . toBe (
1032+ `<my-child data-v-app=""><span>default</span></my-child>` ,
1033+ )
1034+ expect ( calls ) . toEqual ( [
1035+ 'parent rendering' ,
1036+ 'parent mounted' ,
1037+ 'child rendering' ,
1038+ 'child mounted' ,
1039+ ] )
1040+ app . unmount ( )
1041+ } )
1042+
1043+ test ( 'render nested Teleport w/ shadowRoot false' , async ( ) => {
1044+ const target = document . createElement ( 'div' )
1045+ const Child = defineCustomElement (
1046+ {
1047+ render ( ) {
1048+ return h (
1049+ Teleport ,
1050+ { to : target } ,
1051+ {
1052+ default : ( ) => [ renderSlot ( this . $slots , 'default' ) ] ,
1053+ } ,
1054+ )
1055+ } ,
1056+ } ,
1057+ { shadowRoot : false } ,
1058+ )
1059+ customElements . define ( 'my-el-teleport-child' , Child )
1060+ const Parent = defineCustomElement (
1061+ {
1062+ render ( ) {
1063+ return renderSlot ( this . $slots , 'default' )
1064+ } ,
1065+ } ,
1066+ { shadowRoot : false } ,
1067+ )
1068+ customElements . define ( 'my-el-teleport-parent' , Parent )
1069+
1070+ const App = {
1071+ render ( ) {
1072+ return h ( 'my-el-teleport-parent' , null , {
1073+ default : ( ) => [
1074+ h ( 'my-el-teleport-child' , null , {
1075+ default : ( ) => [ h ( 'span' , null , 'default' ) ] ,
1076+ } ) ,
1077+ ] ,
1078+ } )
1079+ } ,
1080+ }
1081+ const app = createApp ( App )
1082+ app . mount ( container )
1083+ await nextTick ( )
1084+ expect ( target . innerHTML ) . toBe ( `<span>default</span>` )
1085+ app . unmount ( )
1086+ } )
9781087 } )
9791088
9801089 describe ( 'helpers' , ( ) => {
0 commit comments