fix(runtime-core): rework vnode hooks handling
- peroperly support directive on components (e.g. <foo v-show="x">) - consistently invoke raw vnode hooks on component vnodes (fix #684)
This commit is contained in:
@@ -11,7 +11,8 @@ import {
|
||||
hasOwn,
|
||||
toRawType,
|
||||
PatchFlags,
|
||||
makeMap
|
||||
makeMap,
|
||||
isReservedProp
|
||||
} from '@vue/shared'
|
||||
import { warn } from './warning'
|
||||
import { Data, ComponentInternalInstance } from './component'
|
||||
@@ -104,7 +105,8 @@ export function resolveProps(
|
||||
|
||||
const { 0: options, 1: needCastKeys } = normalizePropsOptions(_options)!
|
||||
const props: Data = {}
|
||||
let attrs: Data | undefined = void 0
|
||||
let attrs: Data | undefined = undefined
|
||||
let vnodeHooks: Data | undefined = undefined
|
||||
|
||||
// update the instance propsProxy (passed to setup()) to trigger potential
|
||||
// changes
|
||||
@@ -123,21 +125,28 @@ export function resolveProps(
|
||||
|
||||
if (rawProps != null) {
|
||||
for (const key in rawProps) {
|
||||
const value = rawProps[key]
|
||||
// key, ref are reserved and never passed down
|
||||
if (key === 'key' || key === 'ref') continue
|
||||
if (isReservedProp(key)) {
|
||||
if (key !== 'key' && key !== 'ref') {
|
||||
// vnode hooks.
|
||||
;(vnodeHooks || (vnodeHooks = {}))[key] = value
|
||||
}
|
||||
continue
|
||||
}
|
||||
// prop option names are camelized during normalization, so to support
|
||||
// kebab -> camel conversion here we need to camelize the key.
|
||||
if (hasDeclaredProps) {
|
||||
const camelKey = camelize(key)
|
||||
if (hasOwn(options, camelKey)) {
|
||||
setProp(camelKey, rawProps[key])
|
||||
setProp(camelKey, value)
|
||||
} else {
|
||||
// Any non-declared props are put into a separate `attrs` object
|
||||
// for spreading. Make sure to preserve original key casing
|
||||
;(attrs || (attrs = {}))[key] = rawProps[key]
|
||||
;(attrs || (attrs = {}))[key] = value
|
||||
}
|
||||
} else {
|
||||
setProp(key, rawProps[key])
|
||||
setProp(key, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -206,6 +215,7 @@ export function resolveProps(
|
||||
|
||||
instance.props = props
|
||||
instance.attrs = options ? attrs || EMPTY_OBJ : props
|
||||
instance.vnodeHooks = vnodeHooks || EMPTY_OBJ
|
||||
}
|
||||
|
||||
const normalizationMap = new WeakMap<
|
||||
|
||||
Reference in New Issue
Block a user