Skip to content

Can't save state to indexeddb #15327

@staab

Description

@staab

Describe the bug

State can't be saved to indexeddb without using $state.snapshot. This would be only annoying, but if the path a piece of data takes to get to the database is convoluted, as it usually is in a production app, it's hard to know exactly when to snapshot the data. To make matters worse, the only way to detect a proxy reliably is to try/catch an invocation to structuredClone (or some other thing like postMessage that does a structured clone of the object), which makes it very hard to locate the snapshot logic in the indexeddb adapter without large performance penalties.

Reproduction

Code: https://github.com/staab/svelte5-indexeddb-bug
Demo: https://svelte5-indexeddb-bug.onrender.com/

Logs

Uncaught DataCloneError: Failed to execute 'add' on 'IDBObjectStore': #<Object> could not be cloned.

System Info

System:
    OS: macOS 15.3
    CPU: (8) arm64 Apple M1
    Memory: 98.20 MB / 8.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.20.6 - ~/.nvm/versions/node/v18.20.6/bin/node
    npm: 10.8.2 - ~/.nvm/versions/node/v18.20.6/bin/npm
    pnpm: 9.15.0 - ~/Library/pnpm/pnpm
    bun: 1.2.2 - ~/.nvm/versions/node/v18.20.6/bin/bun
  Browsers:
    Brave Browser: 132.1.74.50
    Chrome: 133.0.6943.98
    Safari: 18.3
  npmPackages:
    svelte: ^5.0.0 => 5.20.1

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions