State Machine

作者 jakubkreheld574cc8a576d無授權條款7.5K 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫2 天前更新

Renders every state of a component you choose on a throwaway page, with mock data and a switcher, so you can work on each state.

AI 產生的概覽

在一個臨時頁面上以模擬資料和狀態切換器渲染所選元件的每一種狀態。

功能
此技能會在現有應用程式內建立一個臨時草稿路由,原樣匯入真實元件,並渲染程式碼原本就能到達的每一種狀態,例如載入、空、錯誤、長列表、方案層級和功能旗標。它會在元件的資料邊界注入貼近產品的模擬資料,加入固定切換器來翻轉 __state 查詢參數,讓每種狀態都是一個連結,並在交付前確認每種狀態都能渲染。頁面、fixture 和切換器放在同一個資料夾中,因此只需一次刪除即可移除,且僅在使用者確認後執行。
適用情境
當你需要針對單一元件的所有狀態打磨視覺效果,並希望在一個頁面上存取每種狀態時使用。它是用來迭代狀態視覺的工作台,而不是對已完成工作的審查,也不是探索替代設計方案的方式。
執行需求
需要一個包含目標元件及其資料鉤子的現有應用程式專案,以及用來載入並切換各狀態的瀏覽器。它不附帶指令碼;引用了 switcher.md 規格和 agents/openai.yaml 檔案。未說明需要憑證或網路存取。

State machine

This skill takes one component and renders it on a throwaway page in every state it can be in. Mock data feeds each state, a switcher flips between them and the page is deleted in one step when you are done.

It is a workbench, not a review. The page stays up while the user works on the visuals, one state on screen and every other a keypress away. Stacking hostile scenarios on one page for a single look is break, exploring alternative designs is variant and reviewing finished work is interface-review.

1. Scope one component

One component per run: the audit log table, the network panel, the billing card. "The settings page" spans several, so list them and ask which one.

Restate it in one sentence: what the component shows, where it renders in production and where its data comes from.

2. Find the states in the code

The states are the branches the component already has. Read it and its data hooks for every one:

KindStates
DataLoading, empty, error, one item, a typical set, a set long enough to scroll or paginate, some requests resolved and others pending, stale data refetching
AccountPlan tier, role and permission checks, an owner versus a member
FeatureFlags, trials, limits reached, a disabled or locked feature

A state the code cannot reach is not a state. Do not add a branch to render one. Where the design shows a state the code lacks, list it as missing and leave it out.

Write the set down before building, one line each, named the way the product talks about it: empty, enterprise, member-no-access. Say which kinds you dropped and why in one line. Combine kinds only where the code branches on the combination, such as member-empty, never as a cross product.

3. Build the throwaway page

A scratch route inside the app holds the real component, imported from the project and untouched. The route inherits the app's layout, fonts, global styles and providers for free.

Where the framework splits server from client components, the page is client code, "use client" in Next. Otherwise fixture data can silently vanish crossing that boundary, and the page renders empty.

Render one instance in a container as wide as the component is in production. The container, the fixtures and the switcher are everything the page adds, with no fonts, styles or themes of its own. Keep the page, its fixtures and its switcher in one folder, such as /states/audit-log, so removal is one delete.

4. Feed each state at the data boundary

Supply the data where the component receives it, from the page, without editing the component. In order of preference:

  1. Props, where the component takes its data as props.
  2. The app's own data seam: a seeded query cache, a mock provider or the project's request mocks.

A fixture threaded through props five levels down tests a path production never takes. Where the only way in is editing the component, say so and ask before adding a seam.

Make the data look like the product. Real-shaped names, timestamps, amounts and the item counts users actually have. Three rows of "Test item" make every state look fine.

Loading and pending states hold still. Keep them pending until the switcher moves, rather than resolving after a timeout.

5. Add the switcher

A fixed control flips the __state search param, so every state is a link. The double underscore keeps it clear of any param the app's layout reads. switcher.md [blocked] holds the spec.

6. Confirm every state renders, then hand over

Load the page once in a browser already at hand and flip through every state. The component shows the mock data, not the real data and not a blank region. Mock data that never appears is the common failure here. Live sync, a cache that refetches over the seed or a server boundary dropping the fixture all cause it. Fix the plumbing before handing over.

With no browser at hand, say so and hand the URL over for the user to check.

Then hand over the URL, the state list and the switcher keys. Stop there. Changing how a state looks is the user's next request, not part of this one.

Re-check every state after each change

After a visual change, flip through every state again, since a fix for one state often breaks another.

Remove it in one step, on the user's word

Delete the page folder and any seam the user approved. Then search the codebase for the route and fixture names, and check that the diff touches nothing else of the setup. Commit only when asked.

Before you finish

MistakeFix
The component edited to accept fixturesFeed data from the page through props or the app's data seam; ask before adding a seam
A rebuilt lookalike component on the pageImport the real component from the project
The page restyles or re-themes the componentThe app's layout, fonts and tokens as they are
Fixtures passed as props deep in the treeSupply the data where the component receives it
A branch added to the component to show a stateLeave out states the code cannot reach, and list missing ones
"Item 1", "Test user", three rowsProduct-shaped data in real quantities
Loading resolves after a timeoutHold it until the switcher moves
Handed over without loading each stateLoad every state; a blank or real-data state means broken plumbing
Switcher styled with the project's tokensKeep it visibly outside the design system
Visuals changed unaskedHand over and wait
Page deleted in the same turn it was builtRemove it only on the user's word
Route or fixture names left behindSearch for both after removal

來源與署名

來源:jakubkrehel/skills位於skills/state-machine提交d574cc8

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架