@@ -176,7 +176,8 @@ describe('hot module replacement', () => {
176
176
return { toggle : true }
177
177
} ,
178
178
render : compileToFunction (
179
- `<button @click="toggle = !toggle"></button><KeepAlive><Child v-if="toggle" /></KeepAlive>`
179
+ `<button @click="toggle = !toggle" />
180
+ <KeepAlive><Child v-if="toggle" /></KeepAlive>`
180
181
)
181
182
}
182
183
@@ -243,7 +244,10 @@ describe('hot module replacement', () => {
243
244
return { toggle : true }
244
245
} ,
245
246
render : compileToFunction (
246
- `<button @click="toggle = !toggle"></button><BaseTransition mode="out-in"><KeepAlive><Child v-if="toggle" /></KeepAlive></BaseTransition>`
247
+ `<button @click="toggle = !toggle" />
248
+ <BaseTransition>
249
+ <KeepAlive><Child v-if="toggle" /></KeepAlive>
250
+ </BaseTransition>`
247
251
)
248
252
}
249
253
@@ -271,6 +275,87 @@ describe('hot module replacement', () => {
271
275
// should not unmount when toggling
272
276
triggerEvent ( root . children [ 1 ] as TestElement , 'click' )
273
277
await nextTick ( )
278
+ expect ( serializeInner ( root ) ) . toBe ( `<button></button><!--v-if-->` )
279
+ expect ( unmountSpy ) . toHaveBeenCalledTimes ( 1 )
280
+ expect ( mountSpy ) . toHaveBeenCalledTimes ( 1 )
281
+ expect ( activeSpy ) . toHaveBeenCalledTimes ( 1 )
282
+ expect ( deactiveSpy ) . toHaveBeenCalledTimes ( 1 )
283
+
284
+ // should not mount when toggling
285
+ triggerEvent ( root . children [ 1 ] as TestElement , 'click' )
286
+ await nextTick ( )
287
+ expect ( serializeInner ( root ) ) . toBe ( `<button></button><div>1</div>` )
288
+ expect ( unmountSpy ) . toHaveBeenCalledTimes ( 1 )
289
+ expect ( mountSpy ) . toHaveBeenCalledTimes ( 1 )
290
+ expect ( activeSpy ) . toHaveBeenCalledTimes ( 2 )
291
+ expect ( deactiveSpy ) . toHaveBeenCalledTimes ( 1 )
292
+ } )
293
+
294
+ test ( 'reload KeepAlive slot in Transition with out-in' , async ( ) => {
295
+ const root = nodeOps . createElement ( 'div' )
296
+ const childId = 'test-transition-keep-alive-reload-with-out-in'
297
+ const unmountSpy = vi . fn ( )
298
+ const mountSpy = vi . fn ( )
299
+ const activeSpy = vi . fn ( )
300
+ const deactiveSpy = vi . fn ( )
301
+
302
+ const Child : ComponentOptions = {
303
+ __hmrId : childId ,
304
+ name : 'original' ,
305
+ data ( ) {
306
+ return { count : 0 }
307
+ } ,
308
+ unmounted : unmountSpy ,
309
+ render : compileToFunction ( `<div>{{ count }}</div>` )
310
+ }
311
+ createRecord ( childId , Child )
312
+
313
+ const Parent : ComponentOptions = {
314
+ components : { Child } ,
315
+ data ( ) {
316
+ return { toggle : true }
317
+ } ,
318
+ methods : {
319
+ // @ts -ignore
320
+ onLeave ( _ , done ) {
321
+ setTimeout ( done , 0 )
322
+ }
323
+ } ,
324
+ render : compileToFunction (
325
+ `<button @click="toggle = !toggle" />
326
+ <BaseTransition mode="out-in" @leave="onLeave">
327
+ <KeepAlive><Child v-if="toggle" /></KeepAlive>
328
+ </BaseTransition>`
329
+ )
330
+ }
331
+
332
+ render ( h ( Parent ) , root )
333
+ expect ( serializeInner ( root ) ) . toBe ( `<button></button><div>0</div>` )
334
+
335
+ reload ( childId , {
336
+ __hmrId : childId ,
337
+ name : 'updated' ,
338
+ data ( ) {
339
+ return { count : 1 }
340
+ } ,
341
+ mounted : mountSpy ,
342
+ unmounted : unmountSpy ,
343
+ activated : activeSpy ,
344
+ deactivated : deactiveSpy ,
345
+ render : compileToFunction ( `<div>{{ count }}</div>` )
346
+ } )
347
+ await nextTick ( )
348
+ await new Promise ( r => setTimeout ( r , 0 ) )
349
+ expect ( serializeInner ( root ) ) . toBe ( `<button></button><div>1</div>` )
350
+ expect ( unmountSpy ) . toHaveBeenCalledTimes ( 1 )
351
+ expect ( mountSpy ) . toHaveBeenCalledTimes ( 1 )
352
+ expect ( activeSpy ) . toHaveBeenCalledTimes ( 1 )
353
+ expect ( deactiveSpy ) . toHaveBeenCalledTimes ( 0 )
354
+
355
+ // should not unmount when toggling
356
+ triggerEvent ( root . children [ 1 ] as TestElement , 'click' )
357
+ await nextTick ( )
358
+ await new Promise ( r => setTimeout ( r , 0 ) )
274
359
expect ( serializeInner ( root ) ) . toBe ( `<button></button><!---->` )
275
360
expect ( unmountSpy ) . toHaveBeenCalledTimes ( 1 )
276
361
expect ( mountSpy ) . toHaveBeenCalledTimes ( 1 )
0 commit comments