nextjs

A set of coding rules for Next.js, a React framework for building web applications. It covers the App Router, server-rendered components, data loading, forms, and error handling.

In plain words
What is it for?
Use it when creating routes, pages, shared components, server-side data requests, server actions, loading states, and error pages.
Why use it?
It helps keep browser and server code separate, avoids unnecessary client-side work, and gives each page a consistent structure.

Cursor rule

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/nedcodes-ok/cursorrules-collection/nextjs
Clone the repo
git clone --depth 1 https://github.com/nedcodes-ok/cursorrules-collection
Per session 842 This file is loaded in full into every session.
When invoked 842 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00842 $0.00842
Opus 5 $0.00421 $0.00421
Sonnet 5 $0.00168 $0.00168
Haiku 4.5 $0.00084 $0.00084

Measured yesterday against content hash 4f3cdbb53d04, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

nextjs scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

Origin

Copies of this mod

1 near-identical copy found in the catalogue:

  • nextjs — 100% identical, 0 lines differ
rules-mdc/frameworks/nextjs.mdc · 54 lines

How it starts

The opening of the file, as written. The whole thing — 54 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Next.js Cursor Rules

You are an expert Next.js developer using App Router (v14+). Follow these rules:

Architecture

  • Use App Router (app/ directory) for all new code
  • Default to Server Components. "use client" only for interactivity/hooks/browser APIs
  • "use client" marks the boundary — everything imported into a client component becomes client too, even if not marked. Keep client boundaries as low in the tree as possible
  • Use route groups (parentheses folders) for organization without URL impact
  • Keep page.tsx thin — compose from smaller components, page only wires them together
  • Colocate components with their route: app/dashboard/_components/ not a global components/ folder

Data Fetching

  • Fetch in Server Components with async/await — no useEffect for server data
  • fetch() requests with the same URL and options are automatically deduped within a render pass — don't cache manually
  • Use next: { revalidate: seconds } for time-based ISR, next: { tags: [...] } for on-demand with revalidateTag()
  • Server Actions for mutations — they run server-side even when called from client components
  • loading.tsx for Suspense boundaries per route segment, error.tsx for error boundaries
  • Do not fetch in layouts if child routes need different data — layouts don't re-render on navigation

Rendering Gotchas

  • Static rendering is default. Using cookies(), headers(), or searchParams opts the entire route into dynamic rendering — isolate dynamic parts with Suspense
  • generateStaticParams for dynamic route pre-rendering at build time — without it, dynamic segments are rendered on-demand
  • for all images (handles lazy loading, srcset, WebP). Set explicit width/height or use fill with a sized parent — unsized images cause layout shift
  • Do not import server-only code in client components — use the server-only package to get a build-time error instead of a runtime leak

Read the full file on GitHub · 54 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 54 lines · 842 tokens per session scan A 4f3cdbb53d04

Subscribe to this mod's changes

nextjs is a cursor rule published in the GitHub repository nedcodes-ok/cursorrules-collection (37 stars, last pushed 6mo ago), licensed MIT. It adds 842 tokens to every session, about $0.0042 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.