@@ -1173,4 +1173,53 @@ describe('KeepAlive', () => {
11731173 expect ( deactivatedHome ) . toHaveBeenCalledTimes ( 0 )
11741174 expect ( unmountedHome ) . toHaveBeenCalledTimes ( 1 )
11751175 } )
1176+
1177+ test ( 'should work with async component when update `include` props' , async ( ) => {
1178+ let resolve : ( comp : Component ) => void
1179+ const AsyncComp = defineAsyncComponent (
1180+ ( ) =>
1181+ new Promise ( r => {
1182+ resolve = r as any
1183+ } ) ,
1184+ )
1185+
1186+ const toggle = ref ( true )
1187+ const instanceRef = ref < any > ( null )
1188+ const keepaliveInclude = ref ( [ 'Foo' ] )
1189+ const App = {
1190+ render : ( ) => {
1191+ return h ( KeepAlive , { include : keepaliveInclude . value } , ( ) =>
1192+ toggle . value ? h ( AsyncComp , { ref : instanceRef } ) : null ,
1193+ )
1194+ } ,
1195+ }
1196+
1197+ render ( h ( App ) , root )
1198+ // async component has not been resolved
1199+ expect ( serializeInner ( root ) ) . toBe ( '<!---->' )
1200+
1201+ resolve ! ( {
1202+ name : 'Foo' ,
1203+ data : ( ) => ( { count : 0 } ) ,
1204+ render ( ) {
1205+ return h ( 'p' , this . count )
1206+ } ,
1207+ } )
1208+
1209+ await timeout ( )
1210+ // resolved
1211+ expect ( serializeInner ( root ) ) . toBe ( '<p>0</p>' )
1212+
1213+ // change state + toggle out + update `include` props
1214+ instanceRef . value . count ++
1215+ toggle . value = false
1216+ keepaliveInclude . value = [ 'Foo' ]
1217+ await nextTick ( )
1218+ expect ( serializeInner ( root ) ) . toBe ( '<!---->' )
1219+
1220+ // toggle in, state should be maintained
1221+ toggle . value = true
1222+ await nextTick ( )
1223+ expect ( serializeInner ( root ) ) . toBe ( '<p>1</p>' )
1224+ } )
11761225} )
0 commit comments