Skip to content

Commit

Permalink
fix(reactivity): trigger reactivity for Map key undefined (#12055)
Browse files Browse the repository at this point in the history
close #12054
  • Loading branch information
jh-leong authored Oct 11, 2024
1 parent c0418a3 commit 7ad289e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions packages/reactivity/__tests__/reactive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
2 changes: 1 addition & 1 deletion packages/reactivity/src/dep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down

0 comments on commit 7ad289e

Please sign in to comment.