You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
@MacFJA I am seeing that sometimes the serialized data contains oddities like this
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.
@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
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.
Activity
MacFJA commentedon Oct 2, 2022
Do you have a repository where I can reproduce the error ?
michaelcuneo commentedon Oct 3, 2022
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.flxmrk commentedon Aug 20, 2023
I've experienced lack of persistence when using IndexedDB type, completely reproducible for you at my REPL.
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
flxmrk commentedon Aug 20, 2023
@MacFJA I am seeing that sometimes the serialized data contains oddities like this

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.
MacFJA commentedon Aug 20, 2023
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.
flxmrk commentedon Aug 20, 2023
@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
flxmrk commentedon Aug 21, 2023
@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.