File tree 3 files changed +21
-14
lines changed
3 files changed +21
-14
lines changed Original file line number Diff line number Diff line change @@ -886,6 +886,7 @@ describe('KeepAlive', () => {
886
886
test ( 'should invoke onActivated of child on initial mount' , async ( ) => {
887
887
let parentCount = 0
888
888
let childCount = 0
889
+ const toggle = ref ( true )
889
890
const Child = defineComponent ( {
890
891
name : 'Child' ,
891
892
setup ( ) {
@@ -907,7 +908,7 @@ describe('KeepAlive', () => {
907
908
908
909
const App = {
909
910
render : ( ) => {
910
- return h ( KeepAlive , null , ( ) => h ( AsyncComp ) )
911
+ return h ( KeepAlive , null , ( ) => ( toggle . value ? h ( AsyncComp ) : null ) )
911
912
}
912
913
}
913
914
@@ -916,6 +917,13 @@ describe('KeepAlive', () => {
916
917
expect ( serializeInner ( root ) ) . toBe ( 'child' )
917
918
expect ( parentCount ) . toBe ( 1 )
918
919
expect ( childCount ) . toBe ( 1 )
920
+
921
+ toggle . value = false
922
+ await timeout ( )
923
+ toggle . value = true
924
+ await timeout ( )
925
+ expect ( parentCount ) . toBe ( 2 )
926
+ expect ( childCount ) . toBe ( 2 )
919
927
} )
920
928
921
929
// #4976
Original file line number Diff line number Diff line change @@ -401,18 +401,10 @@ function registerKeepAliveHook(
401
401
// arrays.
402
402
if ( target ) {
403
403
let current = target . parent
404
- let child = target
405
404
while ( current && current . parent ) {
406
405
if ( isKeepAlive ( current . parent . vnode ) ) {
407
- injectToKeepAliveRoot (
408
- wrappedHook ,
409
- type ,
410
- target ,
411
- // #7276
412
- isAsyncWrapper ( current ) ? child : current
413
- )
406
+ injectToKeepAliveRoot ( wrappedHook , type , target , current )
414
407
}
415
- child = current
416
408
current = current . parent
417
409
}
418
410
}
Original file line number Diff line number Diff line change @@ -1407,16 +1407,23 @@ function baseCreateRenderer(
1407
1407
)
1408
1408
}
1409
1409
1410
+ const parentIsAsyncWrapperAndShouldKeepAlive =
1411
+ parent &&
1412
+ isAsyncWrapper ( parent . vnode ) &&
1413
+ parent . vnode . shapeFlag & ShapeFlags . COMPONENT_SHOULD_KEEP_ALIVE
1410
1414
// activated hook for keep-alive roots.
1411
1415
// #1742 activated hook must be accessed after first render
1412
1416
// since the hook may be injected by a child keep-alive
1413
1417
if (
1414
1418
initialVNode . shapeFlag & ShapeFlags . COMPONENT_SHOULD_KEEP_ALIVE ||
1415
- ( parent &&
1416
- isAsyncWrapper ( parent . vnode ) &&
1417
- parent . vnode . shapeFlag & ShapeFlags . COMPONENT_SHOULD_KEEP_ALIVE )
1419
+ parentIsAsyncWrapperAndShouldKeepAlive
1418
1420
) {
1419
- instance . a && queuePostRenderEffect ( instance . a , parentSuspense )
1421
+ if ( parentIsAsyncWrapperAndShouldKeepAlive ) {
1422
+ // #7276 - parent.a contains all the hooks of the descendants
1423
+ parent . a && queuePostRenderEffect ( parent . a , parentSuspense )
1424
+ } else {
1425
+ instance . a && queuePostRenderEffect ( instance . a , parentSuspense )
1426
+ }
1420
1427
if (
1421
1428
__COMPAT__ &&
1422
1429
isCompatEnabled ( DeprecationTypes . INSTANCE_EVENT_HOOKS , instance )
You can’t perform that action at this time.
0 commit comments