Skip to content

Persistent Store broken since 2.0.0 #33

Open

Description

@michaelcuneo

Persist has not worked for me at all, since 2.0.0.

I've tried persist(), I've tried persistBrowserSession(), but both just forget everything when I hit refresh.

I have watched the console while I hit refresh, and it doesn't appear to serialise / deserialise properly.

Activity

  1. MacFJA commented on Oct 2, 2022

    @MacFJA
    Owner

    Do you have a repository where I can reproduce the error ?

  2. michaelcuneo commented on Oct 3, 2022

    @michaelcuneo
    Author

    I managed to get it working by explicitly specifying a serialization ... setSerialization(JSON.stringify, JSON.parse). Without this, it doesn't serialise at all, and I get bad data.

  3. flxmrk commented on Aug 20, 2023

    @flxmrk

    I've experienced lack of persistence when using IndexedDB type, completely reproducible for you at my REPL.

    persist(writable([]), createIndexedDBStorage(), "myArray")

    i discovered that if you persist an empty array as default, without setting another value in immediate execution, then you go and save your array of data to the store (ie: $mystore = [...mydata]), it will NOT actually save the update to the IndexedDB.

    No attempts to save any new value at any subsequent execution time will work. So in most cases, the empty value gets saved, then never actually updates after that point.

    This is also true for string, but it has a strange additional phenomena where the value very briefly updates, then disappears again.

    REPL: https://svelte.dev/repl/e4753fcaebf541d9a33408dede9b5990?version=4.2.0

  4. flxmrk commented on Aug 20, 2023

    @flxmrk

    @MacFJA I am seeing that sometimes the serialized data contains oddities like this
    image

    And that when that gets stored, even in localStorage, it will break persistence. This is where @michaelcuneo suggestion of setSerialization comes into play. By doing that, we get clean data in the storage, and no more issues on localStorage (still issues in indexedDB).

    These tests always need run on a clean browser storage/db to be accurately reproducing.

  5. MacFJA commented on Aug 20, 2023

    @MacFJA
    Owner

    The value you see this added by the serialization engine to avoid circular dependency.

    But you can change the serialization engine to another one, like @michaelcuneo did.

    You can use plain JSON (https://github.com/MacFJA/svelte-persistent-store/blob/main/.docs/How-To/06-Change-Serialization.md#using-json-for-serialization), ESSerializer (https://github.com/MacFJA/svelte-persistent-store/blob/main/.docs/How-To/06-Change-Serialization.md#using-esserializer-for-serialization), or even devalue (from Rich-Harris ; it's the same serialization engine used in SvelteKit).
    You can use whatever you want or whatever fit the best to your need.

    There are no good or bad choices. They all have their pros and cons.

  6. flxmrk commented on Aug 20, 2023

    @flxmrk

    @MacFJA I'll play around with some of those thanks for the tip - but that last message was more of a side point, want to be sure you noticed the message i had above that - with the REPL showing the bug in IndexedDBStorage

  7. flxmrk commented on Aug 21, 2023

    @flxmrk

    @MacFJA

    I also downloaded this repo and tried to reproduce this effect I see in REPL, but was NOT able to reproduce using your test page.

    I cant fathom why I can prove the bug in REPL and in my own project, but not in your test page.

    I've experienced lack of persistence when using IndexedDB type, completely reproducible for you at my REPL.

    persist(writable([]), createIndexedDBStorage(), "myArray")

    i discovered that if you persist an empty array as default, without setting another value in immediate execution, then you go and save your array of data to the store (ie: $mystore = [...mydata]), it will NOT actually save the update to the IndexedDB.

    No attempts to save any new value at any subsequent execution time will work. So in most cases, the empty value gets saved, then never actually updates after that point.

    This is also true for string, but it has a strange additional phenomena where the value very briefly updates, then disappears again.

    REPL: https://svelte.dev/repl/e4753fcaebf541d9a33408dede9b5990?version=4.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions