@@ -5,19 +5,25 @@ import {
5
5
Teleport ,
6
6
type VueElement ,
7
7
createApp ,
8
+ createBlock ,
9
+ createCommentVNode ,
10
+ createElementBlock ,
11
+ createElementVNode ,
8
12
defineAsyncComponent ,
9
13
defineComponent ,
10
14
defineCustomElement ,
11
15
h ,
12
16
inject ,
13
17
nextTick ,
14
18
onMounted ,
19
+ openBlock ,
15
20
provide ,
16
21
ref ,
17
22
render ,
18
23
renderSlot ,
19
24
useHost ,
20
25
useShadowRoot ,
26
+ withCtx ,
21
27
} from '../src'
22
28
23
29
declare var __VUE_HMR_RUNTIME__ : HMRRuntime
@@ -1131,6 +1137,92 @@ describe('defineCustomElement', () => {
1131
1137
expect ( target . innerHTML ) . toBe ( `<span>default</span>` )
1132
1138
app . unmount ( )
1133
1139
} )
1140
+
1141
+ //#13206
1142
+ test ( 'should update slotted children correctly w/ shadowRoot false' , async ( ) => {
1143
+ const E = defineCustomElement (
1144
+ defineComponent ( {
1145
+ props : {
1146
+ isShown : { type : Boolean , required : true } ,
1147
+ } ,
1148
+ render ( ) {
1149
+ return this . isShown
1150
+ ? h ( 'div' , { key : 0 } , [ renderSlot ( this . $slots , 'default' ) ] )
1151
+ : null
1152
+ } ,
1153
+ } ) ,
1154
+ { shadowRoot : false } ,
1155
+ )
1156
+ customElements . define ( 'ce-shadow-root-false' , E )
1157
+
1158
+ const Comp = defineComponent ( {
1159
+ props : {
1160
+ isShown : { type : Boolean , required : true } ,
1161
+ } ,
1162
+ render ( ) {
1163
+ return h ( 'ce-shadow-root-false' , { 'is-shown' : this . isShown } , [
1164
+ renderSlot ( this . $slots , 'default' ) ,
1165
+ ] )
1166
+ } ,
1167
+ } )
1168
+
1169
+ const isShown = ref ( false )
1170
+ const count = ref ( 0 )
1171
+
1172
+ function click ( ) {
1173
+ isShown . value = ! isShown . value
1174
+ count . value ++
1175
+ }
1176
+
1177
+ const App = {
1178
+ render ( ) {
1179
+ return (
1180
+ openBlock ( ) ,
1181
+ createBlock (
1182
+ Comp ,
1183
+ { isShown : isShown . value } ,
1184
+ {
1185
+ default : withCtx ( ( ) => [
1186
+ createElementVNode ( 'div' , null , isShown . value , 1 /* TEXT */ ) ,
1187
+ count . value > 1
1188
+ ? ( openBlock ( ) , createElementBlock ( 'div' , { key : 0 } , 'hi' ) )
1189
+ : createCommentVNode ( 'v-if' , true ) ,
1190
+ ] ) ,
1191
+ _ : 1 /* STABLE */ ,
1192
+ } ,
1193
+ 8 /* PROPS */ ,
1194
+ [ 'isShown' ] ,
1195
+ )
1196
+ )
1197
+ } ,
1198
+ }
1199
+ const container = document . createElement ( 'div' )
1200
+ document . body . appendChild ( container )
1201
+
1202
+ const app = createApp ( App )
1203
+ app . mount ( container )
1204
+ expect ( container . innerHTML ) . toBe (
1205
+ `<ce-shadow-root-false data-v-app=""><!----></ce-shadow-root-false>` ,
1206
+ )
1207
+
1208
+ click ( )
1209
+ await nextTick ( )
1210
+ expect ( container . innerHTML ) . toBe (
1211
+ `<ce-shadow-root-false data-v-app="" is-shown=""><div><div>true</div><!--v-if--></div></ce-shadow-root-false>` ,
1212
+ )
1213
+
1214
+ click ( )
1215
+ await nextTick ( )
1216
+ expect ( container . innerHTML ) . toBe (
1217
+ `<ce-shadow-root-false data-v-app=""><!----></ce-shadow-root-false>` ,
1218
+ )
1219
+
1220
+ click ( )
1221
+ await nextTick ( )
1222
+ expect ( container . innerHTML ) . toBe (
1223
+ `<ce-shadow-root-false data-v-app="" is-shown=""><div><div>true</div><div>hi</div></div></ce-shadow-root-false>` ,
1224
+ )
1225
+ } )
1134
1226
} )
1135
1227
1136
1228
describe ( 'helpers' , ( ) => {
0 commit comments