]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-core): always check props presence in public instance proxy
authorEvan You <yyx990803@gmail.com>
Fri, 26 Jun 2020 14:19:07 +0000 (10:19 -0400)
committerEvan You <yyx990803@gmail.com>
Fri, 26 Jun 2020 14:19:07 +0000 (10:19 -0400)
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

packages/runtime-core/src/componentProxy.ts

index f1aeece4e559374167108e4526d4a2b897b7fd98..400e552158390de098de82535a0caf1a4aec6844 100644 (file)
@@ -222,6 +222,7 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
     // 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
     // prototype) to memoize what access type a key corresponds to.
+    let normalizedProps
     if (key[0] !== '$') {
       const n = accessCache![key]
       if (n !== undefined) {
@@ -245,8 +246,8 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
       } else if (
         // only cache other properties when instance has declared (thus stable)
         // props
-        type.props &&
-        hasOwn(normalizePropsOptions(type)[0]!, key)
+        (normalizedProps = normalizePropsOptions(type)[0]) &&
+        hasOwn(normalizedProps, key)
       ) {
         accessCache![key] = AccessTypes.PROPS
         return props![key]
@@ -352,11 +353,13 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
     }: ComponentRenderContext,
     key: string
   ) {
+    let normalizedProps
     return (
       accessCache![key] !== undefined ||
       (data !== EMPTY_OBJ && hasOwn(data, 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(publicPropertiesMap, key) ||
       hasOwn(appContext.config.globalProperties, key)