Skip to content

$derived doesn't update derived values when used with a store containing an object. #14772

@tomconnors

Description

@tomconnors

Describe the bug

When using $derived to get the value from a store containing an object, updates to the stored value don't cause the derived value to update. I suspect this is not by design, because $effect does handle those updates appropriately. If this is a known limitation, perhaps it should be mentioned in the docs.

Can work around by copying the object with Object.assign.

// This doesn't work:
let x = $derived($myObjectStore);
// This works:
let x = $derived(Object.assign({}, $myObjectStore));

Reproduction

https://svelte.dev/playground/hello-world?version=5.14.4#H4sIAAAAAAAAE41Sy26DMBD8lZUVKUZBpL2SEKnqpf9QeiBm09KaNbKXJBXyv1eGhIQ-oh49s-P1zLgTVNQoUvGEWhs4GKtLkFhWjGUkYrGrNDqRPneCP5swFwARn1UPTZO4PWoO2LZw-BuuDDESO5GKtVO2aniTU85V3RjL8GhaYrSws6aGebI8nU_y-Sqn9fKiovV5frm5dRCxYDyySNm26OM_nj_dNbXwg7ttowMVBOBHI-6tsFgm7y54yFkjg4IMZiXaao-lnPWCaCTpmlQJXZj6miFYwP3AzXC3Q8VSRtmmC0DOypAzGhNtXmUuhhW5iOG0LAz56Huk25bZEBhSulIfWScjyDaDn6RtyoJRShN2gElosViBRW4tgVn5yPch9EKXQkc-hq72YcNw67-7GOOa1nANXzUwpn6wFRdbjWPwQ19Lx8b2vycnPPazfQF9R9mokh2lcOdDnNNXvvgvf8s4ARoDAAA=

Logs

No response

System Info

System:
    OS: macOS 15.0
    CPU: (8) x64 Intel(R) Core(TM) i5-8279U CPU @ 2.40GHz
    Memory: 36.44 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.12.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.9.0 - /usr/local/bin/npm
    pnpm: 8.0.0 - /usr/local/bin/pnpm
  Browsers:
    Chrome: 131.0.6778.204
    Safari: 18.0
  npmPackages:
    svelte: 5.14.4 => 5.14.4

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