Skip to content

Prepare frontend for a new on demand feature flag evaluation

Created by: erzhtor

Part 1 of https://github.com/sourcegraph/sourcegraph/issues/35543.

Description

We are migrating soon to proper on-demand feature flag evaluation. It means that the feature flag is evaluated only whenever it is requested, rather than assigning users to all existing feature flags on the initial page load.

This PR:

  • Refactors frontend feature flag usage to prepare for upcoming on-demand feature flag evaluation migration

The new API brief description

  1. There is a context provider which wraps the whole app:
<FeatureFlagsProvider>...</FeatureFlagsProvider>
  1. And the code for getting a feature flag:
const [value, status, error] = useFeatureFlag('some-feature-flag')
value // boolean
status // 'initial' | 'loading' | 'error'
error // null | Error

2.2 Another HOC API version:

const MyFeatureFlaggedComponent = withFeatureFlag(MyComponent, 'some-feature-flag', true) // default is true, so can be omitted
  1. There is also a mock provider available to override feature flags for testing purposes:
<MockedFeatureFlagsProvider overrides={new Map([['my-feature-flag', true]]}>
...
</MockedFeatureFlagsProvider>

Test plan

  • All CI jobs are passing
  • Codebase looks good
  • And running locally works as previously without any changes

App preview:

Check out the client app preview documentation to learn more.

Merge request reports

Loading