Skip to content

Svelte 5: state_unsafe_mutation Updating state inside a derived is forbidden. If the value should not be reactive, declare it without $state #12571

Closed
@niemyjski

Description

@niemyjski

Describe the bug

After upgrading from 193 to latest I started to get the following error message when I use derived.

state_unsafe_mutation Updating state inside a derived is forbidden. If the value should not be reactive, declare it without $state

This seems like a bug because looking at the component source there is no updating inside of a derived value or in my $derived: https://github.com/svecosystem/runed/blob/main/packages/runed/src/lib/utilities/MediaQuery/MediaQuery.svelte.ts#L60

Reproduction

https://svelte-5-preview.vercel.app/#H4sIAAAAAAAACo2QQU_DMAyF_4qxJrWTygaIU7cOcQcJtCPhkDXuFqlNoiTdmKr8dxTaQatduMX2y3v212Ela3KYf3SoeEOY47MxmKE_m1i4I9WeMEOnW1vGztqVVhq_YYp52RhtPXTwSkLy95bsGQJUVjeQ2FaRSFYj2VYK2nE7zBfLoV70GUlUMgVQauU8SPfC7Z62pSVSvXMBik6jqDRJG6luT1L4Qw73dw-P5muezFdMrZd_S6r1JXdiWXTXCYuG-_JALsBygxk2WshKksDc25ZC9ktoMPwHJai52hcMvWO4iccBSOXJVrwkeLPaOOj69s9ovNFTDjuta-Jq1StCPCY-aorIJ2II-WBXwMzERzofvvU43UGfLhwKmAmy8kgivZm4XKGbZhQwZRaYmtp2ozJcA_wM37tto4xuAgAA

Logs

at state_unsafe_mutation (http://localhost:5173/next/node_modules/.vite/deps/chunk-PNZBZ7D7.js?v=28b39c12:187:19)
    at set (http://localhost:5173/next/node_modules/.vite/deps/chunk-PNZBZ7D7.js?v=28b39c12:1901:5)
    at get matches (http://localhost:5173/next/node_modules/.vite/deps/runed.js?v=28b39c12:602:7)
    at get isLargeScreen (http://localhost:5173/next/src/routes/(app)/+layout.svelte?t=1721699576709:182:27)
    at http://localhost:5173/next/src/routes/(app)/(components)/layouts/Sidebar.svelte?t=1721699576709:42:47
    at update_reaction (http://localhost:5173/next/node_modules/.vite/deps/chunk-PNZBZ7D7.js?v=28b39c12:1276:23)


### System Info

```shell
System:
    OS: Windows 11 10.0.22631
    CPU: (24) x64 AMD Ryzen 9 5900X 12-Core Processor
    Memory: 9.11 GB / 31.91 GB
  Binaries:
    Node: 22.5.1 - C:\Program Files\nodejs\node.EXE
    npm: 10.6.0 - ~\AppData\Roaming\npm\npm.CMD
    pnpm: 9.5.0 - C:\ProgramData\chocolatey\bin\pnpm.EXE
  Browsers:
    Edge: Chromium (126.0.2592.113)
    Internet Explorer: 11.0.22621.3527

Severity

blocking all usage of svelte

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