]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(reactivity): should not observe frozen objects
authorEvan You <yyx990803@gmail.com>
Mon, 23 Mar 2020 15:28:20 +0000 (11:28 -0400)
committerEvan You <yyx990803@gmail.com>
Mon, 23 Mar 2020 15:28:20 +0000 (11:28 -0400)
fix #867

packages/reactivity/__tests__/reactive.spec.ts
packages/reactivity/src/reactive.ts

index 5d8876843b14c2895fe9bbd4bd44dff02816bda0..9f71673401020c9afd0daaa6f37a03b8eee993a8 100644 (file)
@@ -155,6 +155,13 @@ describe('reactivity/reactive', () => {
     expect(isReactive(obj.bar)).toBe(false)
   })
 
+  test('should not observe frozen objects', () => {
+    const obj = reactive({
+      foo: Object.freeze({ a: 1 })
+    })
+    expect(isReactive(obj.foo)).toBe(false)
+  })
+
   describe('shallowReactive', () => {
     test('should not make non-reactive properties reactive', () => {
       const props = shallowReactive({ n: { foo: 1 } })
index 5f8aa5797254ad0da1ae5533cdd18e0abdd7984a..a6f21aadd8ee5204ede499376153f5a36f35f56a 100644 (file)
@@ -33,7 +33,8 @@ const canObserve = (value: any): boolean => {
     !value._isVue &&
     !value._isVNode &&
     isObservableType(toRawType(value)) &&
-    !nonReactiveValues.has(value)
+    !nonReactiveValues.has(value) &&
+    !Object.isFrozen(value)
   )
 }