]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-core): check if the key is string on undefined property warning (#1731)
authorCarlos Rodrigues <david-181@hotmail.com>
Wed, 29 Jul 2020 14:06:36 +0000 (15:06 +0100)
committerGitHub <noreply@github.com>
Wed, 29 Jul 2020 14:06:36 +0000 (10:06 -0400)
packages/runtime-core/__tests__/componentProxy.spec.ts
packages/runtime-core/src/componentProxy.ts

index 02cc5f5f4e505e987f3c9d98aad540c05b0f9e9c..f37bfe3d9d86f60af54e3063ccb05e0d935a4d19 100644 (file)
@@ -217,4 +217,24 @@ describe('component: proxy', () => {
       `was accessed during render but is not defined`
     ).not.toHaveBeenWarned()
   })
+
+  test('should allow symbol to access on render', () => {
+    const Comp = {
+      render() {
+        if ((this as any)[Symbol.unscopables]) {
+          return '1'
+        }
+        return '2'
+      }
+    }
+
+    const app = createApp(Comp)
+    app.mount(nodeOps.createElement('div'))
+
+    expect(
+      `Property ${JSON.stringify(
+        Symbol.unscopables
+      )} was accessed during render ` + `but is not defined on instance.`
+    ).toHaveBeenWarned()
+  })
 })
index e043d93eb4b6cf610da333189d97986c0d4d8fac..84f14ce462a3af3633253d0d6b70be04dab75da0 100644 (file)
@@ -6,7 +6,8 @@ import {
   hasOwn,
   isGloballyWhitelisted,
   NOOP,
-  extend
+  extend,
+  isString
 } from '@vue/shared'
 import {
   ReactiveEffect,
@@ -286,9 +287,10 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
     } else if (
       __DEV__ &&
       currentRenderingInstance &&
-      // #1091 avoid internal isRef/isVNode checks on component instance leading
-      // to infinite warning loop
-      key.indexOf('__v') !== 0
+      (!isString(key) ||
+        // #1091 avoid internal isRef/isVNode checks on component instance leading
+        // to infinite warning loop
+        key.indexOf('__v') !== 0)
     ) {
       if (data !== EMPTY_OBJ && key[0] === '$' && hasOwn(data, key)) {
         warn(