diff --git a/posthog-react-native/CHANGELOG.md b/posthog-react-native/CHANGELOG.md index 1216c642..164f2e78 100644 --- a/posthog-react-native/CHANGELOG.md +++ b/posthog-react-native/CHANGELOG.md @@ -1,3 +1,7 @@ +# 2.9.2 - 2023-12-21 + +1. If `async-storage` or `expo-file-system` is not installed, the SDK will fallback to `persistence: memory` and log a warning + # 2.9.1 - 2023-12-14 1. `getPersistedProperty` uses Nullish Coalescing operator to fallback to `undefined` only if the property is not found diff --git a/posthog-react-native/src/posthog-rn.ts b/posthog-react-native/src/posthog-rn.ts index 1129961b..29a73ecd 100644 --- a/posthog-react-native/src/posthog-rn.ts +++ b/posthog-react-native/src/posthog-rn.ts @@ -46,8 +46,18 @@ export class PostHog extends PostHogCore { if (!posthog) { const persistence = options?.persistence ?? 'file' if (persistence === 'file') { - const storage = new SemiAsyncStorage(options?.customAsyncStorage || buildOptimisiticAsyncStorage()) - posthog = storage.preloadAsync().then(() => new PostHog(apiKey, options, storage)) + try { + const storage = new SemiAsyncStorage(options?.customAsyncStorage || buildOptimisiticAsyncStorage()) + posthog = storage.preloadAsync().then(() => new PostHog(apiKey, options, storage)) + } catch (error) { + console.error( + 'PostHog was unable to initialise with persistence set to "file". Falling back to "memory" persistence.', + error + ) + posthog = Promise.resolve( + new PostHog(apiKey, { ...options, persistence: 'memory', customAsyncStorage: undefined }) + ) + } } else { posthog = Promise.resolve(new PostHog(apiKey, options)) }