|
| 1 | +# AGENTS.md |
| 2 | +<!-- vale off --> |
| 3 | + |
| 4 | +## Scope |
| 5 | + |
| 6 | +This file applies to work under `frontend/`. |
| 7 | +Follow the root `AGENTS.md` first, then use this file for frontend-specific guidance. |
| 8 | + |
| 9 | +## What this package is |
| 10 | + |
| 11 | +- A Next.js App Router frontend workspace. |
| 12 | +- Uses `nhsuk-frontend` Sass/CSS alongside React components and Amplify auth UI. |
| 13 | +- Package-local scripts live in `frontend/package.json` and are the source of truth for package verification. |
| 14 | + |
| 15 | +## Change guidance |
| 16 | + |
| 17 | +- Keep changes small and focused. |
| 18 | +- Prefer existing package entrypoints over deep imports when bringing in framework assets or styles. |
| 19 | +- Treat `.next/` as generated output; do not edit generated files. |
| 20 | +- If you change routing, auth, styles, Next config, ESLint config, or dependencies, run the full verification flow below. |
| 21 | + |
| 22 | +## Known fragile areas |
| 23 | + |
| 24 | +### Sass imports |
| 25 | + |
| 26 | +- `frontend/src/styles/app.scss` must import NHS styles from the package entrypoint: |
| 27 | + |
| 28 | + ```scss |
| 29 | + @use "nhsuk-frontend"; |
| 30 | + ``` |
| 31 | + |
| 32 | +- Do not switch this back to a deep path such as `nhsuk-frontend/dist/nhsuk` unless you have verified that the installed package still resolves that path in this workspace. |
| 33 | +- After changing Sass imports or style tooling, run `npm run build --workspace frontend` from the repo root to catch stylesheet resolution problems. |
| 34 | + |
| 35 | +### App Router query params and auth pages |
| 36 | + |
| 37 | +- Build-time and prerender-sensitive routes should prefer resolving query params in the server `page.tsx` via `searchParams`, then passing plain props into client components. |
| 38 | +- Be careful when introducing `useSearchParams()` in client components used by prerendered routes such as `frontend/src/app/auth/page.tsx`; this can require a suspense boundary or cause build failures. |
| 39 | +- If you touch auth flow or redirect handling, test both the production build and a manual auth URL such as `/auth?redirect=%2F`. |
| 40 | + |
| 41 | +### ESLint and generated Next.js files |
| 42 | + |
| 43 | +- `frontend/.next/` must stay ignored by ESLint. |
| 44 | +- If you change `frontend/eslint.config.mjs`, verify that `.next/**` is still ignored and run lint after a build, not only before it. |
| 45 | +- A clean lint result before `next build` is not sufficient; generated `.next/types/**` files can reveal config regressions only after a build has run. |
| 46 | + |
| 47 | +## Required verification flow |
| 48 | + |
| 49 | +Run these commands from the repository root when making non-trivial changes in `frontend/`: |
| 50 | + |
| 51 | +```sh |
| 52 | +pre-commit run --config scripts/config/pre-commit.yaml |
| 53 | +rm -rf frontend/.next |
| 54 | +npm run build --workspace frontend |
| 55 | +npm run lint --workspace frontend |
| 56 | +npm run typecheck --workspace frontend |
| 57 | +npm run test:unit --workspace frontend |
| 58 | +``` |
| 59 | + |
| 60 | +## Verification notes |
| 61 | + |
| 62 | +- Use the clean build step to surface Sass resolution and App Router prerender issues. |
| 63 | +- Keep the post-build lint step to catch accidental linting of generated `.next` artifacts. |
| 64 | +- `typecheck` and `test:unit` both create mock Amplify outputs automatically via package scripts; prefer the existing scripts over ad hoc commands. |
| 65 | +- If you change auth, routing, middleware, or base-path handling, add a quick manual browser check in development as an extra validation step. |
| 66 | + |
| 67 | +## Minimum review summary for frontend changes |
| 68 | + |
| 69 | +Include in your handoff or PR summary: |
| 70 | + |
| 71 | +- what changed in `frontend/` |
| 72 | +- why the change was needed |
| 73 | +- that the root pre-commit checks were run |
| 74 | +- that `build`, `lint`, `typecheck`, and `test:unit` were run for the frontend workspace |
| 75 | +- any manual route or auth checks you performed |
0 commit comments