Open unleashit opened 7 years ago
Did a little more experimenting and found that if the redux storage can't or won't save the store, it fails silently. Also, it appears that it's fails because of some kind of designated limit that's much lower than the actual browser limit of between 5-10mb. The limit I'm hitting is somewhere between 2-2.5mb. After that, Redux Storage simply won't save. REDUX_STORAGE_SAVE action isn't fired and nothing is reported in the console. The result is the next time LS is loaded like after a browser refresh, the Redux store is being replaced with the initial state (not sure why initialstate and not the last saved localstorage string, but this point may be due to my config).
I realize that I'm making pretty heavy use of LS and that I'm going to need either a different engine and/or a serverside caching solution. But 95% of my users aren't going to hit the browser's LS limits. Many will however use up to a few megs or so (the size of a typical smartphone image). Having all of them hit the server with 2-5mb payloads is more than I'd like to have happen and I think can be avoided. It would be great if it were possible to catch saving errors. In the docs, the load() method is catchable, is there anything for saving?
Also, I wondering why the upper limit is so low and if it's a limitation of Redux Storage, or maybe there's a lower limit for a single localstorage row?
Is this lib still being maintainned?
Last commit 9 mos. ago, seems likely. It's easy enough to implement this yourself anyway. Was mainly being lazy :)
https://egghead.io/lessons/javascript-redux-persisting-the-state-to-the-local-storage
The problem is that I'm facing a blank page error and I think it's because a storage limit.
It was definitely a problem for me, and it fails silently when the size is to big, which is really only 5mb (after serializing) in some browsers. I'd suggest something else besides localStorage if you have more than that or do a try catch around your localStorage.setItem() and at least handle the errors some how. My project is now ok as an MVP, but that's what I plan on doing once it moves forward again.
@renanbandeira can you reproduce this issue in jsfiddle. I understand in case of @unleashit the issue is logical.
But then if it shows blank page do you see that the store is set to initial state or how did you conclude ?
@mrgurdeep hi man, actually now I think it wasn't because of the storage limit. The blank page error only happens with the client who is thousands of miles away and I have no clue. On the other hand, I've seen some logs with 8 to 10MB and it made me realize that storage liimit wasn't the problem.
Feel free to try https://github.com/decentraland/redux-persistence redux-storage compatible alternative
Just wondering if there were anything in the API or plugins to help manage storage size. Like maybe even something as simple as a hook to get the expected size before saving? I have an app where users can add images to a canvas (which ends up in Redux store as an object with base64 data uris) and it would be nice to be able to persist the state through a browser refresh, and only cache on the server if the localstorage limit is reached.
Nice work. Aside from my kind of data heavy use case, I'm very happy the how smooth this is working with the debounce decorator.