Skip to content

Commit 89ee329

Browse files
IanVSZack Story
authored andcommitted
Add an attempt to set/get item from localstorage (#205)
1 parent 6daad3f commit 89ee329

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/defaults/asyncLocalStorage.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,17 @@ const noStorage = process && process.env && process.env.NODE_ENV === 'production
99
}
1010

1111
function hasLocalStorage () {
12+
let storageExists
1213
try {
13-
return typeof window === 'object' && !!window.localStorage
14+
storageExists = (typeof window === 'object' && !!window.localStorage)
15+
if (storageExists) {
16+
const testKey = 'redux-persist localStorage test'
17+
window.localStorage.setItem(testKey, true)
18+
window.localStorage.getItem(testKey)
19+
window.localStorage.removeItem(testKey)
20+
}
1421
} catch (e) { return false }
22+
return storageExists
1523
}
1624

1725
function hasSessionStorage () {

0 commit comments

Comments
 (0)