From d82ebf9d419a8fce4c4c0274e47b25bbcf603ba5 Mon Sep 17 00:00:00 2001 From: tycho Date: Fri, 27 Sep 2024 16:55:34 +0800 Subject: [PATCH] fix(reactivity): trigger reactivity for Map key `undefined` --- packages/reactivity/__tests__/reactive.spec.ts | 10 ++++++++++ packages/reactivity/src/dep.ts | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/reactivity/__tests__/reactive.spec.ts b/packages/reactivity/__tests__/reactive.spec.ts index 47f6aa297ec..aabd954568a 100644 --- a/packages/reactivity/__tests__/reactive.spec.ts +++ b/packages/reactivity/__tests__/reactive.spec.ts @@ -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) + }) }) diff --git a/packages/reactivity/src/dep.ts b/packages/reactivity/src/dep.ts index e7e9672dc9e..c626dff2c76 100644 --- a/packages/reactivity/src/dep.ts +++ b/packages/reactivity/src/dep.ts @@ -342,7 +342,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)) }