Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error restoring data [object Object] #16

Closed
piotr-cz opened this issue Jun 10, 2022 · 4 comments
Closed

Error restoring data [object Object] #16

piotr-cz opened this issue Jun 10, 2022 · 4 comments

Comments

@piotr-cz
Copy link
Owner

piotr-cz commented Jun 10, 2022

Reported by @bigfree:

I try, build is success but now there is an error in retrieving data from the DB 😢

redux-persist/getStoredState: Error restoring data [object Object] SyntaxError: Unexpected token o in JSON at position 1
    at JSON.parse (<anonymous>)
    at defaultDeserialize (getStoredState.js:39:1)
    at getStoredState.js:23:1

The data is stored in the database, but when the page is refreshed, it is no longer in the database. However, the structure of the database remains the same.

Store data:
image

After refresh:
image

My persist config:

const persistConfig: PersistConfig<any> = {
    key: 'root',
    version: 1,
    storage: createIdbStorage({
        name: 'craedit',
        storeName: 'craeditstore',
        version: 1
    }),
    timeout: 100,
    serialize: false,
    debug: true,
    blacklist: ['point']
};

Originally posted by @bigfree in #14 (comment)

@piotr-cz
Copy link
Owner Author

piotr-cz commented Jun 10, 2022

@bigfree
Please try with

  • using serialize: false, deserialize: false

    const persistConfig = {
      key: 'root',
      storage: createIdbStorage({name: 'myApp', storeName: 'keyval'}),
      serialize: false,
    +  deserialize: false,
    }
  • removing serialize: false option

    const persistConfig = {
      key: 'root',
      storage: createIdbStorage({name: 'myApp', storeName: 'keyval'}),
    -  serialize: false,
    }

and let me know if that fixed the issue.

Explaination:
since [email protected] the new undocumented deserialize option seem to be have set to same value as serialize.
So both should be set either to false or true.

@bigfree
Copy link

bigfree commented Jun 10, 2022

@piotr-cz
Cool, looks like it works!
But I had to extend PersistConfig type because it doesn't contain deserialize value..

const persistConfig: PersistConfig<any> & {deserialize: boolean} = {
   ...
}

Explaination:
since [email protected] the new undocumented deserialize option seem to be have set to same value as serialize.
So both should be set either to false or true.

ah good to know 😄

@piotr-cz
Copy link
Owner Author

Did you try with setting both serialize & deserialize option to true and false?
I'd like to document that in README.

Too bad authors didn't document this as IMHO it's a breaking change.

As for types, there are two PR's: rt2zz/redux-persist#1153, rt2zz/redux-persist#1304

@bigfree
Copy link

bigfree commented Jun 10, 2022

This only works if both values are set to true/false.

serialize: true,
deserialize: true,
serialize: false,
deserialize: false,

if option to serialize is set, of course object is not stored in database, only string.
Thank for your time and solved problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants