diff --git a/src/runtime/reactivity.ts b/src/runtime/reactivity.ts index 210e38ec..43ae74b9 100644 --- a/src/runtime/reactivity.ts +++ b/src/runtime/reactivity.ts @@ -368,7 +368,7 @@ function delegateAndNotify( if (hadKey !== hasKey) { notifyReactives(target, KEYCHANGES); } - if (originalValue !== value) { + if (originalValue !== target[getterName](key)) { notifyReactives(target, key); } return ret; diff --git a/tests/reactivity.test.ts b/tests/reactivity.test.ts index 9d67f1d5..ed6ef775 100644 --- a/tests/reactivity.test.ts +++ b/tests/reactivity.test.ts @@ -1292,6 +1292,12 @@ describe("Collections", () => { state.add(3); // setting unobserved key doesn't notify expect(observer).toHaveBeenCalledTimes(3); + expect(state.has(3)).toBe(true); // subscribe to 3 + state.add(3); // adding observed key doesn't notify if key was already present + expect(observer).toHaveBeenCalledTimes(3); + expect(state.has(4)).toBe(false); // subscribe to 4 + state.delete(4); // deleting observed key doesn't notify if key was already not present + expect(observer).toHaveBeenCalledTimes(3); }); test("iterating on keys returns reactives", async () => { @@ -1485,6 +1491,12 @@ describe("Collections", () => { state.set(3, 4); // setting unobserved key doesn't notify expect(observer).toHaveBeenCalledTimes(3); + expect(state.has(3)).toBe(true); // subscribe to 3 + state.set(3, 4); // setting the same value doesn't notify + expect(observer).toHaveBeenCalledTimes(3); + expect(state.has(4)).toBe(false); // subscribe to 4 + state.delete(4); // deleting observed key doesn't notify if key was already not present + expect(observer).toHaveBeenCalledTimes(3); }); test("checking for a key with 'get' subscribes the callback to changes to that key", () => { @@ -1510,6 +1522,12 @@ describe("Collections", () => { state.set(3, 4); // setting unobserved key doesn't notify expect(observer).toHaveBeenCalledTimes(3); + expect(state.get(3)).toBe(4); // subscribe to 3 + state.set(3, 4); // setting the same value doesn't notify + expect(observer).toHaveBeenCalledTimes(3); + expect(state.get(4)).toBe(undefined); // subscribe to 4 + state.delete(4); // deleting observed key doesn't notify if key was already not present + expect(observer).toHaveBeenCalledTimes(3); }); test("getting values returns a reactive", async () => {