Add setting for opting in to beta features (#11123)

This commit is contained in:
DS Boyce
2026-07-15 06:06:54 -07:00
committed by GitHub
parent d7f40b7e7f
commit 3c5c11c002
20 changed files with 685 additions and 90 deletions
+37
View File
@@ -0,0 +1,37 @@
import {useEffect} from 'react'
import {usePreferencesQuery} from '#/state/queries/preferences'
import {useSession} from '#/state/session'
import {account} from '#/storage'
/**
* Caches `bskyAppState.isBetaUser` from preferences into synchronous device
* storage so analytics can read it at init (before beta-gated features are
* evaluated). Scoped per account, since `isBetaUser` is account-specific:
* a global cache would let one account's value leak into another after a
* switch, until the new account's preferences loaded. Must be mounted below
* `QueryProvider`, since the analytics providers that consume the cached value
* sit above it.
*
* Lives outside `#/analytics` so that module never imports the preferences
* query, which would create a circular import.
*/
export function BetaUserStorageSync() {
const {currentAccount} = useSession()
const did = currentAccount?.did
const {data: preferences} = usePreferencesQuery()
const isBetaUser = preferences?.bskyAppState?.isBetaUser
useEffect(() => {
if (!did) return
if (isBetaUser === undefined) return
/*
* Guard against a redundant write on every warm boot. Writing triggers the
* storage change listener, which re-renders the analytics subtree.
*/
if (account.get([did, 'isBetaUser']) === isBetaUser) return
account.set([did, 'isBetaUser'], isBetaUser)
}, [did, isBetaUser])
return null
}
+1
View File
@@ -50,6 +50,7 @@ export const DEFAULT_LOGGED_OUT_PREFERENCES: UsePreferencesQueryResponse = {
queuedNudges: [],
activeProgressGuide: undefined,
nuxs: [],
isBetaUser: undefined,
},
postInteractionSettings: {
threadgateAllowRules: undefined,
+15
View File
@@ -438,6 +438,21 @@ export function useSetActiveProgressGuideMutation() {
})
}
export function useSetIsBetaUserMutation() {
const queryClient = useQueryClient()
const agent = useAgent()
return useMutation({
mutationFn: async (isBetaUser: boolean) => {
await agent.setIsBetaUser(isBetaUser)
// triggers a refetch
await queryClient.invalidateQueries({
queryKey: preferencesQueryKey,
})
},
})
}
export function useSetVerificationPrefsMutation() {
const ax = useAnalytics()
const queryClient = useQueryClient()