Skip to content

SvelteSet is not reactive #15454

@caboe

Description

@caboe

Describe the bug

I am not sure, if this is intended, but to me this behavior is very strange:

  • create a variable with the state rune and a SvelteMap as value
  • add a react rune to trigger some side effects. The changes will not be tracked, but if you wrap it with Array.from, it will.
<script>
	import { SvelteSet } from "svelte/reactivity"
	let fruits = $state(new SvelteSet(['foo', 'bar']))

	/* does not work */
	$effect(() => {
		console.log("effect", fruits)
	});

	/* works */
	$effect(() => {
		console.log("effect with Array", Array.from(fruits))
	});
</script>


<h1>Hello {JSON.stringify(Array.from(fruits))}!</h1>
<button onclick={()=>fruits.add('banana')}>Banana!</button>

Reproduction

Playground: https://svelte.dev/playground/58e91fc3d5e14fd3b08b864629c45e1c?version=5.22.4#H4sIAAAAAAAAE5WQMW_CMBCF_8pxQoojRYlYaRKJTlWHdqAbZjDhAhbBjuwDGkX575UJKAtLt9PT-74nu0ejzoRLXF-pYVoTww95xgRr3ZDH5aZH7trQCAEmz_6qbVN_ZzDBnfL0Kq-sYTLscYm5r5xuuZRGsj631jH0MI0OUDt7BokjmzlSFeur5k5iQBpiqN1Fs4cC5p4VkzB0mwxiE9XWRglEO-WibRxLE7gs21vyYCzDzbpTiOZU11SxEDEUJfQhklxZ421DaWMPQuLYkJg8NoOMh_jt6Qwq_y8X3DQfYeWc6oL2fqThyeKxME3k2fRVRpr8uCg_qGks9J_r76_Us9PmoOtOvJAMszw7Lkpp8t2F2Rqwpmp0dSp6ERfl2ErVfi-inTLKqCgeyvf7NcuzESkxQaZfxiW7Cw3b4Q_D0wPhIwIAAA==

Logs

System Info

System:
    OS: macOS 14.5
    CPU: (10) arm64 Apple M2 Pro
    Memory: 154.13 MB / 32.00 GB
    Shell: 3.6.1 - /usr/local/bin/fish
  Binaries:
    Node: 22.10.0 - ~/.local/share/nvm/v22.10.0/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.9.0 - ~/.local/share/nvm/v22.10.0/bin/npm
    pnpm: 8.7.6 - /usr/local/bin/pnpm
    bun: 1.0.13 - ~/.bun/bin/bun
  Browsers:
    Chrome: 133.0.6943.142
    Edge: 133.0.3065.92
    Firefox Nightly: 137.0a1
    Safari: 17.5
  npmPackages:
    svelte: ^5.17.0 => 5.17.0

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