Feature Flags
Within the utils package, we expose a set of utility functions that allow consumers to use flags to enable or disable features within their application with minimal configuration.
The utils rely on the official @vercel/flags
package (only stable parts of it), extending its functionality to cover:
- Integration with the Vercel toolbar (enabling easy overrides of flag values on preview deployments)
- Integration with the edge config store to switch flags on and off without re-deployment
- Encrypted flag values by default (no leakage in the DOM), but comes with an option to be disabled to make flags available on the client (see explanation below)
- A utility to fetch flag values within
getServerSideProps
andmiddleware.ts
- A utility to fetch flag values on the client (unencrypted flags only!)
- Optionally 100% type-safe flags with the help of a script that fetches the flags from the edge config store and generates types based on them
Why can't I use encrypted flags on the client?
The package uses a private environment variable to encrypt and decrypt the cookies used to store flag values and overrides.
Since this variable is not available on the client, flags will have to be stored in clear text. If you need to use your flags on the client and this is an acceptable tradeoff for you, you can set encryptionMode
to false on every function this packages exposes.
Note: If you disable encryption somewhere along the chain, you'll
need to disable it everywhere, otherwise you will encounter errors.