Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 opened this issue Jul 24, 2024 · 2 comments

Comments

@niemyjski
Copy link

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

niemyjski added a commit to exceptionless/Exceptionless that referenced this issue Jul 24, 2024
@paoloricciuti
Copy link
Member

As you can see the getter you are accessing is actually updating #matches both in the case the effect has not been registered yet or if effect.tracking is false.

Since it's the first time that setter is accessed you are getting this error because it's actually accessing state. So this could be a bug of the implementation in runed (that was my idea so blame me eventually lol). At the same time this feels like something it should be possible to solve. I'll think about this a bit.

@trueadm
Copy link
Contributor

trueadm commented Jul 24, 2024

This looks like a bug in runed. They're mutating state in the getter, which feels a bit off here – or it should be tracked. Either way, It's not a Svelte 5 bug so closing :)

@trueadm trueadm closed this as completed Jul 24, 2024
niemyjski added a commit to exceptionless/Exceptionless that referenced this issue Jul 30, 2024
* Updated to svelte5 dep

* added link resources

* updated client hooks

* Commented out legos

* removed unused code

* added temp tanstack svelte5 adaptor from pr

* WIP rework data tables for svelte5

* Updated svelte

* Temp impl for svelte persisted store

https://twitter.com/puruvjdev/status/1787037268143689894/photo/1
joshnuss/svelte-persisted-store#251

* WIP Runes

* More svelte 5 conversion

* Updated package json

* WIP Svelte 5 work

* Upgraded typography components to runes and use new snippets and props

* More runes work

* More Svelte 5 work

* Updated facet filters to runes

* Upgraded to @exceptionless/fetchclient

* Updated deps

* Upgraded to latest fetch client

* Updated shad

* Upgrade to eslint 9

https://github.com/sveltejs/kit/pull/12268/files

* fixed invalid ref

* Converted slots

* Updated deps

* Added some snippets

* WIP Dashboard

* Updated tailwind

* Fixed copy

* Fixed slots

* Updated deps

* Updated data tables and summaries

* More conversion

* Updated deps

* Converted all components to runes

* Some dispatch changes

* WIP: Dispatch Changes

* Updated deps

* more dispatch work

* Fixed linting errors

* Updated svelte

* Updated shad

* Updated typescript

* Updated deps

* Fixed fetch client

* Fixed svelte errors.

* added conditional icon check

* Update deps

* WIP: Use svelte-query-runes

TanStack/query#6981

* WIP - Reworked snippets and some other fixes.

* Updated deps

* WIP - Svelte 5 work

* Updated deps

* Updated to latest tanstack table

* WIP: Filter runes work.

* Fixed more errors.

* Updated deps

* Use svelte query pkg

* Updated svelte and vitest

* Fixed svelte query issues, fixed linting issues, fixed eventing.

* Fixed web socket events

* Updated deps

* Fixed some filtering issues

* Fixed persisted store

* Updated packages

* Fixed filter reactivity

* Updated deps

* Updated deps

* fixed svelte query issues

* Use runed media query

* Update deps

* Use runed media query

* Fixed svelte issue with state_unsafe_mutation

sveltejs/svelte#12571

* Ensure all runes are serialized with toJSON

sveltejs/svelte#9639

* Added document visibility store and fixed more upgrades

* Updated deps

* Updated queries

* WIP: Demoting tabs

* Updated deps

* Updates to tab promotion

* Fixed bind warnings

* Updated deps

* Use new svelte query apis

* Updated deps

* Fixed stack promotion

* Fixed grid issues

* Fixed fetch client issues with the login forms

* Added custom auth serializer

* Force package install due to svelte 5 peer deps

* rebuilt lock file

* Update Document Visibility helper to match new runed pattern
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants