@@ -11,9 +11,12 @@ import {
11
11
serializeInner as inner ,
12
12
VNode ,
13
13
ref ,
14
- nextTick
14
+ nextTick ,
15
+ defineComponent ,
16
+ withCtx ,
17
+ renderSlot
15
18
} from '@vue/runtime-test'
16
- import { PatchFlags } from '@vue/shared'
19
+ import { PatchFlags , SlotFlags } from '@vue/shared'
17
20
18
21
describe ( 'renderer: optimized mode' , ( ) => {
19
22
let root : TestElement
@@ -398,4 +401,52 @@ describe('renderer: optimized mode', () => {
398
401
expect ( inner ( root ) ) . toBe ( '<div><i>bar</i></div>' )
399
402
expect ( block ! . dynamicChildren ) . toBe ( null )
400
403
} )
404
+
405
+ // #1980
406
+ test ( 'dynamicChildren should be tracked correctly when normalizing slots to plain children' , async ( ) => {
407
+ let block : VNode
408
+ const Comp = defineComponent ( {
409
+ setup ( _props , { slots } ) {
410
+ return ( ) => {
411
+ const vnode = ( openBlock ( ) ,
412
+ ( block = createBlock ( 'div' , null , {
413
+ default : withCtx ( ( ) => [ renderSlot ( slots , 'default' ) ] ) ,
414
+ _ : SlotFlags . FORWARDED
415
+ } ) ) )
416
+
417
+ return vnode
418
+ }
419
+ }
420
+ } )
421
+
422
+ const foo = ref ( 0 )
423
+ const App = {
424
+ setup ( ) {
425
+ return ( ) => {
426
+ return createVNode ( Comp , null , {
427
+ default : withCtx ( ( ) => [
428
+ createVNode ( 'p' , null , foo . value , PatchFlags . TEXT )
429
+ ] ) ,
430
+ // Indicates that this is a stable slot to avoid bail out
431
+ _ : SlotFlags . STABLE
432
+ } )
433
+ }
434
+ }
435
+ }
436
+
437
+ render ( h ( App ) , root )
438
+ expect ( inner ( root ) ) . toBe ( '<div><p>0</p></div>' )
439
+ expect ( block ! . dynamicChildren ! . length ) . toBe ( 1 )
440
+ expect ( block ! . dynamicChildren ! [ 0 ] . type ) . toBe ( Fragment )
441
+ expect ( block ! . dynamicChildren ! [ 0 ] . dynamicChildren ! . length ) . toBe ( 1 )
442
+ expect (
443
+ serialize ( block ! . dynamicChildren ! [ 0 ] . dynamicChildren ! [ 0 ]
444
+ . el as TestElement )
445
+ ) . toBe ( '<p>0</p>' )
446
+
447
+ foo . value ++
448
+ await nextTick ( )
449
+
450
+ expect ( inner ( root ) ) . toBe ( '<div><p>1</p></div>' )
451
+ } )
401
452
} )
0 commit comments