expect(node.patchFlag).toBe(genFlagText(PatchFlags.NEED_PATCH))
})
+ test('NEED_PATCH (vnode hooks)', () => {
+ const { node } = parseWithBind(`<div @vnodeUpdated="foo" />`)
+ expect(node.patchFlag).toBe(genFlagText(PatchFlags.NEED_PATCH))
+ })
+
test('HYDRATE_EVENTS', () => {
// ignore click events (has dedicated fast path)
const { node } = parseWithElementTransform(`<div @click="foo" />`, {
PatchFlagNames,
isSymbol,
isOn,
- isObject
+ isObject,
+ isReservedProp
} from '@vue/shared'
import { createCompilerError, ErrorCodes } from '../errors'
import {
let hasStyleBinding = false
let hasHydrationEventBinding = false
let hasDynamicKeys = false
+ let hasVnodeHook = false
const dynamicPropNames: string[] = []
const analyzePatchFlag = ({ key, value }: Property) => {
if (isStaticExp(key)) {
const name = key.content
+ const isEventHandler = isOn(name)
if (
!isComponent &&
- isOn(name) &&
+ isEventHandler &&
// omit the flag for click handlers because hydration gives click
// dedicated fast path.
name.toLowerCase() !== 'onclick' &&
// omit v-model handlers
- name !== 'onUpdate:modelValue'
+ name !== 'onUpdate:modelValue' &&
+ // omit onVnodeXXX hooks
+ !isReservedProp(name)
) {
hasHydrationEventBinding = true
}
+
+ if (isEventHandler && isReservedProp(name)) {
+ hasVnodeHook = true
+ }
+
if (
value.type === NodeTypes.JS_CACHE_EXPRESSION ||
((value.type === NodeTypes.SIMPLE_EXPRESSION ||
}
if (
(patchFlag === 0 || patchFlag === PatchFlags.HYDRATE_EVENTS) &&
- (hasRef || runtimeDirectives.length > 0)
+ (hasRef || hasVnodeHook || runtimeDirectives.length > 0)
) {
patchFlag |= PatchFlags.NEED_PATCH
}