Send beta user state with AppView requests (#11474)

This commit is contained in:
DS Boyce
2026-08-18 09:50:15 -07:00
committed by GitHub
parent 45aa1a67b0
commit cc3622b583
7 changed files with 159 additions and 22 deletions
+8 -8
View File
@@ -9,6 +9,10 @@ import {Platform} from 'react-native'
import {type Result, type WidenPrimitives} from '@growthbook/growthbook-react'
import {Logger} from '#/logger'
import {
getCachedIsBetaUser,
subscribeToCachedIsBetaUser,
} from '#/state/preferences/beta-user-cache'
import {
Features,
features as feats,
@@ -33,7 +37,7 @@ import {type Metrics, metrics} from '#/analytics/metrics'
import * as refParams from '#/analytics/misc/refParams'
import * as env from '#/env'
import {useGeolocationServiceResponse} from '#/geolocation/service'
import {account, device} from '#/storage'
import {device} from '#/storage'
export * as utils from '#/analytics/utils'
export const features = {init, refresh}
@@ -131,7 +135,7 @@ export const setupDeviceId = getAndMigrateDeviceId()
/**
* Reads the per-account cached `isBetaUser` flag for `did`, kept in sync with
* writes from `BetaUserStorageSync` and the beta settings toggle.
* PDS preference query results and the beta settings toggle.
*
* This deliberately does not use `useStorage`, whose `useState` seeds once and
* only updates via the change listener. The consuming `AnalyticsContext` lives
@@ -146,17 +150,13 @@ function useAccountIsBetaUser(did: string | undefined): boolean | undefined {
const subscribe = useCallback(
(onChange: () => void) => {
if (!did) return () => {}
const sub = account.addOnValueChangedListener(
[did, 'isBetaUser'],
onChange,
)
return () => sub.remove()
return subscribeToCachedIsBetaUser(did, onChange)
},
[did],
)
const getSnapshot = useCallback(() => {
if (!did) return undefined
return account.get([did, 'isBetaUser'])
return getCachedIsBetaUser(did)
}, [did])
return useSyncExternalStore(subscribe, getSnapshot)
}