agentleFS
primerprimer/react/.agents/skills/feature-flags/SKILL.md

feature-flags

Skill3.9k starsChanged 3 days agoMITView on GitHub

Use when: implementing, creating, testing, or debugging feature flags in Primer React. Covers useFeatureFlag hook, FeatureFlags provider, DefaultFeatureFlags, FeatureFlagScope, Storybook integration, and the feature flag lifecycle at GitHub.

  • Reads credentials

We split this skill into the rules it gives an agent

2 rules. 0 are common, 0 are distinctive, and 2 are very specific to this project.

  • 0

    Common

    Most of the 17 edited versions we read keep these.

  • 0

    Distinctive

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use snake_case: primer_react_my_feature_name

    line 64
  2. Very specific:

    Check packages/react/src/FeatureFlags/DefaultFeatureFlags.ts for the current list of all registered feature flags and their default values.

    line 203

“Common” is measured: kept by at least 6 in 10 of the 17 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Feature Flags in Primer React

Feature flags provide a way to incrementally build and deliver changes in Primer alongside the feature flag system at GitHub. They help build confidence in changes and improve the reliability of releases.

Architecture

Feature flags are implemented in packages/react/src/FeatureFlags/ with these core pieces:

FilePurpose
FeatureFlags.tsxReact context provider component
useFeatureFlag.tsHook to check if a flag is enabled
FeatureFlagScope.tsClass that manages flag collections and merging
DefaultFeatureFlags.tsDefault flag values (all flags listed here)
FeatureFlagContext.tsReact context definition
index.tsPublic exports

Exports

Feature flags are exported from @primer/react/experimental:

import {FeatureFlags, useFeatureFlag, DefaultFeatureFlags} from '@primer/react/experimental'

They are NOT exported from the main @primer/react entry point.

How to Use a Feature Flag in a Component

1. Add the flag to DefaultFeatureFlags

Register your flag in packages/react/src/FeatureFlags/DefaultFeatureFlags.ts with a default value of false:

export const DefaultFeatureFlags = FeatureFlagScope.create({
  // ...existing flags...
  primer_react_my_new_feature: false,
})

2. Use useFeatureFlag in your component

import {useFeatureFlag} from '../FeatureFlags'

function MyComponent() {
  const enabled = useFeatureFlag('primer_react_my_new_feature')

  if (enabled) {
    return <NewBehavior />
  }
  return <CurrentBehavior />
}

3. Naming conventions

  • Prefix with primer_react_ for flags in the @primer/react package
  • Use snake_case: primer_react_my_feature_name

Patterns

Change behavior conditionally

function ExampleComponent({children}) {
  const enabled = useFeatureFlag('primer_react_my_feature')

  return (
    <button
      onClick={() => {
        if (enabled) {
          // new behavior
        } else {
          // current behavior
        }
      }}
    >
      {children}
    </button>
  )
}

Toggle between two component versions

function ExampleComponent(props) {
  const enabled = useFeatureFlag('primer_react_my_feature')
  if (enabled) {
    return <ExampleComponentNext {...props} />
  }
  return <ExampleComponentClassic {...props} />
}

Data attributes on DOM elements

function MyOverlay() {
  const enabled = useFeatureFlag('primer_react_my_feature')
  return <div data-my-feature={enabled ? '' : undefined} />
}

Real Codebase Examples

CSS anchor positioning (packages/react/src/AnchoredOverlay/AnchoredOverlay.tsx)

const cssAnchorPositioning = useFeatureFlag('primer_react_css_anchor_positioning')
useEffect(() => {
  if (cssAnchorPositioning && !hasLoadedAnchorPositioningPolyfill.current) {
    applyAnchorPositioningPolyfill()
    hasLoadedAnchorPositioningPolyfill.current = true
  }
}, [open, overlayRef, updateOverlayRef, cssAnchorPositioning])

Breadcrumbs overflow (packages/react/src/Breadcrumbs/Breadcrumbs.tsx)

const overflowMenuEnabled = useFeatureFlag('primer_react_breadcrumbs_overflow_menu')

Testing with Feature Flags

Wrap your component with the FeatureFlags provider to set flag values in tests:

import {FeatureFlags} from '../../FeatureFlags'

// Test with flag enabled
render(
  <FeatureFlags flags={{primer_react_my_feature: true}}>
    <MyComponent />
  </FeatureFlags>,
)

// Test with flag disabled (or omit the wrapper to use default values from DefaultFeatureFlags)
render(
  <FeatureFlags flags={{primer_react_my_feature: false}}>
    <MyComponent />
  </FeatureFlags>,
)

Key testing behaviors

  • Unknown flags default to false
  • Nested FeatureFlags providers merge flags — inner values override outer values
  • You should test both enabled and disabled states

Storybook Integration

Enable flag in a specific story

import {FeatureFlags} from '../../FeatureFlags'

export const WithFeatureEnabled = () => (
  <FeatureFlags flags={{primer_react_my_feature: true}}>
    <MyComponent />
  </FeatureFlags>
)

export const WithFeatureDisabled = () => <MyComponent />

Enable flag in all stories

Storybook's global preview (packages/react/.storybook/preview.jsx) already wraps all stories in a FeatureFlags provider, using DefaultFeatureFlags as the source of default values and toolbar options. In most cases you only need to register your flag in DefaultFeatureFlags.ts; you do not need to manually add it to the FeatureFlags wrapper.

To enable a flag globally via environment, add its exact flag name (for example, primer_react_my_feature) to the featureFlagEnvList set in preview.jsx, and set the corresponding env var to 1 (for example, VITE_primer_react_my_feature=1). The preview code reads import.meta.env[\VITE*${flag}`], so the part after VITE*` must match the flag string exactly.

Feature Flag Lifecycle

  1. Create — Register the flag in DefaultFeatureFlags.ts with value false
  2. Implement — Use useFeatureFlag() in components, write tests for both states
  3. Test in Storybook — Create stories with the flag enabled/disabled
  4. Ship — Merge to main; the flag remains off by default
  5. Enable at GitHub — Use DevPortal to enable for specific actors, then staffship, then GA
  6. Remove — Once fully rolled out, remove the flag from code and DefaultFeatureFlags.ts

Temporarily testing in Dotcom CI

Set your flag to true in DefaultFeatureFlags.ts to enable it by default for CI testing. Set it back to false before merging.

FeatureFlags Provider Internals

  • FeatureFlagScope.create(flags) — Creates a scope from a plain object {[key: string]: boolean}
  • FeatureFlagScope.merge(a, b) — Merges two scopes; b values override a
  • The FeatureFlags component merges parent context flags with the provided flags prop
  • DefaultFeatureFlags is the initial context value — it defines all known flags

Current Feature Flags

Check packages/react/src/FeatureFlags/DefaultFeatureFlags.ts for the current list of all registered feature flags and their default values.

Download now (ZIP)

Trending

Steady: 0 new projects took it in the last 4 weeks, none the 4 weeks before.thin data

Week of Aug 30: 0 new projectsWeek of Sep 6: 0 new projectsWeek of Sep 13: 0 new projectsWeek of Sep 20: 0 new projectsWeek of Sep 27: 0 new projectsWeek of Oct 4: 0 new projectsWeek of Oct 11: 0 new projectsWeek of Oct 18: 0 new projects
Aug 2026Sep 2026Oct 2026
New projects taking a version of this file each week, over the 8 weeks our latest run read: only 0 in all, so this is a hint, not a trend.

Who's talking about primer/react

The biggest 5 of 36 mentions linking to the repository that our crawl found. Each line is their own headline.

See all 36

Talked about on GitHub (36 times).

On GitHub · 36

31 more on GitHub
  • Other versions20 projects use a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 20

    1. react/react★ 252ksame name
    2. facebook/react★ 252ksame name
    3. getsentry/sentry★ 46ksame name
    4. redis/RedisInsight★ 8.9ksame name
    5. BuilderIO/agent-native★ 7.6ksame name
    6. macro-inc/macro★ 6ksame name
    7. marcus/sidecar★ 1.1ksame name
    8. kid-sid/claude-spellbook★ 190same name
    9. irahardianto/awesome-agv★ 157same name
    10. shepherdjerred/monorepo★ 111same name

    10 more not listed

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • Used alongsideProjects with it also use background-jobs, caching and 10 more.

    Other files people use alongside this one.

    Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
    • YepAPISkill

      background-jobs

      Queue workers with BullMQ/Inngest/Trigger.dev, job retries, dead letter queues, concurrency.

      Also in 3 projects that use this

    • zebbernSkill

      caching

      Caching strategies — invalidation, TTL guidelines, cache keys, cache layers, and when not to cache. Use when implementing or reviewing caching logic.

      Also in 3 projects that use this

    • harperaaSkill

      rate-limiting

      Implement rate limiting to prevent brute force attacks, spam, and resource abuse. Use this skill when you need to protect endpoints from automated attacks, prevent API abuse, limit request frequency, or control infrastructure costs. Triggers include "rate limiting", "rate limit", "brute force", "prevent spam", "API abuse", "resource exhaustion", "DoS", "withRateLimit", "too many requests", "429 error".

      Also in 3 projects that use this

    • AnthropicSkill

      incident-response

      Run an incident response workflow — triage, communicate, and write postmortem. Trigger with "we have an incident", "production is down", an alert that needs severity assessment, a status update mid-incident, or when writing a blameless postmortem after resolution.

      Also in 5 projects that use this

    • OpenAISkill

      observability

      Vercel Observability expert guidance — Drains (logs, traces, speed insights, web analytics), Web Analytics, Speed Insights, runtime logs, custom events, OpenTelemetry integration, and monitoring dashboards. Use when instrumenting, debugging, or optimizing application performance and user experience on Vercel.

      Also in 5 projects that use this

    • JohnJBorenSkill

      ci-cd

      CI/CD pipeline design, GitHub Actions, testing automation, and deployment strategies

      Also in 3 projects that use this

  • In this repository17 other files it gives its agents.

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

Reviews can't be read right now.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.