Skip to main content

define-feature-flag

Define a frontend feature flag with `defineFlag` and wire its readers. Use when adding, suggesting, or changing a feature flag, PostHog flag, `ENABLE_*` env flag, `useFeatureFlag`, `isFeatureEnabled`, or `ShowFeatureFlag`.

소스 정보

저장소
macro-inc/macro
최근 소스 활동
2026년 9월 3일 15:18
감지된 SKILL.md 언어
영어
스타
4,599
포크
446

설치 방법

기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.

소스 파일 검토

설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.

SKILL.md 표시 중

SKILL.md
소스 지침 · 읽기 전용 미리보기
name
define-feature-flag
description
Define a frontend feature flag with `defineFlag` and wire its readers. Use when adding, suggesting, or changing a feature flag, PostHog flag, `ENABLE_*` env flag, `useFeatureFlag`, `isFeatureEnabled`, or `ShowFeatureFlag`.
# Define a frontend feature flag Frontend only. Registry: `apps/web/src/lib/core/constant/featureFlags.ts`. There is no shared backend flag system. ## 1. Remote or env-only? | | Remote | Env-only | |---|---|---| | Source of truth | PostHog in deployed envs | `default`, optionally overridden by env | | Discriminator | `key` present | no `key` | | `env` | optional local override | optional override of `default` | | `default` | omit / `undefined` to fall through to PostHog | required | | Readers | `useFeatureFlag`, `ShowFeatureFlag`, `isFeatureEnabled` | `isFeatureEnabled` only | Most product rollouts are **remote**. Use **env-only** when there is no PostHog flag and never will be (compile-time / local kill switch). Ask before assuming. If the user said "flag it" and did not mention PostHog, prefer remote and confirm. ## 2. Define it Add one `defineFlag` next to its neighbors. Do not add `ENABLE_*_FLAG` / `_OVERRIDE` / `ENABLE_*()` triples or a raw PostHog string at the call site. - `key` (remote): kebab-case, named after the question (`enable-foo`, `disable-browser-turso-cache`). Export the object in matching camelCase (`enableFoo`). - `env`: the name after `VITE_`, e.g. `'ENABLE_FOO'` → `VITE_ENABLE_FOO`. - `default`: used when env is unset. On a remote flag, `false` is a real override and **skips PostHog**. On-in-dev / on-in-local is `DEV_MODE_ENV || undefined` or `LOCAL_ONLY || undefined`, not the boolean itself. - Never invert on the flag object. If the product question is "disable X", invert at the call site (`!isFeatureEnabled(disableX)`). - Env-only exports that are used as `if (ENABLE_FOO)` must be the boolean: `defineFlag({ env, default }).enabled`. The object is always truthy. ```ts export const enableFoo = defineFlag({ key: 'enable-foo', env: 'ENABLE_FOO', default: DEV_MODE_ENV || undefined, }); export const ENABLE_BAR = defineFlag({ env: 'ENABLE_BAR', default: false, }).enabled; ``` Do not create the PostHog flag. Ask which project / environment it should live in and wait. ## 3. Read it ```ts const foo = useFeatureFlag(enableFoo); // component: foo().enabled <ShowFeatureFlag flag={enableFoo}>{...}</ShowFeatureFlag> isFeatureEnabled(enableFoo) // queries, helpers, env-only ``` A thin `useXFlag` wrapper around `useFeatureFlag(flag)` is fine when several call sites share the same read. Compose flags in the wrapper (calendar search requires calendar UI), not on the flag object. `useFeatureFlag` / `ShowFeatureFlag` take a `RemoteFlag`. Passing an env-only flag is a type error. ## Don't - Migrate existing FLAG / OVERRIDE / string `useFeatureFlag` call sites unless you are already changing that flag or were asked to. - Invent a second helper (`resolveFeatureFlag` for new flags, a global `flags.foo` map, `.use()` / `.Show()` on the object).
GitHub에서 보기