fix(runtime-core): should disable tracking inside directive lifecycle hooks (#3699)

This commit is contained in:
HcySunYang
2021-05-28 04:53:19 +08:00
committed by GitHub
parent 9f24195d2c
commit ff50e8d78c
2 changed files with 33 additions and 0 deletions

View File

@@ -19,6 +19,7 @@ import { currentRenderingInstance } from './componentRenderContext'
import { callWithAsyncErrorHandling, ErrorCodes } from './errorHandling'
import { ComponentPublicInstance } from './componentPublicInstance'
import { mapCompatDirectiveHook } from './compat/customDirective'
import { pauseTracking, resetTracking } from '@vue/reactivity'
export interface DirectiveBinding<V = any> {
instance: ComponentPublicInstance | null
@@ -130,12 +131,16 @@ export function invokeDirectiveHook(
hook = mapCompatDirectiveHook(name, binding.dir, instance)
}
if (hook) {
// disable tracking inside all lifecycle hooks
// since they can potentially be called inside effects.
pauseTracking()
callWithAsyncErrorHandling(hook, instance, ErrorCodes.DIRECTIVE_HOOK, [
vnode.el,
binding,
vnode,
prevVNode
])
resetTracking()
}
}
}