fix(runtime-core): vnode hooks should not be called on async wrapper (#4349)

fix #4346
This commit is contained in:
HcySunYang
2021-08-17 03:35:50 +08:00
committed by GitHub
parent 3201224ecb
commit cd2d98499e
2 changed files with 75 additions and 5 deletions

View File

@@ -1316,6 +1316,7 @@ function baseCreateRenderer(
let vnodeHook: VNodeHook | null | undefined
const { el, props } = initialVNode
const { bm, m, parent } = instance
const isAsyncWrapperVNode = isAsyncWrapper(initialVNode)
effect.allowRecurse = false
// beforeMount hook
@@ -1323,7 +1324,10 @@ function baseCreateRenderer(
invokeArrayFns(bm)
}
// onVnodeBeforeMount
if ((vnodeHook = props && props.onVnodeBeforeMount)) {
if (
!isAsyncWrapperVNode &&
(vnodeHook = props && props.onVnodeBeforeMount)
) {
invokeVNodeHook(vnodeHook, parent, initialVNode)
}
if (
@@ -1359,7 +1363,7 @@ function baseCreateRenderer(
}
}
if (isAsyncWrapper(initialVNode)) {
if (isAsyncWrapperVNode) {
;(initialVNode.type as ComponentOptions).__asyncLoader!().then(
// note: we are moving the render call into an async callback,
// which means it won't track dependencies - but it's ok because
@@ -1400,7 +1404,10 @@ function baseCreateRenderer(
queuePostRenderEffect(m, parentSuspense)
}
// onVnodeMounted
if ((vnodeHook = props && props.onVnodeMounted)) {
if (
!isAsyncWrapperVNode &&
(vnodeHook = props && props.onVnodeMounted)
) {
const scopedInitialVNode = initialVNode
queuePostRenderEffect(
() => invokeVNodeHook(vnodeHook!, parent, scopedInitialVNode),
@@ -2085,9 +2092,13 @@ function baseCreateRenderer(
}
const shouldInvokeDirs = shapeFlag & ShapeFlags.ELEMENT && dirs
const shouldInvokeVnodeHook = !isAsyncWrapper(vnode)
let vnodeHook: VNodeHook | undefined | null
if ((vnodeHook = props && props.onVnodeBeforeUnmount)) {
if (
shouldInvokeVnodeHook &&
(vnodeHook = props && props.onVnodeBeforeUnmount)
) {
invokeVNodeHook(vnodeHook, parentComponent, vnode)
}
@@ -2140,7 +2151,11 @@ function baseCreateRenderer(
}
}
if ((vnodeHook = props && props.onVnodeUnmounted) || shouldInvokeDirs) {
if (
(shouldInvokeVnodeHook &&
(vnodeHook = props && props.onVnodeUnmounted)) ||
shouldInvokeDirs
) {
queuePostRenderEffect(() => {
vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, vnode)
shouldInvokeDirs &&