Instructions for AI coding agents (and a quick-start for humans) working in this repo. For conventions and rationale, read docs/codebase-overview.md — start at Creating a New Component before writing component code. Human contributor setup is in CONTRIBUTING.md.
Setup: Node >= 24 (.nvmrc), npm install, then npx playwright install chromium for the browser test project.
Never run bare npm test — it starts Vitest in watch mode and will not exit.
| Command | Purpose |
|---|---|
npm run typecheck |
tsc --noEmit |
npm run lint |
ESLint; 0 errors and no more warnings than --max-warnings in package.json |
npm test -- --run |
All tests: jsdom unit project, real-browser browser project, and snapshots |
npm test -- --run -u |
Same, and regenerate story HTML snapshots |
npm run build |
Type-check, library build, .d.ts, entry shims |
npm run test:snapshots |
Story HTML snapshot suite only (~3s) |
npm run test:ci |
Everything CI runs: typecheck, test, build, lint |
Run npm run test:ci before requesting review. A husky pre-push hook runs test:snapshots and blocks the push if snapshots are stale.
- Stories are test fixtures, not just demos. Every story in
components/**/__docs__/*.stories.{jsx,tsx}(except portal-rendered ones, which need component tests instead) is rendered intocomponents/__tests__/__snapshots__/story-snapshots.test.jsx.snap. If you add, remove, or change a story, or change a component's rendered markup, runnpm test -- --run -u, review the snapshot diff, and commit it in the same PR. - A filtered test run does not run the snapshot suite.
npm test -- --run components/comboboxskipscomponents/__tests__/story-snapshots.test.jsx. Always finish with an unfiltered run. - Local runs write new snapshots silently. Outside CI, a plain
npm test -- --runpasses and writes snapshots for new stories without failing; CI then fails if they aren't committed.test:ciandtest:snapshotspass--update=noneto behave like CI. Checkgit statusfor.snapchanges before pushing. - Stories must use the component's real prop API. Cross-check against
components/<name>/__examples__andtypes.ts; stories written against an assumed API are a common source of "component looks broken" reports. - Unexpected console output has a budget of 0. Any test that writes
console.error/console.warnis listed after the run (and, on a PR, annotated on the test file and in the job summary); the run fails pastmaxWarningsinscripts/vitest-console-reporter.ts. Fix the cause, or assert an expected warning withvi.spyOn(console, '<method>'). Lint warnings are annotated on the PR the same way. Build warnings are printed and never fail. - jsdom vs. browser tests. Tests that need a real browser (focus traversal, layout/measurement) go in
*.browser.test.jsx; everything else is jsdom. - New scripts in
scripts/are TypeScript. Write.tsand run it withtsx(asrelease.tsis);npm run typecheckcovers them viatsconfig.scripts.json. The remaining.mjs/.jsscripts predate this rule; convert one when you substantially change it. Tests inscripts/__tests__/stay*.test.mjs, the pattern thescriptsVitest project picks up. - Types are the contract. Runtime PropTypes were removed in the TypeScript migration; the generated
.d.tsfiles are what consumers get. - Restoring or mirroring existing behavior (stories lost in a rewrite, parity with another implementation): build the inventory from git (
git show <old-ref>:<path>,git log --follow), not from memory, and list the before/after set in the PR description.
- Maintainers: push branches to
salesforce/design-system-react, not a personal fork. Chromatic runs on push, so fork PRs get no visual review. External contributors fork as described in CONTRIBUTING.md. - Conventional commits are enforced by commitlint (
fix:,feat:,docs:,chore:,test:,style:, …). Public API removals or renames are breaking: use!and aBREAKING CHANGE:footer. - Keep lint/format-only changes in their own commit (
style:), separate from thefix:/feat:commit, so the functional diff is reviewable. - Rebase on
masterand resolve conflicts before requesting review. - Fill in docs/PULL_REQUEST_TEMPLATE.md. For bug fixes, state the root cause, not just the symptom, and add a regression test.
Maintainers: npm run release-pr -- next (or an explicit version such as 11.0.0-alpha.4) bumps package.json on chore/release-<version> cut from origin/master, commits, pushes, and opens the PR (add --dry-run to preview). Once it merges, create the GitHub Release with gh release create v<version> --target master --generate-notes (add --prerelease for alpha/beta/rc), which triggers .github/workflows/npm-publish.yml to publish to npm. See scripts/release.ts for details.
For a maintenance line, add --base <branch>: npm run release-pr -- next --base 0.10.x cuts chore/release-0.10.66 from origin/0.10.x (next patch-bumps a stable version there) and opens the PR against that branch. After it merges, gh release create v<version> --target 0.10.x --generate-notes runs that branch's own publish workflow. A stable maintenance release publishes under npm's latest dist-tag, which is right while the current major is in prerelease.
Agent-generated notes, plans, and analyses go in .planning/ (gitignored). Don't commit them.
Sections of docs/codebase-overview.md to check when a decision is ambiguous:
- Props Conventions — naming, callbacks,
labels/assistiveText, boolean defaults - TypeScript Patterns
- SLDS Alignment — only SLDS-approved components and markup
- Accessibility — focus management, keyboard navigation, ARIA
- Testing
- Breaking-Change Taxonomy