Skip to content

Setting a store to undefined and then trying to use it in a rune throws state_unsafe_mutation error #12558

Closed
@ndom91

Description

@ndom91

Describe the bug

Previously, in Svelte 4, you used to be able to set a variable to undefined and later set it to a store and meanwhile use it in reactive statements. While not ideal, this used to work.

In svelte 5 if you do something similar it'll throw the state_unsafe_mutation error. See reproduction below. It's probably right to error in this case, but the error is very misleading we spent hours trying to track it down yesterday 😅

Maybe for some context, our before / after:

Before

const prs = $derived($hostedListingServiceStore?.prs);
const listedPr = $derived($prs?.find((pr) => pr.sourceBranch === branch.upstreamName));

After

const prStore = $derived($hostedListingServiceStore?.prs);
const prs = $derived(prStore ? $prStore : undefined);
const listedPr = $derived(prs?.find((pr) => pr.sourceBranch === branch.upstreamName));

Reproduction

https://svelte-5-preview.vercel.app/#H4sIAAAAAAAAE1WMzQqDMBCEXyUsHloQeven0GfosenBmrFdMJuQrIKI7148FOlxZr5vVhp4RKbqsZJ0HlTRLUYqSZe4hzxjVFBJOUyp35sm94mjXq1YHaHGd8sLdw0JpjWTOAwscPU-90HyDwge-mF5m9YUDolnuFNxuOfaSnM5rsXKWvybG5Xkg-OB4ajSNGF7bl-Xn5hLwAAAAA==

Logs

No response

System Info

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