mcpbeat Sign in

Setting Feature Flags In Storybook Agent Skill

Use when writing a Storybook story for a component gated on a feature flag — boolean flags or multivariate/experiment-arm variants. Covers the `featureFlags` story parameter and why imperatively setting flags renders the flag-off branch in visual-regression snapshots while passing in jest.

1k tokens
context cost
the whole folder, loaded on every use
1
files
instructions only
0
copies elsewhere
how many repositories repackaged it
690
stars on the repo
on the repository, not the skill itself

Install

one command, takes just this skill from the repository
npx skills add https://github.com/PostHog/posthog --skill setting-feature-flags-in-storybook

The instruction itself

7 sections, as written by the author

Setting feature flags in Storybook

> [!WARNING]

> Never call featureFlagLogic.actions.setFeatureFlags(...) from a story. It silently

> no-ops in the visual-regression runtime (rendering the flag-OFF branch) while passing

> in jest — so unit tests stay green and the snapshot is wrong. Use the featureFlags

> story parameter instead.

Mental model: boolean flags always work (they ride the always-merged baseline);

variant values need a gate that _only the featureFlags parameter opens correctly_.

How to use it

This is the stable contract — prefer it over anything in "Under the hood" below.

Boolean flags (flag is simply on)

const meta: Meta = {
  title: 'Scenes/MyScene',
  parameters: {
    featureFlags: [FEATURE_FLAGS.MY_FLAG, FEATURE_FLAGS.OTHER_FLAG],
  },
}

Array entries are flags that evaluate to true. This is the common case.

Multivariate flags (pin a specific variant)

For a flag whose value is a variant string (experiment arms, multivariate rollouts), use

the record form — the array form can only express true:

// meta-level: applies to every story in the file
parameters: { featureFlags: { [FEATURE_FLAGS.THEME_OVERRIDE]: 'intent_plus' } }

// per-story: a different arm per story
export const ControlArm: Story = {
    parameters: { featureFlags: { [FEATURE_FLAGS.THEME_OVERRIDE]: 'control' } },
}
export const TreatmentArm: Story = {
    parameters: { featureFlags: { [FEATURE_FLAGS.THEME_OVERRIDE]: 'intent_plus' } },
}

You can mix booleans and variants in one record: { 'some-bool-flag': true, 'my-experiment': 'test_b' }.

> [!IMPORTANT]

> A story's parameters replace the meta's (shallow merge), so a per-story

> featureFlags drops every flag set at the meta level. **Re-list any meta flags you

> still need** — silently losing one renders the flag-off branch and is easy to miss.

Why the obvious approach fails

Setting flags imperatively (featureFlagLogic.actions.setFeatureFlags) works in jest

(NODE_ENV==='test') but not in the built visual-regression Storybook. posthog-js loads

flags and fires onFeatureFlags with an empty set, which dispatches setFeatureFlags

and wipes whatever you set imperatively — so the unit test passes while the snapshot

renders the flag-OFF branch. The featureFlags parameter avoids this by writing flags to

the always-merged baseline instead (below), so the empty callback can't clobber them.

> Do not try to fix this by disabling posthog-js flags (e.g. advanced_disable_feature_flags).

> The app shell (appLogic.showApp) only renders once receivedFeatureFlags is true,

> which is set by that same onFeatureFlags callback — suppress it and every

> Scenes-App/* story stalls behind a 3s timeout and flakes.

Under the hood (implementation detail — may drift)

> This explains _why_ the parameter works, for trust and for anyone extending the harness.

> Treat "How to use it" above as the contract, not this.

withFeatureFlagssetFeatureFlags (frontend/src/mocks/browser.tsx) writes the

flags (array or record) straight to window.POSTHOG_APP_CONTEXT.persisted_feature_flags.

getPersistedFeatureFlags (frontend/src/lib/logic/featureFlagLogic.ts) reads that as

featureFlagLogic's initial value and spyOnFeatureFlags always merges it as the

baseline — so both booleans and pinned variants survive the empty onFeatureFlags

callback. The only production-side support this needs is getPersistedFeatureFlags

accepting the record form (variant values) in addition to the server's array form.

You should not need to touch any of this. If you're extending the harness, that's the seam.

See also

The featureFlags parameter only controls the flag. If a component's render also depends

on other runtime state (localStorage, an APP_CONTEXT field, a kea logic that resolves an

entry), stage that state too — typically in a small wrapper the story renders that sets it

and mounts the logic before rendering the component. Keep that wrapper in the story file;

don't add test-only props to the production component to make it renderable.

Other skills for the same job

different authors, same section of the catalogue
Webapp Testing
by anthropics
vendor ×12

Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.

6k tokens scripts
Finishing A Development Branch
by ZhanlinCui
×7

Use when implementation is complete, all tests pass, and you need to decide how to integrate the work - guides completion of development work by presenting structured options for merge, PR, or cleanup

1k tokens
Test Driven Development
by w95
×7

Use when implementing any feature or bugfix, before writing implementation code

2k tokens
Systematic Debugging
by ratacat
×7

Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes

10k tokens scripts
Verification Before Completion
by ZhanlinCui
×6

Use when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions always

1k tokens
Backtest Expert
by BaggaT236
×3

Expert guidance for systematic backtesting of trading strategies. Use when developing, testing, stress-testing, or validating quantitative trading strategies. Covers "beating ideas to death" methodology, parameter robustness testing, slippage modeling, bias prevention, and interpreting backtest results. Applicable when user asks about backtesting, strategy validation, robustness testing, avoiding overfitting, or systematic trading development.

15k tokens scripts
Adaptyv
by christophacham
×3

Cloud laboratory platform for automated protein testing and validation. Use when designing proteins and needing experimental validation including binding assays, expression testing, thermostability measurements, enzyme activity assays, or protein sequence optimization. Also use for submitting experiments via API, tracking experiment status, downloading results, optimizing protein sequences for better expression using computational tools (NetSolP, SoluProt, SolubleMPNN, ESM), or managing protein design workflows with wet-lab validation.

16k tokens
Aeon
by christophacham
×3

This skill should be used for time series machine learning tasks including classification, regression, clustering, forecasting, anomaly detection, segmentation, and similarity search. Use when working with temporal data, sequential patterns, or time-indexed observations requiring specialized algorithms beyond standard ML approaches. Particularly suited for univariate and multivariate time series analysis with scikit-learn compatible APIs.

19k tokens

How to use it

Copy the folder

Take posthog/setting-feature-flags-in-storybook from the repository into ~/.claude/skills for personal use, or into .claude/skills inside a project.

Check the name does not clash

The agent identifies a skill by the name field in its header. Two skills with the same name cannot sit side by side — one of them will be ignored.