From 7611ea6033db64f1b0242bb0a07f274b15c322e5 Mon Sep 17 00:00:00 2001 From: Samuel Degueldre Date: Fri, 18 Mar 2022 13:33:03 +0100 Subject: [PATCH] [FIX] reactivity: do not crash when reading reactive frozen objects This crash was caused by the fact that Proxies *must* return the value of the property on the target when that property is non-writeable and non-configurable. Since the reactivity system always attempts to proxify the value from the target, this crashes. This commit fixes that by not proxifying such values. This however means that from that point on, we have escaped the reactivity system and will not subscribe to any changes in that object or its children. --- src/reactivity.ts | 5 +++++ tests/reactivity.test.ts | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/src/reactivity.ts b/src/reactivity.ts index 29937005..86aede0d 100644 --- a/src/reactivity.ts +++ b/src/reactivity.ts @@ -232,6 +232,11 @@ function basicProxyHandler(callback: Callback): ProxyHandler { expect(n).toBe(1); expect(state.k).toEqual({ n: 2 }); }); + + test("can access properties on reactive of frozen objects", async () => { + const obj = Object.freeze({ a: {} }); + const state = createReactive(obj); + expect(() => state.a).not.toThrow(); + expect(state.a).toBe(obj.a); + }); }); describe("Collections", () => {