feature-flags
π―Skillfrom facebook/react
Manages React feature flags across channels, enabling targeted testing, gating, and debugging of experimental features with precise control.
Installation
npx skills add https://github.com/facebook/react --skill feature-flagsSkill Details
Use when feature flag tests fail, flags need updating, understanding @gate pragmas, debugging channel-specific test failures, or adding new flags to React.
Overview
# React Feature Flags
Flag Files
| File | Purpose |
|------|---------|
| packages/shared/ReactFeatureFlags.js | Default flags (canary), __EXPERIMENTAL__ overrides |
| packages/shared/forks/ReactFeatureFlags.www.js | www channel, __VARIANT__ overrides |
| packages/shared/forks/ReactFeatureFlags.native-fb.js | React Native, __VARIANT__ overrides |
| packages/shared/forks/ReactFeatureFlags.test-renderer.js | Test renderer |
Gating Tests
`@gate` pragma (test-level)
Use when the feature is completely unavailable without the flag:
```javascript
// @gate enableViewTransition
it('supports view transitions', () => {
// This test only runs when enableViewTransition is true
// and is SKIPPED (not failed) when false
});
```
`gate()` inline (assertion-level)
Use when the feature exists but behavior differs based on flag:
```javascript
it('renders component', async () => {
await act(() => root.render(
if (gate(flags => flags.enableNewBehavior)) {
expect(container.textContent).toBe('new output');
} else {
expect(container.textContent).toBe('legacy output');
}
});
```
Adding a New Flag
- Add to
ReactFeatureFlags.jswith default value - Add to each fork file (
.www.js,.native-fb.js, etc.) - If it should vary in www/RN, set to
__VARIANT__in the fork file - Gate tests with
@gate flagNameor inlinegate()
Checking Flag States
Use /flags to view states across channels. See the flags skill for full command options.
`__VARIANT__` Flags (GKs)
Flags set to __VARIANT__ simulate gatekeepers - tested twice (true and false):
```bash
/test www
/test www variant false
```
Debugging Channel-Specific Failures
- Run
/flags --diffto compare values - Check
@gateconditions - test may be gated to specific channels - Run
/testto isolate the failure - Verify flag exists in all fork files if newly added
Common Mistakes
- Forgetting both variants - Always test
wwwANDwww variant falsefor__VARIANT__flags - Using @gate for behavior differences - Use inline
gate()if both paths should run - Missing fork files - New flags must be added to ALL fork files, not just the main one
- Wrong gate syntax - It's
gate(flags => flags.name), notgate('name')
More from this repository6
Automatically fixes code formatting and linting issues to ensure clean, compliant code before committing.
Validates code changes by running formatting, linting, type checking, and testing across source and www directories.
Runs React codebase tests across different release channels with configurable flags and test patterns.
Extracts and manages error codes for React, helping developers identify and assign unique codes to new error messages.
Runs Flow type checking for React code, detecting type errors across different renderers like DOM, browser, and React Native.
Checks and compares feature flag states across different release channels with detailed visualization and debugging capabilities.