Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(reactivity): trigger reactivity for Map key undefined #12055

Merged
merged 2 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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