feat(storybook): per-component context.md + View as Markdown button (MVP)#6218
feat(storybook): per-component context.md + View as Markdown button (MVP)#6218blunteshwar wants to merge 2 commits into
Conversation
|
📚 Branch Preview Links🔍 First Generation Visual Regression Test ResultsWhen a visual regression test fails (or has previously failed while working on this branch), its results can be found in the following URLs:
Deployed to Azure Blob Storage: If the changes are expected, update the |
Ships LLM-consumable `context.md` files for the 8 currently migrated
2nd-gen components (badge, divider, progress-circle, status-light, icon,
asset, avatar, color-loupe) and a Storybook button that opens the file
in a new tab from each component's docs page.
These files are the prose grounding layer for AI-assisted SWC
development — separate from the human-facing README.md and from the
machine-only Custom Elements Manifest. Each file covers when-to-use,
when-NOT-to-use, accessibility contract, composition rules, runtime
invariants, common LLM mistakes, and gen-1 → gen-2 differences.
Distribution:
- Source-of-truth: 2nd-gen/packages/swc/components/{slug}/context.md
- Build step (.storybook/scripts/copy-context-md.mjs) copies them into
public/components/{slug}/context.md (gitignored) so Storybook serves
them without exposing the component source directory to the static-
asset layer (avoiding the video/mp2t MIME error from .ts files).
- ContextMarkdownButton block reads meta.component, strips the
swc-/sp- prefix, HEAD-fetches the URL, and renders only when the
file exists. Components without context.md (e.g. typography) hide
the button automatically.
Typography is intentionally excluded — it's a CSS-class utility, not a
custom-element component, so the per-component file model does not fit.
See [RFC] context.md for 2nd-gen SWC components for the proposal:
https://wiki.corp.adobe.com/spaces/AdobeDesign/pages/3854270520
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
The View as Markdown button used an absolute path (`/components/...`) which resolves to the domain root. On the PR preview deploy under `/pr-NNNN/docs/second-gen-storybook/`, that sends the request to the wrong host root and returns 404, so the button hides itself (correct fallback behaviour, but invisible button). Resolve the URL via `document.baseURI` so it inherits the storybook deploy prefix automatically. Works in both local dev (root path) and CI preview deploys (sub-path). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
610083a to
9f83984
Compare
|
@blunteshwar Adding this content here risks drifting from our single source of truth. We should instead convert the Storybook docs page into Markdown so it can be reliably consumed by AI. This conversion should be part of an automated pipeline to keep everything in sync. |
| * git-ignored. | ||
| * | ||
| * `context.md` is the LLM-consumable component documentation proposed in | ||
| * https://wiki.corp.adobe.com/spaces/AdobeDesign/pages/3854270520. |
There was a problem hiding this comment.
We should not include internal links
| * - the meta has no `component` tag | ||
| * - the resolved `context.md` returns 404 (not yet authored for that component) | ||
| */ | ||
| export const ContextMarkdownButton = ({ of }: { of?: any }) => { |
There was a problem hiding this comment.
Recommending renaming this to ViewContextMaekdown as the original name sounds like it’s specific for the button component
|
I don’t think we should introduce another hand authored file as a source of truth. This will allow a lot of drift between the context and the storybook docs. Can you share more about the authoring experience change that would come with this new pattern? Does the replace another way of documenting? |
Description
Ships an MVP for the per-component
context.mdsystem proposed in [RFC] context.md for 2nd-gen SWC components.Two pieces:
context.mdfiles — one per migrated 2nd-gen component (badge,divider,progress-circle,status-light,icon,asset,avatar,color-loupe). Each file is the LLM-only prose grounding layer: when-to-use, when-NOT-to-use, accessibility contract, composition rules, runtime invariants, common LLM mistakes, and gen-1 → gen-2 differences.context.mdin a new tab — same pattern as React Spectrum's docs (https://react-spectrum.adobe.com/Tabs.md).typographyis intentionally excluded — it's a CSS-class utility, not a custom-element component, so the per-component file model does not fit.Motivation and context
When external developers ask LLMs (Claude, Cursor, Copilot, Gemini) to build with SWC, the model frequently hallucinates: wrong variant names, missing
aria-label, mixed gen-1/gen-2 imports,outlineon a non-semantic variant. Existing docs surfaces (README, CEM, Storybook stories) are not LLM-grounding-shaped.context.mdis purpose-built for LLM consumption — chrome-free, anti-pattern-rich, runtime-invariant-aware.This PR ships the smallest viable slice from RFC §7 so we can evaluate whether the format reduces hallucination before scaling to all future migrations.
Related issue(s)
Note on branch base
This branch was cut from
color-loupe-migration, not directly frommain. The PR diff againstmainwill therefore include color-loupe commits that haven't yet landed on main. The actual context.md / button work is in the single new commit41f88ca216— easiest to review by filtering the commits view to that commit.Screenshots
The button renders top-right above the subtitle on every component's docs page. Click → new tab opens the raw markdown.
(Reviewer: please add a screenshot after running locally — see manual test steps below.)
Implementation notes
context.mdfile in each component's directory (2nd-gen/packages/swc/components/{slug}/context.md). These ship with the package via npm..storybook/scripts/copy-context-md.mjs) copies the files intopublic/components/{slug}/context.md(gitignored) before Storybook starts. This is wired into bothyarn storybookandyarn storybook:build.staticDirsmapping of the components dir: mapping the entire components dir exposes.tssource files, which browsers receive with MIME typevideo/mp2tand refuse to execute as modules. Copying onlycontext.mdkeeps the public surface tight.fetch HEADreturns 404), so unmigrated and excluded components (e.g. typography) just don't show it.Author's checklist
Reviewer's checklist
patch,minor, ormajorfeaturesManual review test cases
Button renders on a migrated component's docs page
cd 2nd-gen/packages/swc && yarn storybookComponents → Badge → README/components/badge/context.mdshowing the raw markdown contentButton is hidden for components without a context.md
Typography → README(or any non-migrated component)Production build serves the same files
cd 2nd-gen/packages/swc && yarn storybook:buildstorybook-static/(e.g.npx http-server storybook-static)Device review
Accessibility testing checklist
Keyboard (required — document steps below)
Components → Badge → READMEcontext.mdrendered as raw markdownScreen reader (required — document steps below)
aria-labeltext "opens in new tab" if reviewers feel announcement is unclear)