Lib not working with Blob data
forna opened this issue · comments
forna commented
The lib is not working when using Blobs.
I set the value in one page and in the next page the value is gone.
It works correctly if instead of Blob I use a String or an Int.
I write to the browser console in the page where the store is set:
Then in the next page I try to retrieve the value and it is empty:
I have prepared an example to show the issue:
src/lib/store.js:
import { persisted } from "svelte-local-storage-store"
export const store = persisted("sessionStore",
{ blobStore: Blob },
{storage: "local"})
src/routes/+page.svelte:
<script>
import {store} from "$lib/store.js"
const obj = { hello: "world" }
const blob = new Blob([JSON.stringify(obj, null, 2)], {type: "application/zip"})
store.set({"blobStore": blob})
console.log($store.blobStore)
</script>
<a href ="/destination">Click me!</a>
src/routes/destination/+page.svelte:
<script>
import {store} from "$lib/store.js"
console.log($store.blobStore)
</script>
Joshua Nussbaum commented
Hi @forna,
This library uses JSON.stringify()
under the hood to serialize data. But you can customize it by passing the serializer
option.
There's an example in the readme.