joshnuss / svelte-persisted-store

A Svelte store that persists to localStorage

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Lib not working with Blob data

forna opened this issue · comments

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:

image

Then in the next page I try to retrieve the value and it is empty:

image

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>

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.