Storybook stories in PostHog

SkillMedia

storybook-stories is a skill that guides an AI agent through writing Storybook stories for PostHog UI components. It covers the provider stack that stories run inside, the fact that tRPC and useHostTRPC queries never resolve in Storybook, and the pure-presentational split that makes a component storyable. Use it when adding or fixing a *.stories.tsx file under packages/ui.

Use Storybook stories in PostHog in Claude, ChatGPT or Ahel Desktop

Free. Sign in, add Storybook stories in PostHog and connect your AI. About a minute.

Also: Claude Code · Cursor · Codex

Then ask your AI: use the Storybook stories in PostHog skill

Details

Instructions available. Your AI can read the instructions. Execution depends on the setup they require.

Have a component under packages/ui that needs a story, or an existing *.stories.tsx file to fix.

Storybook stories in PostHogStart free

What your AI can do with it

  • Write *.stories.tsx files for components under packages/ui
  • Explain that stories are already wrapped by global decorators
  • Warn that useHostTRPC queries stay pending forever in Storybook
  • Split a component into a pure presentational part and a container
  • Add per-story decorators only to constrain layout

Getting started

  1. Have a component under packages/ui that needs a story, or an existing *.stories.tsx file to fix.
  2. Confirm the story file sits next to the component and matches the *.stories.tsx glob.
  3. Do not add providers or a Theme in the story, since global decorators already supply them.
  4. If the component fetches data, split out a pure presentational component that takes data and handlers as props.
  5. Write stories against the pure component, one per visual state, and run the storybook dev server or static build to check.

What this skill tells your AI

The instructions your AI receives, as published by posthog/posthog in products/desktop/.claude/skills/storybook-stories/SKILL.md and read by ahel’s review.

Stories live next to components as *.stories.tsx and are collected by apps/code/.storybook/main.ts (its glob includes packages/ui/src/**/*.stories.tsx). Run/build:

pnpm --filter code storybook        # dev server on :6006
pnpm --filter code build-storybook  # static build (also a good CI/typecheck gate)

Every story is already wrapped (don't re-wrap)

apps/code/.storybook/preview.tsx applies two global decorators, so a story should not add its own providers or <Theme>:

  • withAppProviders — a QueryClient, the host tRPC context, a DI ServiceProvider, and a minimal TanStack Router. So useHostTRPC(), useService(), useRouterState(), etc. render instead of throwing "must be used within a Provider".
  • A <Theme> (Radix) bound to the dark/light toolbar global. This root provider is the one sanctioned Radix usage — it supplies the CSS tokens. Radix components are banned: build stories and components from @posthog/quill plus div + Tailwind (see UI Components).

Add a per-story decorator only to constrain layout (e.g. wrap in a maxWidth div so a full-width component sizes realistically).

The gotcha: data never arrives in Storybook

This is the thing that wastes time. In withAppProviders the tRPC ipcLink is a no-op (apps/code/.storybook/mocks/electron-trpc.ts), so:

  • Any query issued through useHostTRPC() (and hooks built on it, like useClaudeCliSessions) stays pending forever — query.data is undefined, permanently.
  • useService(TOKEN) returns an inert proxy stub for anything not explicitly bound (service.foo().bar never throws, but calls are no-ops). Only a few tokens resolve for real: HOST_TRPC_CLIENT (a no-op client with a handful of stubbed methods), IMPERATIVE_QUERY_CLIENT, DIFF_WORKER_FACTORY.

So a component that fetches its own data renders its empty/loading branch in Storybook — frequently null. Storying it directly shows nothing.

The fix: split a pure presentational component

Separate the data/wiring from the rendering, and story the pure part — which also satisfies the repo rule "components render; hooks wrap exactly one query" (AGENTS.md). Keep both in the same file:

// Pure — takes data + handlers as props. This is what the story targets.
export function WidgetList({ items, onPick }: WidgetListProps) { … }

// Container — does the tRPC/useService wiring, renders <WidgetList/>.
export function Widget({ repoPath }: WidgetProps) {
  const { data } = useSomeQuery(repoPath);
  return <WidgetList items={data?.items ?? []} onPick={…} />;
}

Then each story is just args for WidgetList — one per visual state (empty, single, over-limit, in-flight/disabled, fallback text, …). Real example: packages/ui/src/features/task-detail/components/ContinueCliSessions.tsx + .stories.tsx.

Filtering/branching that lives in the container (not the pure view) isn't exercised by these visual stories — cover it with a small unit test if it's worth pinning.

Conventions

  • title groups in the sidebar, e.g. "Task Detail/ContinueCliSessions".
  • Build fixtures with a small factory (session(overrides)) rather than repeating object literals across stories.
  • Date.now()/new Date() are fine in stories, but fixed ISO strings keep relative-time output stable enough for visual review.
  • Typecheck covers stories (they're .tsx under the package); a build-storybook additionally catches Storybook-specific breakage.

Signals

GitHub stars
40k
Forks
3k
Last commit
Sep 2026

Others that do the same job

Questions

Why does a data-fetching component render empty in Storybook?
The tRPC ipcLink in withAppProviders is a no-op, so any query through useHostTRPC stays pending forever and query.data is undefined. The component shows its empty or loading branch, often null.
Should a story add its own providers or Theme?
No. preview.tsx applies withAppProviders and a Theme globally, so a story should not re-wrap them. Add a per-story decorator only to constrain layout, such as a maxWidth div.
Advanced
Item type
skill
Key
storybook-stories-posthog
Source
github.com/posthog/posthog