9
9
createCommentVNode ,
10
10
createElementBlock ,
11
11
createElementVNode ,
12
+ createSlots ,
13
+ createTextVNode ,
12
14
defineAsyncComponent ,
13
15
defineComponent ,
14
16
defineCustomElement ,
@@ -1138,8 +1140,8 @@ describe('defineCustomElement', () => {
1138
1140
app . unmount ( )
1139
1141
} )
1140
1142
1141
- //#13206
1142
- test ( 'should update slotted children correctly w/ shadowRoot false' , async ( ) => {
1143
+ // #13206
1144
+ test ( 'update slotted v-if nodes w/ shadowRoot false' , async ( ) => {
1143
1145
const E = defineCustomElement (
1144
1146
defineComponent ( {
1145
1147
props : {
@@ -1148,7 +1150,7 @@ describe('defineCustomElement', () => {
1148
1150
render ( ) {
1149
1151
return this . isShown
1150
1152
? h ( 'div' , { key : 0 } , [ renderSlot ( this . $slots , 'default' ) ] )
1151
- : null
1153
+ : createCommentVNode ( 'v-if' )
1152
1154
} ,
1153
1155
} ) ,
1154
1156
{ shadowRoot : false } ,
@@ -1202,7 +1204,7 @@ describe('defineCustomElement', () => {
1202
1204
const app = createApp ( App )
1203
1205
app . mount ( container )
1204
1206
expect ( container . innerHTML ) . toBe (
1205
- `<ce-shadow-root-false data-v-app=""><!----></ce-shadow-root-false>` ,
1207
+ `<ce-shadow-root-false data-v-app=""><!--v-if --></ce-shadow-root-false>` ,
1206
1208
)
1207
1209
1208
1210
click ( )
@@ -1214,7 +1216,7 @@ describe('defineCustomElement', () => {
1214
1216
click ( )
1215
1217
await nextTick ( )
1216
1218
expect ( container . innerHTML ) . toBe (
1217
- `<ce-shadow-root-false data-v-app=""><!----></ce-shadow-root-false>` ,
1219
+ `<ce-shadow-root-false data-v-app=""><!--v-if --></ce-shadow-root-false>` ,
1218
1220
)
1219
1221
1220
1222
click ( )
@@ -1223,6 +1225,92 @@ describe('defineCustomElement', () => {
1223
1225
`<ce-shadow-root-false data-v-app="" is-shown=""><div><div>true</div><div>hi</div></div></ce-shadow-root-false>` ,
1224
1226
)
1225
1227
} )
1228
+
1229
+ // #13234
1230
+ test ( 'switch between slotted and fallback nodes w/ shadowRoot false' , async ( ) => {
1231
+ const E = defineCustomElement (
1232
+ defineComponent ( {
1233
+ render ( ) {
1234
+ return renderSlot ( this . $slots , 'foo' , { } , ( ) => [
1235
+ createTextVNode ( 'fallback' ) ,
1236
+ ] )
1237
+ } ,
1238
+ } ) ,
1239
+ { shadowRoot : false } ,
1240
+ )
1241
+ customElements . define ( 'ce-with-fallback-shadow-root-false' , E )
1242
+
1243
+ const Comp = defineComponent ( {
1244
+ render ( ) {
1245
+ return (
1246
+ openBlock ( ) ,
1247
+ createElementBlock ( 'ce-with-fallback-shadow-root-false' , null , [
1248
+ this . $slots . foo
1249
+ ? ( openBlock ( ) ,
1250
+ createElementBlock ( 'div' , { key : 0 , slot : 'foo' } , [
1251
+ renderSlot ( this . $slots , 'foo' ) ,
1252
+ ] ) )
1253
+ : createCommentVNode ( 'v-if' , true ) ,
1254
+ renderSlot ( this . $slots , 'default' ) ,
1255
+ ] )
1256
+ )
1257
+ } ,
1258
+ } )
1259
+
1260
+ const isShown = ref ( false )
1261
+ const App = defineComponent ( {
1262
+ components : { Comp } ,
1263
+ render ( ) {
1264
+ return (
1265
+ openBlock ( ) ,
1266
+ createBlock (
1267
+ Comp ,
1268
+ null ,
1269
+ createSlots (
1270
+ { _ : 2 /* DYNAMIC */ } as any ,
1271
+ [
1272
+ isShown . value
1273
+ ? {
1274
+ name : 'foo' ,
1275
+ fn : withCtx ( ( ) => [ createTextVNode ( 'foo' ) ] ) ,
1276
+ key : '0' ,
1277
+ }
1278
+ : undefined ,
1279
+ ] as any ,
1280
+ ) ,
1281
+ 1024 /* DYNAMIC_SLOTS */ ,
1282
+ )
1283
+ )
1284
+ } ,
1285
+ } )
1286
+
1287
+ const container = document . createElement ( 'div' )
1288
+ document . body . appendChild ( container )
1289
+
1290
+ const app = createApp ( App )
1291
+ app . mount ( container )
1292
+ expect ( container . innerHTML ) . toBe (
1293
+ `<ce-with-fallback-shadow-root-false data-v-app="">` +
1294
+ `fallback` +
1295
+ `</ce-with-fallback-shadow-root-false>` ,
1296
+ )
1297
+
1298
+ isShown . value = true
1299
+ await nextTick ( )
1300
+ expect ( container . innerHTML ) . toBe (
1301
+ `<ce-with-fallback-shadow-root-false data-v-app="">` +
1302
+ `<div slot="foo">foo</div>` +
1303
+ `</ce-with-fallback-shadow-root-false>` ,
1304
+ )
1305
+
1306
+ isShown . value = false
1307
+ await nextTick ( )
1308
+ expect ( container . innerHTML ) . toBe (
1309
+ `<ce-with-fallback-shadow-root-false data-v-app="">` +
1310
+ `fallback<!--v-if-->` +
1311
+ `</ce-with-fallback-shadow-root-false>` ,
1312
+ )
1313
+ } )
1226
1314
} )
1227
1315
1228
1316
describe ( 'helpers' , ( ) => {
0 commit comments