@@ -2,6 +2,7 @@ import type { MockedFunction } from 'vitest'
2
2
import {
3
3
type HMRRuntime ,
4
4
type Ref ,
5
+ Teleport ,
5
6
type VueElement ,
6
7
createApp ,
7
8
defineAsyncComponent ,
@@ -10,6 +11,7 @@ import {
10
11
h ,
11
12
inject ,
12
13
nextTick ,
14
+ onMounted ,
13
15
provide ,
14
16
ref ,
15
17
render ,
@@ -975,6 +977,113 @@ describe('defineCustomElement', () => {
975
977
`<span>default</span>text` + `<!---->` + `<div>fallback</div>` ,
976
978
)
977
979
} )
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
+ } )
978
1087
} )
979
1088
980
1089
describe ( 'helpers' , ( ) => {
0 commit comments