fix(runtime-core): cache props default values to avoid unnecessary watcher trigger (#3474)
fix #3471
This commit is contained in:
@@ -139,6 +139,9 @@ export function initProps(
|
||||
const props: Data = {}
|
||||
const attrs: Data = {}
|
||||
def(attrs, InternalObjectKey, 1)
|
||||
|
||||
instance.propsDefaults = Object.create(null)
|
||||
|
||||
setFullProps(instance, rawProps, props, attrs)
|
||||
// validation
|
||||
if (__DEV__) {
|
||||
@@ -326,9 +329,14 @@ function resolvePropValue(
|
||||
if (hasDefault && value === undefined) {
|
||||
const defaultValue = opt.default
|
||||
if (opt.type !== Function && isFunction(defaultValue)) {
|
||||
setCurrentInstance(instance)
|
||||
value = defaultValue(props)
|
||||
setCurrentInstance(null)
|
||||
const { propsDefaults } = instance
|
||||
if (key in propsDefaults) {
|
||||
value = propsDefaults[key]
|
||||
} else {
|
||||
setCurrentInstance(instance)
|
||||
value = propsDefaults[key] = defaultValue(props)
|
||||
setCurrentInstance(null)
|
||||
}
|
||||
} else {
|
||||
value = defaultValue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user