]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(reactivity): trigger reactivity for Map key `undefined` (#12055)
authorTycho <jh.leong@outlook.com>
Fri, 11 Oct 2024 02:39:08 +0000 (10:39 +0800)
committerGitHub <noreply@github.com>
Fri, 11 Oct 2024 02:39:08 +0000 (10:39 +0800)
close #12054

packages/reactivity/__tests__/reactive.spec.ts
packages/reactivity/src/dep.ts

index 47f6aa297ecb762994a213cbd48ac8e40af9795a..aabd954568afcc627fd44ef45cbaee2a0bcdbf10 100644 (file)
@@ -409,4 +409,14 @@ describe('reactivity/reactive', () => {
     e.effect.stop()
     expect(targetMap.get(obj)?.get('x')).toBeFalsy()
   })
+
+  test('should trigger reactivity when Map key is undefined', () => {
+    const map = reactive(new Map())
+    const c = computed(() => map.get(void 0))
+
+    expect(c.value).toBe(void 0)
+
+    map.set(void 0, 1)
+    expect(c.value).toBe(1)
+  })
 })
index 7e404874348a5d4b401b43de2d1279a60a7d87ae..196c2aaf98ed7a2c372c1e82c6df0c4974d5d7cb 100644 (file)
@@ -340,7 +340,7 @@ export function trigger(
       })
     } else {
       // schedule runs for SET | ADD | DELETE
-      if (key !== void 0) {
+      if (key !== void 0 || depsMap.has(void 0)) {
         run(depsMap.get(key))
       }