When developing new features for Element, we use feature flags to give us more flexibility and control over when and where those features are enabled.
For example, flags make the following things possible:
- Extended testing of a feature via labs on develop
- Enabling features when ready instead of the first moment the code is released
- Testing a feature with a specific set of users (by enabling only on a specific Element instance)
The size of the feature controlled by a feature flag may vary widely: it could be a large project like reactions or a smaller change to an existing algorithm. A large project might use several feature flags if it's useful to control the deployment of different portions independently.
Everyone involved in a feature (engineering, design, product, reviewers) should think about its deployment plan up front as best as possible so we can have the right feature flags in place from the start.
Historically, we have often used feature flags to guard client features that depend on unstable spec features. Unfortunately, there was never clear agreement about how long such a flag should live for, when it should be removed, etc.
Under the new spec process, server-side unstable features can be used by clients and enabled by default as long as clients commit to doing the associated clean up work once a feature stabilises.
When starting work on a feature, we should create a matching feature flag:
- Add a new setting of the form:
"feature_cats": {
isFeature: true,
displayName: _td("Adds cats everywhere"),
supportedLevels: LEVELS_FEATURE,
default: false,
},
- Check whether the feature is enabled as appropriate:
SettingsStore.getValue("feature_cats")
- Document the feature in the labs documentation
With these steps completed, the feature is disabled by default, but can be enabled on develop and nightly by interested users for testing.
Different features may have different deployment plans for when to enable where. The following lists a few common options.
Set the feature to true
in the
develop
and
nightly
configs:
"features": {
"feature_cats": true
},
Set the feature to true
in the
staging / app
and
release
configs.
Note: The above will only enable the feature for https://app.element.io and official Element
Desktop builds. It will not be enabled for self-hosted installed, custom desktop builds, etc. To
cover these cases, change the setting's default
in Settings.tsx
to true
.
Once we're confident that a feature is working well, we should remove or convert the flag.
If the feature is meant to be turned off/on by the user:
- Remove
isFeature
from the setting - Change the
default
totrue
(if desired). - Remove the feature from the labs documentation
- Celebrate! 🥳
If the feature is meant to be forced on (non-configurable):
- Remove the setting
- Remove all
getValue
lines that test for the feature. - Remove the feature from the labs documentation
- If applicable, remove the feature state from develop, nightly, staging / app, and release configs
- Celebrate! 🥳