Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If async-storage or expo-file-system is not installed, the SDK will fallback to persistence: memory and log a warning #146

Merged
merged 8 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions posthog-react-native/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 8 additions & 2 deletions posthog-react-native/src/posthog-rn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,14 @@ 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' }))
}
} else {
posthog = Promise.resolve(new PostHog(apiKey, options))
}
Expand Down
Loading