Skip to content

Commit 1b2149d

Browse files
committed
fix(reactivity): should not observe frozen objects
fix #867
1 parent 0dc2478 commit 1b2149d

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

packages/reactivity/__tests__/reactive.spec.ts

+7
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,13 @@ describe('reactivity/reactive', () => {
155155
expect(isReactive(obj.bar)).toBe(false)
156156
})
157157

158+
test('should not observe frozen objects', () => {
159+
const obj = reactive({
160+
foo: Object.freeze({ a: 1 })
161+
})
162+
expect(isReactive(obj.foo)).toBe(false)
163+
})
164+
158165
describe('shallowReactive', () => {
159166
test('should not make non-reactive properties reactive', () => {
160167
const props = shallowReactive({ n: { foo: 1 } })

packages/reactivity/src/reactive.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ const canObserve = (value: any): boolean => {
3333
!value._isVue &&
3434
!value._isVNode &&
3535
isObservableType(toRawType(value)) &&
36-
!nonReactiveValues.has(value)
36+
!nonReactiveValues.has(value) &&
37+
!Object.isFrozen(value)
3738
)
3839
}
3940

0 commit comments

Comments
 (0)