[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.
This commit is contained in:
Samuel Degueldre
2022-03-18 13:33:03 +01:00
committed by Géry Debongnie
parent c7d515a6b3
commit 7611ea6033
2 changed files with 12 additions and 0 deletions
+7
View File
@@ -1095,6 +1095,13 @@ describe("Reactivity", () => {
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", () => {