feature-flags
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseReact Feature Flags
React 功能标志
Flag Files
标志文件
| File | Purpose |
|---|---|
| Default flags (canary), |
| www channel, |
| React Native, |
| Test renderer |
| 文件 | 用途 |
|---|---|
| 默认标志(金丝雀版本), |
| www渠道, |
| React Native, |
| 测试渲染器 |
Gating Tests
测试门控
@gate
pragma (test-level)
@gate@gate
编译指示(测试级别)
@gateUse 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
});当功能在没有标志的情况下完全不可用时使用:
javascript
// @gate enableViewTransition
it('supports view transitions', () => {
// 仅当enableViewTransition为true时运行此测试
// 为false时会跳过(而非失败)
});gate()
inline (assertion-level)
gate()内联 gate()
(断言级别)
gate()Use when the feature exists but behavior differs based on flag:
javascript
it('renders component', async () => {
await act(() => root.render(<App />));
if (gate(flags => flags.enableNewBehavior)) {
expect(container.textContent).toBe('new output');
} else {
expect(container.textContent).toBe('legacy output');
}
});当功能存在但行为会根据标志不同而变化时使用:
javascript
it('renders component', async () => {
await act(() => root.render(<App />));
if (gate(flags => flags.enableNewBehavior)) {
expect(container.textContent).toBe('new output');
} else {
expect(container.textContent).toBe('legacy output');
}
});Adding a New Flag
添加新标志
- Add to with default value
ReactFeatureFlags.js - Add to each fork file (,
*.www.js, etc.)*.native-fb.js - If it should vary in www/RN, set to in the fork file
__VARIANT__ - Gate tests with or inline
@gate flagNamegate()
- 在中添加并设置默认值
ReactFeatureFlags.js - 添加到每个分支文件(、
*.www.js等)*.native-fb.js - 如果需要在www/React Native中有所不同,在分支文件中设置为
__VARIANT__ - 使用或内联
@gate flagName对测试进行门控gate()
Checking Flag States
检查标志状态
Use to view states across channels. See the skill for full command options.
/flagsflags使用查看各渠道的状态。查看技能获取完整命令选项。
/flagsflags__VARIANT__
Flags (GKs)
__VARIANT____VARIANT__
标志(门控器)
__VARIANT__Flags set to simulate gatekeepers - tested twice (true and false):
__VARIANT__bash
/test www <pattern> # __VARIANT__ = true
/test www variant false <pattern> # __VARIANT__ = false设置为的标志模拟门控器 - 会测试两次(true和false):
__VARIANT__bash
/test www <pattern> # __VARIANT__ = true
/test www variant false <pattern> # __VARIANT__ = falseDebugging Channel-Specific Failures
调试特定渠道的测试失败
- Run to compare values
/flags --diff <channel1> <channel2> - Check conditions - test may be gated to specific channels
@gate - Run to isolate the failure
/test <channel> <pattern> - Verify flag exists in all fork files if newly added
- 运行比较值
/flags --diff <channel1> <channel2> - 检查条件 - 测试可能被门控到特定渠道
@gate - 运行隔离失败场景
/test <channel> <pattern> - 如果是新添加的标志,验证其存在于所有分支文件中
Common Mistakes
常见错误
- Forgetting both variants - Always test AND
wwwforwww variant falseflags__VARIANT__ - Using @gate for behavior differences - Use inline if both paths should run
gate() - Missing fork files - New flags must be added to ALL fork files, not just the main one
- Wrong gate syntax - It's , not
gate(flags => flags.name)gate('name')
- 忘记测试两种变体 - 对于标志,务必同时测试
__VARIANT__和wwwwww variant false - 对行为差异使用@gate - 如果两种路径都需要运行,请使用内联
gate() - 遗漏分支文件 - 新标志必须添加到所有分支文件,而不仅仅是主文件
- 错误的gate语法 - 正确写法是,而非
gate(flags => flags.name)gate('name')