- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 2.1k
 
Description
Describe the bug
Having multiple async $deriveds in a page's script tag will cause a state_unsafe_mutation error (in addition to this Svelte error: sveltejs/svelte#16596). I am unable to reproduce it in plain Svelte, so I think it may be related to SvelteKit's navigation.
For some reason a single async $derived is fine. Initial page load is also fine.
I'm unsure what the exact consequences of this error are, because upgrading my existing SK application to async svelte + remote functions has exposed at least a half dozen bugs and it's hard to separate the consequences from each other. However my application is having the results of remote function calls derived from page.params lagging 1 page behind, so I'm guessing that may be the state that SK is updating on navigation that is triggering this error. Though the specific line from the stack trace is from setting navigating.
Reproduction
Smallest reproduction I could fine:
Navigate between / and /page2 using the links on the page. Observe and state_unsafe_mutation error in the console.
Logs
Uncaught (in promise) Svelte error: state_unsafe_mutation
Updating state inside `$derived(...)`, `$inspect(...)` or a template expression is forbidden. If the value should not be reactive, declare it without `$state`
https://svelte.dev/e/state_unsafe_mutation
    state_unsafe_mutation chunk-5IEL6O5J.js:448
    set chunk-5IEL6O5J.js:1367
    set error state.svelte.js:55
    navigate client.js:1682
    _start_router client.js:2452
    setTimeout handler*_start_router/</</< client.js:2446
    _start_router client.js:2445
    _start_router client.js:2444System Info
System:
    OS: Linux 6.15 Arch Linux
    CPU: (12) x64 AMD Ryzen 5 2600 Six-Core Processor
    Memory: 6.60 GB / 15.54 GB
    Container: Yes
    Shell: 5.3.3 - /bin/bash
  Binaries:
    Node: 22.17.0 - ~/.nvm/versions/node/v22.17.0/bin/node
    Yarn: 1.22.22 - /usr/bin/yarn
    npm: 10.9.2 - ~/.nvm/versions/node/v22.17.0/bin/npm
    pnpm: 10.13.1 - ~/.local/share/pnpm/pnpm
  Browsers:
    Chromium: 139.0.7258.66
  npmPackages:
    @sveltejs/adapter-auto: ^6.0.0 => 6.0.1 
    @sveltejs/kit: ^2.27.3 => 2.27.3 
    @sveltejs/vite-plugin-svelte: ^5.0.0 => 5.1.1 
    svelte: ^5.38.1 => 5.38.1 
    vite: ^6.2.6 => 6.3.5Severity
blocking an upgrade
Additional Information
No response