Skip to content

Commit

Permalink
fix: added check for disabled session storage (#58)
Browse files Browse the repository at this point in the history
Co-authored-by: Mathieu Lajoie <[email protected]>
  • Loading branch information
MattL75 and MattL75 authored Oct 8, 2020
1 parent f9e2221 commit 5e02b6e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/stateMachine.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import storeFactory from './logic/storeFactory';
import isUndefined from './utils/isUndefined';
import isSessionStorageAllowed from './utils/isSessionStorageAllowed';
import { setUpDevTools } from './logic/devTool';
import StateMachineContext from './StateMachineContext';
import getSyncStoreData from './logic/getSyncStoreData';
Expand All @@ -21,7 +22,7 @@ import {

const isClient = typeof window !== 'undefined';
const isDevMode: boolean = process.env.NODE_ENV !== 'production';
let storageType: Storage = isClient
let storageType: Storage = isClient && isSessionStorageAllowed()
? window.sessionStorage
: {
getItem: payload => payload,
Expand Down
7 changes: 7 additions & 0 deletions src/utils/isSessionStorageAllowed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default (): boolean => {
try {
return !!window.sessionStorage
} catch (e) {
return false
}
}

0 comments on commit 5e02b6e

Please sign in to comment.