diff --git a/packages/reactivity/__tests__/reactive.spec.ts b/packages/reactivity/__tests__/reactive.spec.ts index 5d8876843b1..9f716734010 100644 --- a/packages/reactivity/__tests__/reactive.spec.ts +++ b/packages/reactivity/__tests__/reactive.spec.ts @@ -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 } }) diff --git a/packages/reactivity/src/reactive.ts b/packages/reactivity/src/reactive.ts index 5f8aa579725..a6f21aadd8e 100644 --- a/packages/reactivity/src/reactive.ts +++ b/packages/reactivity/src/reactive.ts @@ -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) ) }