-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "fix(core): Check for storage initialization errors (#13938)"
This reverts commit 0f50917.
- Loading branch information
Showing
5 changed files
with
13 additions
and
86 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
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,51 +1,22 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { ConsoleLogger } from '../Logger'; | ||
|
||
import { InMemoryStorage } from './InMemoryStorage'; | ||
|
||
/** | ||
* @internal | ||
* @returns Either a reference to window.localStorage or an in-memory storage as fallback | ||
*/ | ||
|
||
const logger = new ConsoleLogger('CoreStorageUtils'); | ||
|
||
export const getLocalStorageWithFallback = (): Storage => { | ||
try { | ||
// Attempt to use localStorage directly | ||
if (typeof window !== 'undefined' && window.localStorage) { | ||
return window.localStorage; | ||
} | ||
} catch (e) { | ||
// Handle any errors related to localStorage access | ||
logger.error('LocalStorage access failed:', e); | ||
} | ||
|
||
// Return in-memory storage as a fallback if localStorage is not accessible | ||
return new InMemoryStorage(); | ||
}; | ||
export const getLocalStorageWithFallback = (): Storage => | ||
typeof window !== 'undefined' && window.localStorage | ||
? window.localStorage | ||
: new InMemoryStorage(); | ||
|
||
/** | ||
* @internal | ||
* @returns Either a reference to window.sessionStorage or an in-memory storage as fallback | ||
*/ | ||
export const getSessionStorageWithFallback = (): Storage => { | ||
try { | ||
// Attempt to use sessionStorage directly | ||
if (typeof window !== 'undefined' && window.sessionStorage) { | ||
// Verify we can actually use it by testing access | ||
window.sessionStorage.getItem('test'); | ||
|
||
return window.sessionStorage; | ||
} | ||
|
||
throw new Error('sessionStorage is not defined'); | ||
} catch (e) { | ||
// Handle any errors related to sessionStorage access | ||
logger.error('SessionStorage access failed:', e); | ||
|
||
return new InMemoryStorage(); | ||
} | ||
}; | ||
export const getSessionStorageWithFallback = (): Storage => | ||
typeof window !== 'undefined' && window.sessionStorage | ||
? window.sessionStorage | ||
: new InMemoryStorage(); |