Open
Description
Describe the bug
Getting a state_unsafe_mutation
error for the following piece of code. To me it feels like nothing is inherently wrong with it.
Surprisingly enough we are using this pattern a lot and everything worked fine. However today I've decided to force runes mode through svelte.config.js
and a lot of things got crashed with this error.
Reproduction
<script>
import { SvelteMap } from 'svelte/reactivity'
const source = ['hey', 'ho']
const computed = $derived.by(() => {
const map = new SvelteMap()
for (const item of source) {
map.set(item, item)
}
return map
})
</script>
{#each computed.values() as item}
{item}
{/each}
Working REPL - this is how we use it in our codebase and it seems to work until you do compilerOptions: { runes: true }
.
<!-- App.svelte -->
<script>
import { Model } from './Model.svelte.js'
const model = new Model()
</script>
{#each model.computed.values() as item}
{item}
{/each}
// Model.svelte.js
import { SvelteMap } from 'svelte/reactivity'
export class Model {
source = ['hey', 'ho']
computed = $derived.by(() => {
const map = new SvelteMap()
for (const item of this.source) {
map.set(item, item)
}
return map
})
}
Logs
System Info
irrelevant
Severity
annoyance
Metadata
Metadata
Assignees
Labels
No labels