agentleFS
isabelle-barpisabelle-barp/agent-brain/skills/stack-nextjs-react/SKILL.md

stack-nextjs-react

Skill0 starsChanged 5 months agoApache-2.0View on GitHub

Next.js/React implementation patterns for agents working in projects whose docs/TECH_STACK.md lists nextjs-react. Load when implementing, testing, or reviewing code on this stack.

The file

Files
SKILL.md

Stack: Next.js / React

When this applies

Detection markers (any of):

  • docs/TECH_STACK.md ## Detected stacks lists nextjs-react
  • Dependencies: next, react, react-dom; optionally @playwright/test in the e2e project
  • Files: next.config.{js,mjs,ts}, an app/ directory with page.tsx/layout.tsx (App Router), or a Vite + React SPA (vite.config.ts + react plugin)

Which surface (Next.js SSR/SSG vs SPA) and which router are in use is declared in docs/ARCHITECTURE.md and the spec — never invent a target app.

Implementation patterns

App Router & server/client boundaries

  • Pages live under app/<route>/page.tsx; server components by default. Mark 'use client' ONLY when the component needs interactivity, state, or effects — and push the client boundary as low in the tree as possible.
  • Server components fetch data on the server (direct calls or the typed server-side client); client components use the generated typed hooks. Confirm App vs Pages Router before writing — do not mix conventions.
  • For SPA surfaces, follow the routing library already configured in the app. Use existing primitives and styling conventions; do not introduce a new component library.

Data fetching & forms

  • No manual fetch wrappers. Consume the typed client/hooks generated from the project's contract layer (docs/ARCHITECTURE.md declares it: GraphQL codegen hooks, ts-rest client, etc.). If a needed operation is missing from the contract, signal it — do not work around it; the contract is backend-owned.
  • Handle EVERY documented response shape explicitly (success, domain errors, network errors) — map each to the UI state declared in SPEC_<FEATURE>.md §7.
  • Forms validate against the shared schema (Zod or project equivalent) before submit; submit controls are disabled/pending while a mutation is in flight.

data-testid registry discipline (the FE↔E2E contract)

  • Every interactive element MUST carry the data-testid declared in SPEC_<FEATURE>.md §7.3. Add no data-testids not in the registry; omit none from it. The registry is the ONLY contract between the component and the E2E tester.
  • Format: <domain>-<element>-<qualifier> (e.g. bookings-submit-button).
  • data-testid is for tests, NOT a substitute for accessibility: every interactive element also needs an accessible name (label, aria-label, or visible text).
<button
  data-testid="bookings-submit-button"   // exact ID from SPEC_<FEATURE>.md §7.3
  aria-label="Confirm booking"
  onClick={handleSubmit}
  disabled={isPending}
>
  {label}
</button>

State coverage

Wire every state declared in SPEC_<FEATURE>.md §7: default, empty, loading, error, conflict (for write actions), permission-denied. A state in the spec without a wired UI path is an incomplete implementation, not polish.

Testing on this stack

Playwright E2E — the thin tip of the pyramid. Deep Playwright craft (fixtures, anti-flakiness discipline, network policy, compose-profile runs) lives in .claude/skills/stack-playwright/SKILL.md — this section carries only the FE↔E2E contract; avoid duplicating the craft here.

  • Query ONLY by data-testid from SPEC_<FEATURE>.md §7.3 (page.getByTestId(...)). Never by visible text, label, role, or tag — visible text changes with i18n; data-testid is the stable contract. A getByTestId value not in §7.3 is an invented ID — a violation.
  • One UI AC = one test, named test('AC-<FEATURE>-NN: <behavior>', ...), with GIVEN/WHEN/THEN comments aligned to the spec wording.
  • Thin layer: happy paths + critical flows only. Permission denial / empty / loading: one E2E each maximum. Boundary and edge cases belong to unit/integration tests.
  • Fresh E2E tests MUST fail (RED) before the UI exists — red is the correct state for a new test commit.
  • The E2E tester never reads frontend source — SPEC_<FEATURE>.md §7 is its only UI source; an insufficient §7 is a spec defect to flag, not a license to inspect components.
  • Pre-seeded backend state goes through the project's test-fixture mechanism — never a hand-rolled DB connection from the E2E suite; a missing fixture mechanism is a flagged gap, not something to improvise.
  • Reuse the existing Playwright config in the -e2e project; do not introduce a parallel runner.

Spec validation checks

Stack-specific checks the spec validators (spec-validate-ui, on SPEC_<FEATURE>.md §7 UI Behavior) delegate here:

CheckSeverity
data-testid values follow <domain>-<element>-<qualifier> formatBLOCKER
No data-testid collisions within the spec or with other specs on the same surfaceBLOCKER
Required states covered: default, empty, loading, errorBLOCKER
Conflict state covered for write actionsWARNING
Permission-denied state covered when auth-gatedWARNING
Every interaction row maps to a §4 API operationWARNING
Every UI-surfaced user story in §2 has at least one component in §7WARNING
Confirmation dialogs specified for destructive actionsWARNING

Validation IS execution: ls the mock asset, grep the spec set for duplicate data-testid values — a duplicate data-testid in production is a Playwright nightmare; catching it here is the validator's job.

Live validation commands

R-VAL-03 matrix (frontend/UI changes) — exact invocations live in docs/DEV_SETUP.md; obligations:

CheckTypical shape
Type-check + lint affected projectstypecheck/lint targets per DEV_SETUP
Build the production bundlebuild target per DEV_SETUP
Start the dev server and use the feature in a browserdev target per DEV_SETUP
Verify the golden path AND at least one edge state (empty/error/loading)manual interaction in the running app
Spot-check unrelated pages for regressionquick pass

Type checking and test suites verify code correctness, not feature correctness — if the UI cannot be exercised, say so explicitly rather than claiming success. Test-only changes follow R-VAL-04: run Playwright and observe RED-or-GREEN per the task's BDD intent. All rows must pass before commit per .claude/rules/LIVE_VALIDATION.md.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.