-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: restore fallback for broken sessionStorage (#74)
The subset of the history of browser history stack entries within the current session is mirrored in sessionStorage so that it can be restored into Redux on page reload or on navigation from external history stack entries (using the borwser back/forward buttons, reload button, unfreezing, etc). There used to be a fallback for browsers where sessionStorage is not supported which instead stored the entries inside the current history state. This fallback was removed as part of #61. However, although all modern browsers officially support sessionStorage, there are various circumstances in which it fails to work: - if the user fills the entire quota (very unlikely that Rudy itself would do this, but other user code might) - in private browsing mode on iOS Safari - if all cookies are disabled in Chrome (and possibly also in some modified versions of chrome for android) This change restores that fallback. It comes with the same caveats that were there before: - since only the current history index is accessible, only the current and previous stack entries can be seen. This means that when returning to a stack entry in the middle of r the Rudy stack, the redux mirror of the stack entries will only include current and past entries, not future ones. - as a consequence, route callbacks that occur before a transition to a route will not work when navigating forward beyond the entries in the redux state.
- Loading branch information
1 parent
30e698c
commit 8df1154
Showing
5 changed files
with
73 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { default as isServer } from './isServer' | ||
export { default as createSelector } from './createSelector' | ||
export { default as supportsSessionStorage } from './supportsSessionStorage' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* eslint-env browser */ | ||
|
||
let _supportsSessionStorage: boolean | ||
|
||
export default (): boolean => { | ||
if (_supportsSessionStorage !== undefined) { | ||
return _supportsSessionStorage | ||
} | ||
try { | ||
window.sessionStorage.setItem('rudytestitem', 'testvalue') | ||
if (window.sessionStorage.getItem('rudytestitem') === 'testvalue') { | ||
window.sessionStorage.removeItem('rudytestitem') | ||
_supportsSessionStorage = true | ||
} else { | ||
_supportsSessionStorage = false | ||
} | ||
} catch { | ||
_supportsSessionStorage = false | ||
} | ||
if (!_supportsSessionStorage) { | ||
// eslint-disable-next-line no-console | ||
console.warn( | ||
'[rudy]: WARNING: This browser does not support sessionStorage!', | ||
) | ||
} | ||
return _supportsSessionStorage | ||
} |