diff options
author | dan <dan.abramov@gmail.com> | 2024-04-18 04:39:29 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-18 04:39:29 +0100 |
commit | 02becdf4491cded0f0435e880e1ad4030d500403 (patch) | |
tree | 725ffa94609c380d4a9d8f25609642eb7d4b4748 /src/state/shell/selected-feed.tsx | |
parent | 086dc93a7a6e69b0df2ed084ee68bb4e26c13f88 (diff) | |
download | voidsky-02becdf4491cded0f0435e880e1ad4030d500403.tar.zst |
[Statsig] Make gate checks lazily (#3594)
Diffstat (limited to 'src/state/shell/selected-feed.tsx')
-rw-r--r-- | src/state/shell/selected-feed.tsx | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/src/state/shell/selected-feed.tsx b/src/state/shell/selected-feed.tsx index 5c0ac0b02..dca3445f3 100644 --- a/src/state/shell/selected-feed.tsx +++ b/src/state/shell/selected-feed.tsx @@ -1,5 +1,6 @@ import React from 'react' +import {Gate} from '#/lib/statsig/gates' import {useGate} from '#/lib/statsig/statsig' import {isWeb} from '#/platform/detection' import * as persisted from '#/state/persisted' @@ -10,7 +11,7 @@ type SetContext = (v: string) => void const stateContext = React.createContext<StateContext>('home') const setContext = React.createContext<SetContext>((_: string) => {}) -function getInitialFeed(startSessionWithFollowing: boolean) { +function getInitialFeed(gate: (gateName: Gate) => boolean) { if (isWeb) { if (window.location.pathname === '/') { const params = new URLSearchParams(window.location.search) @@ -26,7 +27,7 @@ function getInitialFeed(startSessionWithFollowing: boolean) { return feedFromSession } } - if (!startSessionWithFollowing) { + if (!gate('start_session_with_following')) { const feedFromPersisted = persisted.get('lastSelectedHomeFeed') if (feedFromPersisted) { // Fall back to the last chosen one across all tabs. @@ -37,10 +38,8 @@ function getInitialFeed(startSessionWithFollowing: boolean) { } export function Provider({children}: React.PropsWithChildren<{}>) { - const startSessionWithFollowing = useGate('start_session_with_following') - const [state, setState] = React.useState(() => - getInitialFeed(startSessionWithFollowing), - ) + const gate = useGate() + const [state, setState] = React.useState(() => getInitialFeed(gate)) const saveState = React.useCallback((feed: string) => { setState(feed) |