react-nextjs-conventions
Step 6 of the pipeline (WORKFLOW.md). Frames the writing of code on the React 18/19 + Next.js stack. Every
rule below holds in a repo with nothing installed (CONVENTIONS.md, rule A). Complementary to legolas
(the diff review agent): here we write the code, legolas re-reads it afterwards.
Relation to an org skill catalogue. Where a company ships its own versioned catalogue for this stack, it
is the authority on its house style and overrides this block wherever the two differ. This block is the
generic default. Two house conventions in particular genuinely split across real codebases — type vs
interface for object shapes, and where tests live — and this block says "pick one and apply it uniformly"
rather than pretending there's a universal answer.
An applied override is recorded, not hidden. Write the code the governing rule actually requires, and
leave one short neutral trace addressed to whoever can decide (a line in the PR description, the task summary
or an ADR): which rule was overridden, by what, and that it is a resolved case. Never phrase it as "a conflict
between mentis and the house rules" to a non-technical stakeholder — that framing reads as broken even when
the case is a normal, resolved one, and has already caused a real project to get abandoned and restarted over
nothing. Raise one specific, named question to the decider only when no rule anywhere actually resolves the
case.
On a Laravel + Inertia.js app with React pages, there is no Next.js runtime (no App Router, no
Next data fetching) — a page there is a plain component wired by Inertia. This block's Next-specific
sections don't have an equivalent in that architecture; see skills/inertia-conventions §4 before
flagging an Inertia repo against them.
When
As soon as a .tsx component, a Next.js route, a hook, a store slice or a query hook is written or modified,
during code (6) or tdd (5).
Steps
Read only the sections the task actually touches. The rules live one file per section under
references/; loading all of them for a change that only renames a variable is waste, and a section
read is a section that has to be applied. If you are reviewing a whole diff, pick the rows whose
trigger the diff meets, not the whole table.
| § |
Covers |
Read it when |
File |
| 1 |
Components and files |
a component is created or split |
01-components-files.md |
| 2 |
Naming |
a symbol or a file has to be named |
02-naming.md |
| 3 |
Typing |
props, state or a generic is typed |
03-typing.md |
| 4 |
Control flow |
conditional rendering, lists, early returns |
04-control-flow.md |
| 5 |
State, effects, hooks |
a hook is written, or an effect added |
05-state-effects-hooks.md |
| 6 |
Server state and stores |
TanStack Query, Zustand or RTK |
06-server-state-stores.md |
| 7 |
Next.js |
the App Router, a server component, a route handler |
07-next-js.md |
| 8 |
The component library |
a UI element is built, or custom CSS is about to be written |
08-component-library.md |
| 9 |
Security, never negotiable |
always, on any diff |
09-security-never-negotiable.md |
| 10 |
Accessibility and bundle weight |
a control is rendered, or a dependency added |
10-accessibility-bundle-weight.md |
| 11 |
Testing components and hooks |
a component, a hook, a form or a data-fetching screen gets a test |
11-testing.md |
| 12 |
Boundaries, composition, context, forms, refs |
a failure or loading state is contained, a context or compound component is introduced, a form, portal or ref is built, an external store is subscribed to |
12-boundaries-composition-forms.md |
| 13 |
Further security surface |
a link opens a new window, inline data is shipped to the browser, an outside object is merged, a third-party script or widget is added, or the production build is configured |
13-security-surface-extra.md |
| 14 |
Next.js 16 Cache Components |
cacheComponents is on, a route sets dynamic/revalidate/fetchCache, "use cache" appears, or a 15 app moves to 16 |
14-cache-components.md |
| 15 |
The Server Action result contract and idempotency |
a Server Action is written or reviewed: its return type, how it reports failure, what a second run does, what a deployment does to an open form |
15-server-action-contract.md |
| 16 |
Rendering and runtime performance |
a list grows, an interaction lags, a scroll or input handler is added, or something re-renders too often |
16-rendering-runtime-performance.md |
§16 overlaps §5 (when to memoise), §10 (what a dependency adds to the bundle) and §12 (lazy-loading a heavy component): the rule stays in the section that owns it, and §16 keeps only the runtime cost of rendering. Measure first with skills/webperf.
Output / checkpoint
Code compliant with the sections above. No dedicated checkpoint: compliance is checked by gate (7) and by
legolas at review time in the review step (8).
Guardrails
No comments in the code produced. Never modify a generated component file in place: always go through a
wrapper. Don't duplicate an existing hook or selector before checking that no nearby one covers the need.
This block writes code, it doesn't review diffs; for the review, that's legolas. Where an org catalogue is
installed and disagrees with a rule here, it wins — apply it and leave the short neutral trace described at the top, never a silent override. When in doubt about a rule covered by neither, escalate rather than guess.
Origin
Rules mined from market catalogues, linters and internal review feedback, rewritten in the house
voice; the full provenance, the source stamps and the refresh log are in
references/origin.md. Read it when checking whether a rule is still
current, not when applying one.
1---2name: react-nextjs-conventions3description: "Use when writing or reviewing React/Next.js: structure and naming, typing, hooks discipline, immutability, memo, server-state libraries, validation at boundaries, App Router, effects and security correctness, tests, boundaries and composition, further security surface, the Server Action result contract and idempotency."4metadata:5 source: https://skillmd.com/skills/techmefr/react-nextjs-conventions6---78# react-nextjs-conventions910Step 6 of the pipeline (`WORKFLOW.md`). Frames the writing of code on the React 18/19 + Next.js stack. Every11rule below holds in a repo with **nothing installed** (`CONVENTIONS.md`, rule A). Complementary to `legolas`12(the diff review agent): here we write the code, legolas re-reads it afterwards.1314**Relation to an org skill catalogue.** Where a company ships its own versioned catalogue for this stack, it15is the authority on **its** house style and overrides this block wherever the two differ. This block is the16generic default. Two house conventions in particular genuinely split across real codebases — `type` vs17`interface` for object shapes, and where tests live — and this block says "pick one and apply it uniformly"18rather than pretending there's a universal answer.1920**An applied override is recorded, not hidden.** Write the code the governing rule actually requires, and21leave one short neutral trace addressed to whoever can decide (a line in the PR description, the task summary22or an ADR): which rule was overridden, by what, and that it is a resolved case. Never phrase it as "a conflict23between mentis and the house rules" to a non-technical stakeholder — that framing reads as broken even when24the case is a normal, resolved one, and has already caused a real project to get abandoned and restarted over25nothing. Raise one specific, named question to the decider only when no rule anywhere actually resolves the26case.2728**On a Laravel + Inertia.js app with React pages, there is no Next.js runtime** (no App Router, no29Next data fetching) — a page there is a plain component wired by Inertia. This block's Next-specific30sections don't have an equivalent in that architecture; see `skills/inertia-conventions` §4 before31flagging an Inertia repo against them.3233## When34As soon as a `.tsx` component, a Next.js route, a hook, a store slice or a query hook is written or modified,35during `code` (6) or `tdd` (5).3637## Steps3839**Read only the sections the task actually touches.** The rules live one file per section under40`references/`; loading all of them for a change that only renames a variable is waste, and a section41read is a section that has to be applied. If you are reviewing a whole diff, pick the rows whose42trigger the diff meets, not the whole table.4344| § | Covers | Read it when | File |45|---|---|---|---|46| 1 | Components and files | a component is created or split | [`01-components-files.md`](./references/01-components-files.md) |47| 2 | Naming | a symbol or a file has to be named | [`02-naming.md`](./references/02-naming.md) |48| 3 | Typing | props, state or a generic is typed | [`03-typing.md`](./references/03-typing.md) |49| 4 | Control flow | conditional rendering, lists, early returns | [`04-control-flow.md`](./references/04-control-flow.md) |50| 5 | State, effects, hooks | a hook is written, or an effect added | [`05-state-effects-hooks.md`](./references/05-state-effects-hooks.md) |51| 6 | Server state and stores | TanStack Query, Zustand or RTK | [`06-server-state-stores.md`](./references/06-server-state-stores.md) |52| 7 | Next.js | the App Router, a server component, a route handler | [`07-next-js.md`](./references/07-next-js.md) |53| 8 | The component library | a UI element is built, or custom CSS is about to be written | [`08-component-library.md`](./references/08-component-library.md) |54| 9 | Security, never negotiable | always, on any diff | [`09-security-never-negotiable.md`](./references/09-security-never-negotiable.md) |55| 10 | Accessibility and bundle weight | a control is rendered, or a dependency added | [`10-accessibility-bundle-weight.md`](./references/10-accessibility-bundle-weight.md) |56| 11 | Testing components and hooks | a component, a hook, a form or a data-fetching screen gets a test | [`11-testing.md`](./references/11-testing.md) |57| 12 | Boundaries, composition, context, forms, refs | a failure or loading state is contained, a context or compound component is introduced, a form, portal or ref is built, an external store is subscribed to | [`12-boundaries-composition-forms.md`](./references/12-boundaries-composition-forms.md) |58| 13 | Further security surface | a link opens a new window, inline data is shipped to the browser, an outside object is merged, a third-party script or widget is added, or the production build is configured | [`13-security-surface-extra.md`](./references/13-security-surface-extra.md) |59| 14 | Next.js 16 Cache Components | `cacheComponents` is on, a route sets `dynamic`/`revalidate`/`fetchCache`, `"use cache"` appears, or a 15 app moves to 16 | [`14-cache-components.md`](./references/14-cache-components.md) |60| 15 | The Server Action result contract and idempotency | a Server Action is written or reviewed: its return type, how it reports failure, what a second run does, what a deployment does to an open form | [`15-server-action-contract.md`](./references/15-server-action-contract.md) |61| 16 | Rendering and runtime performance | a list grows, an interaction lags, a scroll or input handler is added, or something re-renders too often | [`16-rendering-runtime-performance.md`](./references/16-rendering-runtime-performance.md) |6263§16 overlaps §5 (when to memoise), §10 (what a dependency adds to the bundle) and §12 (lazy-loading a heavy component): the rule stays in the section that owns it, and §16 keeps only the runtime cost of rendering. Measure first with `skills/webperf`.6465## Output / checkpoint66Code compliant with the sections above. No dedicated checkpoint: compliance is checked by `gate` (7) and by67`legolas` at review time in the `review` step (8).6869## Guardrails70No comments in the code produced. Never modify a generated component file in place: always go through a71wrapper. Don't duplicate an existing hook or selector before checking that no nearby one covers the need.72This block writes code, it doesn't review diffs; for the review, that's `legolas`. Where an org catalogue is73installed and disagrees with a rule here, **it wins** — apply it and leave the short neutral trace described at the top, never a silent override. When in doubt about a rule covered by neither, escalate rather than guess.7475## Origin76Rules mined from market catalogues, linters and internal review feedback, rewritten in the house77voice; the full provenance, the source stamps and the refresh log are in78[`references/origin.md`](./references/origin.md). Read it when checking whether a rule is still79current, not when applying one.