UNPKG

841 BPlain TextView Raw
1import { Platform } from 'expo-modules-core';
2const LOCAL_STORAGE_KEY = 'EXPO_ERROR_RECOVERY_STORAGE';
3
4function _consumeRecoveryProps(): string | null {
5 if (!Platform.isDOMAvailable) return null;
6 try {
7 const props = localStorage.getItem(LOCAL_STORAGE_KEY);
8 localStorage.removeItem(LOCAL_STORAGE_KEY);
9 return props;
10 } catch (e) {
11 // Catches localStorage SecurityError https://github.com/expo/expo/issues/8355
12 }
13 return null;
14}
15
16export default {
17 get name(): string {
18 return 'ExpoErrorRecovery';
19 },
20
21 saveRecoveryProps(props: string): void {
22 if (!Platform.isDOMAvailable) return;
23 try {
24 localStorage.setItem(LOCAL_STORAGE_KEY, props);
25 } catch (e) {
26 // Catches localStorage SecurityError https://github.com/expo/expo/issues/8355
27 }
28 },
29
30 recoveredProps: _consumeRecoveryProps(),
31};