fix(keep-alive): should remove wrapped version of injected keep alive hooks (#1959)
This commit is contained in:
parent
a47626a4a3
commit
1ea24000c8
@ -18,7 +18,7 @@ export function injectHook(
|
|||||||
hook: Function & { __weh?: Function },
|
hook: Function & { __weh?: Function },
|
||||||
target: ComponentInternalInstance | null = currentInstance,
|
target: ComponentInternalInstance | null = currentInstance,
|
||||||
prepend: boolean = false
|
prepend: boolean = false
|
||||||
) {
|
): Function | undefined {
|
||||||
if (target) {
|
if (target) {
|
||||||
const hooks = target[type] || (target[type] = [])
|
const hooks = target[type] || (target[type] = [])
|
||||||
// cache the error handling wrapper for injected hooks so the same hook
|
// cache the error handling wrapper for injected hooks so the same hook
|
||||||
@ -47,6 +47,7 @@ export function injectHook(
|
|||||||
} else {
|
} else {
|
||||||
hooks.push(wrappedHook)
|
hooks.push(wrappedHook)
|
||||||
}
|
}
|
||||||
|
return wrappedHook
|
||||||
} else if (__DEV__) {
|
} else if (__DEV__) {
|
||||||
const apiName = `on${capitalize(
|
const apiName = `on${capitalize(
|
||||||
ErrorTypeStrings[type].replace(/ hook$/, '')
|
ErrorTypeStrings[type].replace(/ hook$/, '')
|
||||||
|
@ -360,14 +360,16 @@ function registerKeepAliveHook(
|
|||||||
}
|
}
|
||||||
|
|
||||||
function injectToKeepAliveRoot(
|
function injectToKeepAliveRoot(
|
||||||
hook: Function,
|
hook: Function & { __weh?: Function },
|
||||||
type: LifecycleHooks,
|
type: LifecycleHooks,
|
||||||
target: ComponentInternalInstance,
|
target: ComponentInternalInstance,
|
||||||
keepAliveRoot: ComponentInternalInstance
|
keepAliveRoot: ComponentInternalInstance
|
||||||
) {
|
) {
|
||||||
injectHook(type, hook, keepAliveRoot, true /* prepend */)
|
// injectHook wraps the original for error handling, so make sure to remove
|
||||||
|
// the wrapped version.
|
||||||
|
const injected = injectHook(type, hook, keepAliveRoot, true /* prepend */)
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
remove(keepAliveRoot[type]!, hook)
|
remove(keepAliveRoot[type]!, injected)
|
||||||
}, target)
|
}, target)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user