fix(reactivity): should not observe frozen objects

fix #867
This commit is contained in:
Evan You 2020-03-23 11:28:20 -04:00
parent 0dc2478569
commit 1b2149dbb2
2 changed files with 9 additions and 1 deletions

View 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 } })

View 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)
)
}