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