From 6037018dd27b5f25aa10c88528f8dca12b7b9281 Mon Sep 17 00:00:00 2001 From: FrancoisGe Date: Thu, 12 Oct 2023 09:47:44 +0200 Subject: [PATCH] [FIX] reactivity: don't react when we set the same object The purpose of this commit is to not notify reactivity when an object is replaced by the same object (same reference) in an reactive object. --- src/runtime/reactivity.ts | 2 +- tests/reactivity.test.ts | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/runtime/reactivity.ts b/src/runtime/reactivity.ts index 43ae74b9..9588d6cc 100644 --- a/src/runtime/reactivity.ts +++ b/src/runtime/reactivity.ts @@ -249,7 +249,7 @@ function basicProxyHandler(callback: Callback): ProxyHandler { const obj2 = createReactive({ b: {} }, () => n2++); const obj3 = createReactive({ c: {} }, () => n3++); + // assign the same object should'nt notify reactivity obj2.b = obj2.b; obj2.b; obj3.c = obj3.c; obj3.c; expect(n1).toBe(0); - expect(n2).toBe(1); - expect(n3).toBe(1); + expect(n2).toBe(0); + expect(n3).toBe(0); obj2.b = obj1; obj2.b; obj3.c = obj1; obj3.c; expect(n1).toBe(0); - expect(n2).toBe(2); - expect(n3).toBe(2); + expect(n2).toBe(1); + expect(n3).toBe(1); obj1.a = obj1.a + 2; obj1.a; expect(n1).toBe(1); - expect(n2).toBe(2); - expect(n3).toBe(2); + expect(n2).toBe(1); + expect(n3).toBe(1); obj2.b.a = obj2.b.a + 1; expect(n1).toBe(2); - expect(n2).toBe(3); - expect(n3).toBe(2); + expect(n2).toBe(2); + expect(n3).toBe(1); }); test("reactive inside other: reading the inner reactive from outer doesn't affect the inner's subscriptions", async () => {