Persist as part of `beforeunload` not working because of `setInterval` usage
I'm using redux-persist's more advanced hooks (using createPersistoid) to have more granular control over how often we persist the store state. Currently I am throttling persistoid updates to once every 30 seconds. However, if the user is closing the window or leaving the page I would like to take that opportunity to persist, by listening to the beforeunload event.
This doesn't work reliably, because persistoid.update uses setInterval with a timeout set to the config's throttle value here. In my case, this value is 0, but using setInterval to make this asynchronous means that the persistoid update doesn't complete before the tab is closed. What do you think the best approach would be to fix this? A couple of ideas:
- if
throttleis set to 0, don't usesetIntervalat all and execute synchronously. - a config boolean called
disableThrottleorwriteSynchronouslythat executes the update synchronously.
I'd be happy to cut a PR for either approach, I just wanted to know which would be preferred. Thanks so much for maintaining this library! <3
Source: rt2zz/redux-persist