diff --git a/android/expoview/src/main/java/versioned/host/exp/exponent/modules/universal/ScopedErrorRecoveryModule.kt b/android/expoview/src/main/java/versioned/host/exp/exponent/modules/universal/ScopedErrorRecoveryModule.kt index 411dfe1c0d4a48..7139cb1fb86319 100644 --- a/android/expoview/src/main/java/versioned/host/exp/exponent/modules/universal/ScopedErrorRecoveryModule.kt +++ b/android/expoview/src/main/java/versioned/host/exp/exponent/modules/universal/ScopedErrorRecoveryModule.kt @@ -9,14 +9,10 @@ class ScopedErrorRecoveryModule(context: Context, val experienceId: ExperienceId mSharedPreferences.edit().putString(experienceId.get(), props).apply() } - override fun popProps(): Map { - with(mSharedPreferences.getString(experienceId.get(), "")) { - return if (isNotEmpty()) { - mSharedPreferences.edit().remove(experienceId.get()).apply() - getPropsFromString(this) - } else { - emptyMap() - } + override fun popProps(): String? { + return mSharedPreferences.getString(experienceId.get(), null)?.let { + mSharedPreferences.edit().remove(experienceId.get()).apply() + it } } } diff --git a/ios/Exponent/Versioned/Core/UniversalModules/EXScopedErrorRecovery.m b/ios/Exponent/Versioned/Core/UniversalModules/EXScopedErrorRecovery.m deleted file mode 100644 index 64574e7f98bf55..00000000000000 --- a/ios/Exponent/Versioned/Core/UniversalModules/EXScopedErrorRecovery.m +++ /dev/null @@ -1,7 +0,0 @@ -// Copyright 2018-present 650 Industries. All rights reserved. - -#import "EXScopedErrorRecovery.h" - -@implementation EXScopedErrorRecovery - -@end diff --git a/ios/Exponent/Versioned/Core/UniversalModules/EXScopedErrorRecoveryModule.m b/ios/Exponent/Versioned/Core/UniversalModules/EXScopedErrorRecoveryModule.m index 0e88e16b0a98fd..a145f4e59b4bbe 100644 --- a/ios/Exponent/Versioned/Core/UniversalModules/EXScopedErrorRecoveryModule.m +++ b/ios/Exponent/Versioned/Core/UniversalModules/EXScopedErrorRecoveryModule.m @@ -21,7 +21,7 @@ - (instancetype)initWithExperienceId:(NSString *)experienceId return self; } -- (BOOL)pushProps:(NSDictionary *)props +- (BOOL)pushProps:(NSString *)props { NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults]; NSDictionary *errorRecoveryStore = [preferences objectForKey:userDefaultsKey]; @@ -36,12 +36,12 @@ - (BOOL)pushProps:(NSDictionary *)props } } -- (NSDictionary *)popProps +- (NSString *)popProps { NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults]; NSDictionary *errorRecoveryStore = [preferences objectForKey:userDefaultsKey]; if (errorRecoveryStore != nil) { - NSDictionary *props = [errorRecoveryStore objectForKey:_experienceId]; + NSString *props = [errorRecoveryStore objectForKey:_experienceId]; if (props != nil) { NSMutableDictionary *storeWithRemovedProps = [errorRecoveryStore mutableCopy]; [storeWithRemovedProps removeObjectForKey:_experienceId]; diff --git a/packages/expo-error-recovery/README.md b/packages/expo-error-recovery/README.md index 5fb5c6ae32b8df..1ad899768ff7f0 100644 --- a/packages/expo-error-recovery/README.md +++ b/packages/expo-error-recovery/README.md @@ -1,6 +1,6 @@ # expo-error-recovery -`expo-error-recovery` helping you gracefully handle crashes due to fatal JavaScript errors. +`expo-error-recovery` helps you gracefully handle crashes caused by fatal JavaScript errors. # API documentation diff --git a/packages/expo-error-recovery/android/build.gradle b/packages/expo-error-recovery/android/build.gradle index daff11c5bceb33..114468d8498f5e 100644 --- a/packages/expo-error-recovery/android/build.gradle +++ b/packages/expo-error-recovery/android/build.gradle @@ -16,6 +16,10 @@ apply plugin: 'kotlin-android' group = 'host.exp.exponent' version = '1.0.0' +def safeExtGet(prop, fallback) { + rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback +} + // Upload android library to maven with javadoc and android sources configurations { deployerJars @@ -42,11 +46,11 @@ uploadArchives { } android { - compileSdkVersion 26 + compileSdkVersion safeExtGet("compileSdkVersion", 28) defaultConfig { - minSdkVersion 21 - targetSdkVersion 26 + minSdkVersion safeExtGet("minSdkVersion", 21) + targetSdkVersion safeExtGet("targetSdkVersion", 28) versionCode 1 versionName '1.0.0' } @@ -67,6 +71,4 @@ dependencies { unimodule 'unimodules-core' api "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion" - - implementation 'com.google.code.gson:gson:2.8.5' } diff --git a/packages/expo-error-recovery/android/src/main/java/expo/modules/errorrecovery/ErrorRecoveryModule.kt b/packages/expo-error-recovery/android/src/main/java/expo/modules/errorrecovery/ErrorRecoveryModule.kt index 30663b53f4d178..0ab4b2d2e47f64 100644 --- a/packages/expo-error-recovery/android/src/main/java/expo/modules/errorrecovery/ErrorRecoveryModule.kt +++ b/packages/expo-error-recovery/android/src/main/java/expo/modules/errorrecovery/ErrorRecoveryModule.kt @@ -2,9 +2,6 @@ package expo.modules.errorrecovery import android.content.Context import android.content.SharedPreferences -import com.google.gson.Gson -import com.google.gson.JsonIOException -import com.google.gson.reflect.TypeToken import org.unimodules.core.ExportedModule import org.unimodules.core.ModuleRegistry @@ -19,19 +16,14 @@ open class ErrorRecoveryModule(context: Context) : ExportedModule(context) { override fun getName(): String = "ExpoErrorRecovery" - override fun onCreate(moduleRegistry: ModuleRegistry) { mSharedPreferences = context.applicationContext.getSharedPreferences(ERROR_STORE, Context.MODE_PRIVATE) } @ExpoMethod - fun setRecoveryProps(props: Map, promise: Promise) { - return try { - propsReadyToSave = Gson().toJson(props) - promise.resolve(null) - } catch (exception: JsonIOException) { - promise.reject("E_INVALID_PROPS", "Cannot parse props.", exception) - } + fun setRecoveryProps(props: String, promise: Promise) { + propsReadyToSave = props + promise.resolve(null) } @ExpoMethod @@ -42,34 +34,19 @@ open class ErrorRecoveryModule(context: Context) : ExportedModule(context) { promise.resolve(null) } - override fun getConstants(): Map? { - popProps().let { - return if (it.isEmpty()) { - null - } else { - mapOf("errors" to it) - } - } + override fun getConstants(): Map { + return mapOf("errors" to popProps()) } - protected fun getPropsFromString(propsString: String): Map { - return Gson().fromJson(propsString, object : TypeToken>() {}.type) - } protected open fun pushProps(props: String) { mSharedPreferences.edit().putString("errorRecovery", props).apply() } - protected open fun popProps(): Map { - with(mSharedPreferences.getString("errorRecovery", "")) { - return if (isNotEmpty()) { - mSharedPreferences.edit().remove("errorRecovery").apply() - getPropsFromString(this) - } else { - emptyMap() - } + protected open fun popProps(): String? { + return mSharedPreferences.getString("errorRecovery", null)?.let { + mSharedPreferences.edit().remove("errorRecovery").apply() + it } } - - } diff --git a/packages/expo-error-recovery/build/ErrorRecovery.js b/packages/expo-error-recovery/build/ErrorRecovery.js index 71cede6c2aec48..2dd0b437393571 100644 --- a/packages/expo-error-recovery/build/ErrorRecovery.js +++ b/packages/expo-error-recovery/build/ErrorRecovery.js @@ -1,7 +1,7 @@ import { UnavailabilityError } from '@unimodules/core'; import { once } from 'lodash'; import ExpoErrorRecovery from './ExpoErrorRecovery'; -const globalHadlerSwapper = once(() => { +const globalHandlerSwapper = once(() => { // ErrorUtlis came from react-native // https://github.com/facebook/react-native/blob/1151c096dab17e5d9a6ac05b61aacecd4305f3db/Libraries/vendor/core/ErrorUtils.js#L25 const globalHandler = ErrorUtils.getGlobalHandler(); @@ -10,12 +10,18 @@ const globalHadlerSwapper = once(() => { globalHandler(error, isFatal); }); }); -export const errors = ExpoErrorRecovery.errors; +export const errors = _parseNativeErrors(); export function setRecoveryProps(props) { if (!ExpoErrorRecovery.setRecoveryProps) { throw new UnavailabilityError('ErrorRecovery', 'setRecoveryProps'); } - ExpoErrorRecovery.setRecoveryProps(props); - globalHadlerSwapper(); + ExpoErrorRecovery.setRecoveryProps(JSON.stringify(props)); + globalHandlerSwapper(); +} +function _parseNativeErrors() { + if (ExpoErrorRecovery.errors) { + return JSON.parse(ExpoErrorRecovery.errors); + } + return undefined; } //# sourceMappingURL=ErrorRecovery.js.map \ No newline at end of file diff --git a/packages/expo-error-recovery/build/ErrorRecovery.js.map b/packages/expo-error-recovery/build/ErrorRecovery.js.map index 2dc32b32cb22b8..921381550a912f 100644 --- a/packages/expo-error-recovery/build/ErrorRecovery.js.map +++ b/packages/expo-error-recovery/build/ErrorRecovery.js.map @@ -1 +1 @@ -{"version":3,"file":"ErrorRecovery.js","sourceRoot":"","sources":["../src/ErrorRecovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,iBAAiB,MAAM,qBAAqB,CAAC;AAEpD,MAAM,mBAAmB,GAAG,IAAI,CAAC,GAAG,EAAE;IACpC,oCAAoC;IACpC,iIAAiI;IACjI,MAAM,aAAa,GAAG,UAAU,CAAC,gBAAgB,EAAE,CAAC;IACpD,UAAU,CAAC,gBAAgB,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;QACnD,MAAM,iBAAiB,CAAC,iBAAiB,EAAE,CAAC;QAC5C,aAAa,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAChC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,MAAM,GAAG,iBAAiB,CAAC,MAAM,CAAC;AAE/C,MAAM,UAAU,gBAAgB,CAAC,KAA6B;IAC5D,IAAI,CAAC,iBAAiB,CAAC,gBAAgB,EAAE;QACvC,MAAM,IAAI,mBAAmB,CAAC,eAAe,EAAE,kBAAkB,CAAC,CAAC;KACpE;IACD,iBAAiB,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;IAC1C,mBAAmB,EAAE,CAAC;AACxB,CAAC","sourcesContent":["import { UnavailabilityError } from '@unimodules/core';\nimport { once } from 'lodash';\nimport ExpoErrorRecovery from './ExpoErrorRecovery';\n\nconst globalHadlerSwapper = once(() => {\n // ErrorUtlis came from react-native\n // https://github.com/facebook/react-native/blob/1151c096dab17e5d9a6ac05b61aacecd4305f3db/Libraries/vendor/core/ErrorUtils.js#L25\n const globalHandler = ErrorUtils.getGlobalHandler();\n ErrorUtils.setGlobalHandler(async (error, isFatal) => {\n await ExpoErrorRecovery.saveRecoveryProps();\n globalHandler(error, isFatal);\n });\n});\n\nexport const errors = ExpoErrorRecovery.errors;\n\nexport function setRecoveryProps(props: { [key: string]: any }): void {\n if (!ExpoErrorRecovery.setRecoveryProps) {\n throw new UnavailabilityError('ErrorRecovery', 'setRecoveryProps');\n }\n ExpoErrorRecovery.setRecoveryProps(props);\n globalHadlerSwapper();\n}\n"]} \ No newline at end of file +{"version":3,"file":"ErrorRecovery.js","sourceRoot":"","sources":["../src/ErrorRecovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,iBAAiB,MAAM,qBAAqB,CAAC;AAEpD,MAAM,oBAAoB,GAAG,IAAI,CAAC,GAAG,EAAE;IACrC,oCAAoC;IACpC,iIAAiI;IACjI,MAAM,aAAa,GAAG,UAAU,CAAC,gBAAgB,EAAE,CAAC;IACpD,UAAU,CAAC,gBAAgB,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;QACnD,MAAM,iBAAiB,CAAC,iBAAiB,EAAE,CAAC;QAC5C,aAAa,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAChC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,MAAM,GAAG,kBAAkB,EAAE,CAAC;AAE3C,MAAM,UAAU,gBAAgB,CAAC,KAA6B;IAC5D,IAAI,CAAC,iBAAiB,CAAC,gBAAgB,EAAE;QACvC,MAAM,IAAI,mBAAmB,CAAC,eAAe,EAAE,kBAAkB,CAAC,CAAC;KACpE;IACD,iBAAiB,CAAC,gBAAgB,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;IAC1D,oBAAoB,EAAE,CAAC;AACzB,CAAC;AAED,SAAS,kBAAkB;IACzB,IAAI,iBAAiB,CAAC,MAAM,EAAE;QAC5B,OAAO,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;KAC7C;IACD,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import { UnavailabilityError } from '@unimodules/core';\nimport { once } from 'lodash';\nimport ExpoErrorRecovery from './ExpoErrorRecovery';\n\nconst globalHandlerSwapper = once(() => {\n // ErrorUtlis came from react-native\n // https://github.com/facebook/react-native/blob/1151c096dab17e5d9a6ac05b61aacecd4305f3db/Libraries/vendor/core/ErrorUtils.js#L25\n const globalHandler = ErrorUtils.getGlobalHandler();\n ErrorUtils.setGlobalHandler(async (error, isFatal) => {\n await ExpoErrorRecovery.saveRecoveryProps();\n globalHandler(error, isFatal);\n });\n});\n\nexport const errors = _parseNativeErrors();\n\nexport function setRecoveryProps(props: { [key: string]: any }): void {\n if (!ExpoErrorRecovery.setRecoveryProps) {\n throw new UnavailabilityError('ErrorRecovery', 'setRecoveryProps');\n }\n ExpoErrorRecovery.setRecoveryProps(JSON.stringify(props));\n globalHandlerSwapper();\n}\n\nfunction _parseNativeErrors() {\n if (ExpoErrorRecovery.errors) {\n return JSON.parse(ExpoErrorRecovery.errors);\n }\n return undefined;\n}"]} \ No newline at end of file diff --git a/packages/expo-error-recovery/ios/EXErrorRecovery/EXErrorRecoveryModule.h b/packages/expo-error-recovery/ios/EXErrorRecovery/EXErrorRecoveryModule.h index c16695c598992a..5f6e3aebde8f95 100644 --- a/packages/expo-error-recovery/ios/EXErrorRecovery/EXErrorRecoveryModule.h +++ b/packages/expo-error-recovery/ios/EXErrorRecovery/EXErrorRecoveryModule.h @@ -5,8 +5,8 @@ @interface EXErrorRecoveryModule : UMExportedModule -- (BOOL)pushProps:(NSDictionary *)props; +- (BOOL)pushProps:(NSString *)props; -- (NSDictionary *)popProps; +- (NSString *)popProps; @end diff --git a/packages/expo-error-recovery/ios/EXErrorRecovery/EXErrorRecoveryModule.m b/packages/expo-error-recovery/ios/EXErrorRecovery/EXErrorRecoveryModule.m index c53923d278b222..bf82f1b359dc9c 100644 --- a/packages/expo-error-recovery/ios/EXErrorRecovery/EXErrorRecoveryModule.m +++ b/packages/expo-error-recovery/ios/EXErrorRecovery/EXErrorRecoveryModule.m @@ -6,7 +6,7 @@ @interface EXErrorRecoveryModule () -@property (nonatomic, strong) NSDictionary *recoveryPropsToSave; +@property (nonatomic, strong) NSString *recoveryPropsToSave; @end @@ -15,7 +15,7 @@ @implementation EXErrorRecoveryModule UM_EXPORT_MODULE(ExpoErrorRecovery); UM_EXPORT_METHOD_AS(setRecoveryProps, - setRecoveryProps:(NSDictionary *)props + setRecoveryProps:(NSString *)props resovler:(UMPromiseResolveBlock)resolve rejecter:(UMPromiseRejectBlock)reject) { @@ -43,16 +43,16 @@ - (NSDictionary *)constantsToExport }; } -- (BOOL)pushProps:(NSDictionary *)props { +- (BOOL)pushProps:(NSString *)props { NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults]; [preferences setObject:props forKey:userDefaultsKey]; return [preferences synchronize]; } -- (NSDictionary *)popProps +- (NSString *)popProps { NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults]; - NSDictionary *props = [preferences objectForKey:userDefaultsKey]; + NSString *props = [preferences objectForKey:userDefaultsKey]; if (props != nil) { [preferences removeObjectForKey:userDefaultsKey]; [preferences synchronize]; diff --git a/packages/expo-error-recovery/package.json b/packages/expo-error-recovery/package.json index 2ebddc47b08c3c..b00b6ee262ac45 100644 --- a/packages/expo-error-recovery/package.json +++ b/packages/expo-error-recovery/package.json @@ -17,7 +17,7 @@ "react-native", "expo", "expo-error-recovery", - "errorr-recovery" + "error-recovery" ], "repository": { "type": "git", diff --git a/packages/expo-error-recovery/src/ErrorRecovery.ts b/packages/expo-error-recovery/src/ErrorRecovery.ts index 29aa845697dd39..c860c765357b83 100644 --- a/packages/expo-error-recovery/src/ErrorRecovery.ts +++ b/packages/expo-error-recovery/src/ErrorRecovery.ts @@ -2,7 +2,7 @@ import { UnavailabilityError } from '@unimodules/core'; import { once } from 'lodash'; import ExpoErrorRecovery from './ExpoErrorRecovery'; -const globalHadlerSwapper = once(() => { +const globalHandlerSwapper = once(() => { // ErrorUtlis came from react-native // https://github.com/facebook/react-native/blob/1151c096dab17e5d9a6ac05b61aacecd4305f3db/Libraries/vendor/core/ErrorUtils.js#L25 const globalHandler = ErrorUtils.getGlobalHandler(); @@ -12,12 +12,19 @@ const globalHadlerSwapper = once(() => { }); }); -export const errors = ExpoErrorRecovery.errors; +export const errors = _parseNativeErrors(); export function setRecoveryProps(props: { [key: string]: any }): void { if (!ExpoErrorRecovery.setRecoveryProps) { throw new UnavailabilityError('ErrorRecovery', 'setRecoveryProps'); } - ExpoErrorRecovery.setRecoveryProps(props); - globalHadlerSwapper(); + ExpoErrorRecovery.setRecoveryProps(JSON.stringify(props)); + globalHandlerSwapper(); } + +function _parseNativeErrors() { + if (ExpoErrorRecovery.errors) { + return JSON.parse(ExpoErrorRecovery.errors); + } + return undefined; +} \ No newline at end of file diff --git a/packages/expo/src/__tests__/ErrorRecovery-test.ts b/packages/expo/src/__tests__/ErrorRecovery-test.ts deleted file mode 100644 index 416a0a91c6c377..00000000000000 --- a/packages/expo/src/__tests__/ErrorRecovery-test.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { describeCrossPlatform } from 'jest-expo'; -import { NativeModules } from 'react-native'; -import * as ErrorRecovery from '../ErrorRecovery/ErrorRecovery'; - -describeCrossPlatform('ErrorRecovery', () => { - it('passes the recovery props to the native method', () => { - ErrorRecovery.setRecoveryProps({ a: 'test' }); - expect(NativeModules.ExponentErrorRecovery.setRecoveryProps).toHaveBeenCalledWith({ - a: 'test', - }); - }); -});