diff --git a/src/analytics/features/index.ts b/src/analytics/features/index.ts index d438a2f8d7..81eb9eced0 100644 --- a/src/analytics/features/index.ts +++ b/src/analytics/features/index.ts @@ -1,3 +1,5 @@ +import {MMKV} from '@bsky.app/react-native-mmkv' +import {setPolyfills} from '@growthbook/growthbook' import {GrowthBook} from '@growthbook/growthbook-react' import {getNavigationMetadata, type Metadata} from '#/analytics/metadata' @@ -5,6 +7,20 @@ import * as env from '#/env' export {Features} from '#/analytics/features/types' +const CACHE = new MMKV({id: 'bsky_features_cache'}) + +setPolyfills({ + localStorage: { + getItem: key => { + const value = CACHE.getString(key) + return value != null ? JSON.parse(value) : null + }, + setItem: async (key, value) => { + CACHE.set(key, JSON.stringify(value)) + }, + }, +}) + /** * We vary the amount of time we wait for GrowthBook to fetch feature * gates based on the strategy specified.