2019-11-07 14:31:52 +01:00
|
|
|
# Feature flags
|
|
|
|
|
2020-07-17 12:45:29 +02:00
|
|
|
When developing new features for Element, we use feature flags to give us more
|
2019-11-07 14:31:52 +01:00
|
|
|
flexibility and control over when and where those features are enabled.
|
|
|
|
|
|
|
|
For example, flags make the following things possible:
|
|
|
|
|
2022-12-09 13:28:29 +01:00
|
|
|
- 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)
|
2019-11-07 14:31:52 +01:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
## Interaction with spec process
|
|
|
|
|
|
|
|
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](https://github.com/matrix-org/matrix-doc/pull/2324), 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.
|
|
|
|
|
|
|
|
## Starting work on a feature
|
|
|
|
|
|
|
|
When starting work on a feature, we should create a matching feature flag:
|
|
|
|
|
2019-11-08 16:19:23 +01:00
|
|
|
1. Add a new
|
2022-03-25 17:43:03 +01:00
|
|
|
[setting](https://github.com/matrix-org/matrix-react-sdk/blob/develop/src/settings/Settings.tsx)
|
2019-11-08 16:19:23 +01:00
|
|
|
of the form:
|
2022-12-09 13:28:29 +01:00
|
|
|
|
2019-11-07 14:31:52 +01:00
|
|
|
```js
|
|
|
|
"feature_cats": {
|
|
|
|
isFeature: true,
|
|
|
|
displayName: _td("Adds cats everywhere"),
|
|
|
|
supportedLevels: LEVELS_FEATURE,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
```
|
2022-12-09 13:28:29 +01:00
|
|
|
|
2019-11-08 16:19:23 +01:00
|
|
|
2. Check whether the feature is enabled as appropriate:
|
2022-12-09 13:28:29 +01:00
|
|
|
|
2019-11-07 14:31:52 +01:00
|
|
|
```js
|
2022-12-09 13:28:29 +01:00
|
|
|
SettingsStore.getValue("feature_cats");
|
2019-11-07 14:31:52 +01:00
|
|
|
```
|
2022-12-09 13:28:29 +01:00
|
|
|
|
2020-09-30 13:00:02 +02:00
|
|
|
3. Document the feature in the [labs documentation](https://github.com/vector-im/element-web/blob/develop/docs/labs.md)
|
2019-11-07 14:31:52 +01:00
|
|
|
|
|
|
|
With these steps completed, the feature is disabled by default, but can be
|
2020-04-23 12:06:15 +02:00
|
|
|
enabled on develop and nightly by interested users for testing.
|
2019-11-07 14:31:52 +01:00
|
|
|
|
2019-11-08 16:57:46 +01:00
|
|
|
Different features may have different deployment plans for when to enable where.
|
|
|
|
The following lists a few common options.
|
2019-11-07 14:31:52 +01:00
|
|
|
|
2020-04-23 12:06:15 +02:00
|
|
|
## Enabling by default on develop and nightly
|
2019-11-07 14:31:52 +01:00
|
|
|
|
2020-08-17 22:00:04 +02:00
|
|
|
Set the feature to `true` in the
|
2020-09-30 13:00:02 +02:00
|
|
|
[develop](https://github.com/vector-im/element-web/blob/develop/element.io/develop/config.json)
|
2020-04-23 12:06:15 +02:00
|
|
|
and
|
2020-09-30 13:58:44 +02:00
|
|
|
[nightly](https://github.com/vector-im/element-desktop/blob/develop/element.io/nightly/config.json)
|
2020-04-23 12:06:15 +02:00
|
|
|
configs:
|
2019-11-07 14:31:52 +01:00
|
|
|
|
|
|
|
```json
|
|
|
|
"features": {
|
2020-08-17 22:00:04 +02:00
|
|
|
"feature_cats": true
|
2019-11-07 14:31:52 +01:00
|
|
|
},
|
|
|
|
```
|
|
|
|
|
2020-04-23 12:06:15 +02:00
|
|
|
## Enabling by default on staging, app, and release
|
|
|
|
|
2020-08-17 22:00:04 +02:00
|
|
|
Set the feature to `true` in the
|
2020-09-30 13:00:02 +02:00
|
|
|
[staging / app](https://github.com/vector-im/element-web/blob/develop/element.io/app/config.json)
|
2020-04-23 12:06:15 +02:00
|
|
|
and
|
2020-09-30 13:58:44 +02:00
|
|
|
[release](https://github.com/vector-im/element-desktop/blob/develop/element.io/release/config.json)
|
2020-04-23 12:06:15 +02:00
|
|
|
configs.
|
2019-11-07 14:31:52 +01:00
|
|
|
|
2020-08-17 22:00:04 +02:00
|
|
|
**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
|
2022-03-25 17:43:03 +01:00
|
|
|
cover these cases, change the setting's `default` in `Settings.tsx` to `true`.
|
2019-11-07 14:31:52 +01:00
|
|
|
|
|
|
|
## Feature deployed successfully
|
|
|
|
|
2020-08-17 22:00:04 +02:00
|
|
|
Once we're confident that a feature is working well, we should remove or convert the flag.
|
2019-11-07 14:31:52 +01:00
|
|
|
|
2020-08-17 22:00:04 +02:00
|
|
|
If the feature is meant to be turned off/on by the user:
|
2022-12-09 13:28:29 +01:00
|
|
|
|
2020-08-17 22:00:04 +02:00
|
|
|
1. Remove `isFeature` from the [setting](https://github.com/matrix-org/matrix-react-sdk/blob/develop/src/settings/Settings.ts)
|
|
|
|
2. Change the `default` to `true` (if desired).
|
2020-09-30 13:00:02 +02:00
|
|
|
3. Remove the feature from the [labs documentation](https://github.com/vector-im/element-web/blob/develop/docs/labs.md)
|
2020-08-17 22:00:04 +02:00
|
|
|
4. Celebrate! 🥳
|
2019-11-08 16:57:46 +01:00
|
|
|
|
2020-08-17 22:00:04 +02:00
|
|
|
If the feature is meant to be forced on (non-configurable):
|
2022-12-09 13:28:29 +01:00
|
|
|
|
2020-08-17 22:00:04 +02:00
|
|
|
1. Remove the [setting](https://github.com/matrix-org/matrix-react-sdk/blob/develop/src/settings/Settings.ts)
|
|
|
|
2. Remove all `getValue` lines that test for the feature.
|
2020-09-30 13:00:02 +02:00
|
|
|
3. Remove the feature from the [labs documentation](https://github.com/vector-im/element-web/blob/develop/docs/labs.md)
|
2020-08-17 22:00:04 +02:00
|
|
|
4. If applicable, remove the feature state from
|
2020-09-30 13:00:02 +02:00
|
|
|
[develop](https://github.com/vector-im/element-web/blob/develop/element.io/develop/config.json),
|
|
|
|
[nightly](https://github.com/vector-im/element-desktop/blob/develop/element.io/nightly/config.json),
|
|
|
|
[staging / app](https://github.com/vector-im/element-web/blob/develop/element.io/app/config.json),
|
2020-04-23 12:06:15 +02:00
|
|
|
and
|
2020-09-30 13:00:02 +02:00
|
|
|
[release](https://github.com/vector-im/element-desktop/blob/develop/element.io/release/config.json)
|
2019-11-08 16:57:46 +01:00
|
|
|
configs
|
2020-08-17 22:00:04 +02:00
|
|
|
5. Celebrate! 🥳
|