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

Storage limit handling? #7

Open
unleashit opened this issue Aug 30, 2017 · 8 comments
Open

Storage limit handling? #7

unleashit opened this issue Aug 30, 2017 · 8 comments

Comments

@unleashit
Copy link

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.

@unleashit
Copy link
Author

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?

@renanbandeira
Copy link

Is this lib still being maintainned?

@unleashit
Copy link
Author

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

@renanbandeira
Copy link

The problem is that I'm facing a blank page error and I think it's because a storage limit.

@unleashit
Copy link
Author

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.

@mrgurdeep
Copy link

@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 ?

@renanbandeira
Copy link

@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.

@belohlavek
Copy link

Feel free to try https://github.com/decentraland/redux-persistence redux-storage compatible alternative

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

4 participants