@@ -1141,7 +1141,7 @@ describe('defineCustomElement', () => {
1141
1141
} )
1142
1142
1143
1143
// #13206
1144
- test ( 'update slotted v-if nodes w/ shadowRoot false' , async ( ) => {
1144
+ test ( 'update slotted v-if nodes w/ shadowRoot false (optimized mode) ' , async ( ) => {
1145
1145
const E = defineCustomElement (
1146
1146
defineComponent ( {
1147
1147
props : {
@@ -1155,16 +1155,18 @@ describe('defineCustomElement', () => {
1155
1155
} ) ,
1156
1156
{ shadowRoot : false } ,
1157
1157
)
1158
- customElements . define ( 'ce-shadow-root-false' , E )
1158
+ customElements . define ( 'ce-shadow-root-false-optimized ' , E )
1159
1159
1160
1160
const Comp = defineComponent ( {
1161
1161
props : {
1162
1162
isShown : { type : Boolean , required : true } ,
1163
1163
} ,
1164
1164
render ( ) {
1165
- return h ( 'ce-shadow-root-false' , { 'is-shown' : this . isShown } , [
1166
- renderSlot ( this . $slots , 'default' ) ,
1167
- ] )
1165
+ return h (
1166
+ 'ce-shadow-root-false-optimized' ,
1167
+ { 'is-shown' : this . isShown } ,
1168
+ [ renderSlot ( this . $slots , 'default' ) ] ,
1169
+ )
1168
1170
} ,
1169
1171
} )
1170
1172
@@ -1185,7 +1187,12 @@ describe('defineCustomElement', () => {
1185
1187
{ isShown : isShown . value } ,
1186
1188
{
1187
1189
default : withCtx ( ( ) => [
1188
- createElementVNode ( 'div' , null , isShown . value , 1 /* TEXT */ ) ,
1190
+ createElementVNode (
1191
+ 'div' ,
1192
+ null ,
1193
+ String ( isShown . value ) ,
1194
+ 1 /* TEXT */ ,
1195
+ ) ,
1189
1196
count . value > 1
1190
1197
? ( openBlock ( ) , createElementBlock ( 'div' , { key : 0 } , 'hi' ) )
1191
1198
: createCommentVNode ( 'v-if' , true ) ,
@@ -1204,7 +1211,94 @@ describe('defineCustomElement', () => {
1204
1211
const app = createApp ( App )
1205
1212
app . mount ( container )
1206
1213
expect ( container . innerHTML ) . toBe (
1207
- `<ce-shadow-root-false data-v-app=""><!--v-if--></ce-shadow-root-false>` ,
1214
+ `<ce-shadow-root-false-optimized data-v-app="">` +
1215
+ `<div>false</div><!--v-if-->` +
1216
+ `</ce-shadow-root-false-optimized>` ,
1217
+ )
1218
+
1219
+ click ( )
1220
+ await nextTick ( )
1221
+ expect ( container . innerHTML ) . toBe (
1222
+ `<ce-shadow-root-false-optimized data-v-app="" is-shown="">` +
1223
+ `<div><div>true</div><!--v-if--></div>` +
1224
+ `</ce-shadow-root-false-optimized>` ,
1225
+ )
1226
+
1227
+ click ( )
1228
+ await nextTick ( )
1229
+ expect ( container . innerHTML ) . toBe (
1230
+ `<ce-shadow-root-false-optimized data-v-app="">` +
1231
+ `<div>false</div><!--v-if-->` +
1232
+ `</ce-shadow-root-false-optimized>` ,
1233
+ )
1234
+
1235
+ click ( )
1236
+ await nextTick ( )
1237
+ expect ( container . innerHTML ) . toBe (
1238
+ `<ce-shadow-root-false-optimized data-v-app="" is-shown="">` +
1239
+ `<div><div>true</div><div>hi</div></div>` +
1240
+ `</ce-shadow-root-false-optimized>` ,
1241
+ )
1242
+ } )
1243
+
1244
+ test . todo ( 'update slotted v-if nodes w/ shadowRoot false' , async ( ) => {
1245
+ const E = defineCustomElement (
1246
+ defineComponent ( {
1247
+ props : {
1248
+ isShown : { type : Boolean , required : true } ,
1249
+ } ,
1250
+ render ( ) {
1251
+ return this . isShown
1252
+ ? h ( 'div' , { key : 0 } , [ renderSlot ( this . $slots , 'default' ) ] )
1253
+ : createCommentVNode ( 'v-if' )
1254
+ } ,
1255
+ } ) ,
1256
+ { shadowRoot : false } ,
1257
+ )
1258
+ customElements . define ( 'ce-shadow-root-false' , E )
1259
+
1260
+ const Comp = defineComponent ( {
1261
+ props : {
1262
+ isShown : { type : Boolean , required : true } ,
1263
+ } ,
1264
+ render ( ) {
1265
+ return h ( 'ce-shadow-root-false' , { 'is-shown' : this . isShown } , [
1266
+ renderSlot ( this . $slots , 'default' ) ,
1267
+ ] )
1268
+ } ,
1269
+ } )
1270
+
1271
+ const isShown = ref ( false )
1272
+ const count = ref ( 0 )
1273
+
1274
+ function click ( ) {
1275
+ isShown . value = ! isShown . value
1276
+ count . value ++
1277
+ }
1278
+
1279
+ const App = {
1280
+ render ( ) {
1281
+ return h (
1282
+ Comp ,
1283
+ { isShown : isShown . value } ,
1284
+ {
1285
+ default : ( ) => [
1286
+ h ( 'div' , null , String ( isShown . value ) ) ,
1287
+ count . value > 1
1288
+ ? h ( 'div' , { key : 0 } , 'hi' )
1289
+ : createCommentVNode ( 'v-if' , true ) ,
1290
+ ] ,
1291
+ } ,
1292
+ )
1293
+ } ,
1294
+ }
1295
+ const container = document . createElement ( 'div' )
1296
+ document . body . appendChild ( container )
1297
+
1298
+ const app = createApp ( App )
1299
+ app . mount ( container )
1300
+ expect ( container . innerHTML ) . toBe (
1301
+ `<ce-shadow-root-false data-v-app=""><div>false</div><!--v-if--></ce-shadow-root-false>` ,
1208
1302
)
1209
1303
1210
1304
click ( )
@@ -1216,7 +1310,7 @@ describe('defineCustomElement', () => {
1216
1310
click ( )
1217
1311
await nextTick ( )
1218
1312
expect ( container . innerHTML ) . toBe (
1219
- `<ce-shadow-root-false data-v-app=""><!--v-if--></ce-shadow-root-false>` ,
1313
+ `<ce-shadow-root-false data-v-app=""><div>false</div>< !--v-if--></ce-shadow-root-false>` ,
1220
1314
)
1221
1315
1222
1316
click ( )
@@ -1227,7 +1321,7 @@ describe('defineCustomElement', () => {
1227
1321
} )
1228
1322
1229
1323
// #13234
1230
- test ( 'switch between slotted and fallback nodes w/ shadowRoot false' , async ( ) => {
1324
+ test ( 'switch between slotted and fallback nodes w/ shadowRoot false (optimized mode) ' , async ( ) => {
1231
1325
const E = defineCustomElement (
1232
1326
defineComponent ( {
1233
1327
render ( ) {
@@ -1238,21 +1332,25 @@ describe('defineCustomElement', () => {
1238
1332
} ) ,
1239
1333
{ shadowRoot : false } ,
1240
1334
)
1241
- customElements . define ( 'ce-with-fallback-shadow-root-false' , E )
1335
+ customElements . define ( 'ce-with-fallback-shadow-root-false-optimized ' , E )
1242
1336
1243
1337
const Comp = defineComponent ( {
1244
1338
render ( ) {
1245
1339
return (
1246
1340
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
- ] )
1341
+ createElementBlock (
1342
+ 'ce-with-fallback-shadow-root-false-optimized' ,
1343
+ null ,
1344
+ [
1345
+ this . $slots . foo
1346
+ ? ( openBlock ( ) ,
1347
+ createElementBlock ( 'div' , { key : 0 , slot : 'foo' } , [
1348
+ renderSlot ( this . $slots , 'foo' ) ,
1349
+ ] ) )
1350
+ : createCommentVNode ( 'v-if' , true ) ,
1351
+ renderSlot ( this . $slots , 'default' ) ,
1352
+ ] ,
1353
+ )
1256
1354
)
1257
1355
} ,
1258
1356
} )
@@ -1290,27 +1388,107 @@ describe('defineCustomElement', () => {
1290
1388
const app = createApp ( App )
1291
1389
app . mount ( container )
1292
1390
expect ( container . innerHTML ) . toBe (
1293
- `<ce-with-fallback-shadow-root-false data-v-app="">` +
1391
+ `<ce-with-fallback-shadow-root-false-optimized data-v-app="">` +
1294
1392
`fallback` +
1295
- `</ce-with-fallback-shadow-root-false>` ,
1393
+ `</ce-with-fallback-shadow-root-false-optimized >` ,
1296
1394
)
1297
1395
1298
1396
isShown . value = true
1299
1397
await nextTick ( )
1300
1398
expect ( container . innerHTML ) . toBe (
1301
- `<ce-with-fallback-shadow-root-false data-v-app="">` +
1399
+ `<ce-with-fallback-shadow-root-false-optimized data-v-app="">` +
1302
1400
`<div slot="foo">foo</div>` +
1303
- `</ce-with-fallback-shadow-root-false>` ,
1401
+ `</ce-with-fallback-shadow-root-false-optimized >` ,
1304
1402
)
1305
1403
1306
1404
isShown . value = false
1307
1405
await nextTick ( )
1308
1406
expect ( container . innerHTML ) . toBe (
1309
- `<ce-with-fallback-shadow-root-false data-v-app="">` +
1407
+ `<ce-with-fallback-shadow-root-false-optimized data-v-app="">` +
1310
1408
`fallback<!--v-if-->` +
1311
- `</ce-with-fallback-shadow-root-false>` ,
1409
+ `</ce-with-fallback-shadow-root-false-optimized >` ,
1312
1410
)
1313
1411
} )
1412
+
1413
+ test . todo (
1414
+ 'switch between slotted and fallback nodes w/ shadowRoot false' ,
1415
+ async ( ) => {
1416
+ const E = defineCustomElement (
1417
+ defineComponent ( {
1418
+ render ( ) {
1419
+ return renderSlot ( this . $slots , 'foo' , { } , ( ) => [
1420
+ createTextVNode ( 'fallback' ) ,
1421
+ ] )
1422
+ } ,
1423
+ } ) ,
1424
+ { shadowRoot : false } ,
1425
+ )
1426
+ customElements . define ( 'ce-with-fallback-shadow-root-false' , E )
1427
+
1428
+ const Comp = defineComponent ( {
1429
+ render ( ) {
1430
+ return h ( 'ce-with-fallback-shadow-root-false' , null , [
1431
+ this . $slots . foo
1432
+ ? h ( 'div' , { key : 0 , slot : 'foo' } , [
1433
+ renderSlot ( this . $slots , 'foo' ) ,
1434
+ ] )
1435
+ : createCommentVNode ( 'v-if' , true ) ,
1436
+ renderSlot ( this . $slots , 'default' ) ,
1437
+ ] )
1438
+ } ,
1439
+ } )
1440
+
1441
+ const isShown = ref ( false )
1442
+ const App = defineComponent ( {
1443
+ components : { Comp } ,
1444
+ render ( ) {
1445
+ return h (
1446
+ Comp ,
1447
+ null ,
1448
+ createSlots (
1449
+ { _ : 2 /* DYNAMIC */ } as any ,
1450
+ [
1451
+ isShown . value
1452
+ ? {
1453
+ name : 'foo' ,
1454
+ fn : withCtx ( ( ) => [ createTextVNode ( 'foo' ) ] ) ,
1455
+ key : '0' ,
1456
+ }
1457
+ : undefined ,
1458
+ ] as any ,
1459
+ ) ,
1460
+ )
1461
+ } ,
1462
+ } )
1463
+
1464
+ const container = document . createElement ( 'div' )
1465
+ document . body . appendChild ( container )
1466
+
1467
+ const app = createApp ( App )
1468
+ app . mount ( container )
1469
+ expect ( container . innerHTML ) . toBe (
1470
+ `<ce-with-fallback-shadow-root-false data-v-app="">` +
1471
+ `fallback` +
1472
+ `</ce-with-fallback-shadow-root-false>` ,
1473
+ )
1474
+
1475
+ isShown . value = true
1476
+ await nextTick ( )
1477
+ expect ( container . innerHTML ) . toBe (
1478
+ `<ce-with-fallback-shadow-root-false data-v-app="">` +
1479
+ `<div slot="foo">foo</div>` +
1480
+ `</ce-with-fallback-shadow-root-false>` ,
1481
+ )
1482
+
1483
+ isShown . value = false
1484
+ await nextTick ( )
1485
+ expect ( container . innerHTML ) . toBe (
1486
+ `<ce-with-fallback-shadow-root-false data-v-app="">` +
1487
+ `fallback<!--v-if-->` +
1488
+ `</ce-with-fallback-shadow-root-false>` ,
1489
+ )
1490
+ } ,
1491
+ )
1314
1492
} )
1315
1493
1316
1494
describe ( 'helpers' , ( ) => {
0 commit comments