This issue was erroneous; I was comparing the head of the 1.0 branch with a release that was built from a different, earlier commit. The original issue follows.
persistState.js has the following snippet:
function getDefaultStorage() {
return adapter(localStorage);
}
// snip
export default function persistState(storage = getDefaultStorage(), key = defaultKey, callback) {
I figure it's written this way so that if you provide a non-default storage mechanism (i.e. AsyncStorage, in this case), it never creates the default adapter and therefore never hits the localStorage reference. Unfortunately, it seems like Babel has decided that this function is inlinable, so the transpiled code ends up like so:
var defaultStorage = (0, _adaptersLocalStorage2['default'])(localStorage);
// snip
function persistState(storage, key, callback) {
if (storage === undefined) storage = defaultStorage;
So it always hits the localStorage reference, throwing an exception at runtime on React Native:
This issue was erroneous; I was comparing the head of the 1.0 branch with a release that was built from a different, earlier commit. The original issue follows.
persistState.js
has the following snippet:I figure it's written this way so that if you provide a non-default storage mechanism (i.e. AsyncStorage, in this case), it never creates the default adapter and therefore never hits the
localStorage
reference. Unfortunately, it seems like Babel has decided that this function is inlinable, so the transpiled code ends up like so:So it always hits the
localStorage
reference, throwing an exception at runtime on React Native: