fix(runtime-core): always check props presence in public instance proxy

When the there are props merged from mixins or extends, the component itself
may not have a props property.

fix #1236 where merged props are not exposed in production
This commit is contained in:
Evan You 2020-06-26 10:19:07 -04:00
parent 5453e791ae
commit e0d19a6953

View File

@ -222,6 +222,7 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
// is the multiple hasOwn() calls. It's much faster to do a simple property // is the multiple hasOwn() calls. It's much faster to do a simple property
// access on a plain object, so we use an accessCache object (with null // access on a plain object, so we use an accessCache object (with null
// prototype) to memoize what access type a key corresponds to. // prototype) to memoize what access type a key corresponds to.
let normalizedProps
if (key[0] !== '$') { if (key[0] !== '$') {
const n = accessCache![key] const n = accessCache![key]
if (n !== undefined) { if (n !== undefined) {
@ -245,8 +246,8 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
} else if ( } else if (
// only cache other properties when instance has declared (thus stable) // only cache other properties when instance has declared (thus stable)
// props // props
type.props && (normalizedProps = normalizePropsOptions(type)[0]) &&
hasOwn(normalizePropsOptions(type)[0]!, key) hasOwn(normalizedProps, key)
) { ) {
accessCache![key] = AccessTypes.PROPS accessCache![key] = AccessTypes.PROPS
return props![key] return props![key]
@ -352,11 +353,13 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
}: ComponentRenderContext, }: ComponentRenderContext,
key: string key: string
) { ) {
let normalizedProps
return ( return (
accessCache![key] !== undefined || accessCache![key] !== undefined ||
(data !== EMPTY_OBJ && hasOwn(data, key)) || (data !== EMPTY_OBJ && hasOwn(data, key)) ||
(setupState !== EMPTY_OBJ && hasOwn(setupState, key)) || (setupState !== EMPTY_OBJ && hasOwn(setupState, key)) ||
(type.props && hasOwn(normalizePropsOptions(type)[0]!, key)) || ((normalizedProps = normalizePropsOptions(type)[0]) &&
hasOwn(normalizedProps, key)) ||
hasOwn(ctx, key) || hasOwn(ctx, key) ||
hasOwn(publicPropertiesMap, key) || hasOwn(publicPropertiesMap, key) ||
hasOwn(appContext.config.globalProperties, key) hasOwn(appContext.config.globalProperties, key)