Skip to content

Map.set() doesn't trigger reactivity #15230

@JakeBeaver

Description

@JakeBeaver

Describe the bug

It was my understanding that we want mutating a map to also trigger reactivity.
Whether by design or by bug, this doesn't work now

<script>
	let a = $state(new Map())
	let count = $state(1);

	// this doesn't go beyond "init"
	$inspect(a);

	function onclick(){
		a.set(count, count);		
		count++;
		
		// uncomment below to fix
		// a = new Map(a);
	}
</script>

<button {onclick}>{count}</button>

<!-- this stays empty -->
{[...a.keys()]}

Reproduction

https://svelte.dev/playground/hello-world?version=5.19.8#H4sIAAAAAAAACm2QzWrDMBCEX2UrArWJf-jVcQO99dIniHKQ5U0rIq9EtG5ijN-9KKqbSy8CfTPL7OwsSA0oGvGO1jq4uovtIcPeMPa5KMTJWAyiOcyCJx99EYhinXrzvgrfaDmyTgX8j2tHjMRBNKIN-mI87yVJtsig4BU2gRVjRniFD-WzPF9F7Ubih-El30mKWl0Df5kAvcNAzwyfDjqcHPUghSHDUkTXxlDwqDlT69xpJM3GETjS1uhzls8RS1ZVQM7ucUVKzXeRJ_UOtttd-qW3rmEk7YYBiaFD667ADk7m9ifHZmultAEvktr6cQBqu5HZEcy_-yz7-Z61tHVSkuupLFPfwGoKgIPnCcpyL2k-VFWlqjNOIcuPiyRRCMYbi4YvIy7H5QdFgQz43gEAAA==

Logs

System Info

repl

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions