agentleFS
amirrezaalastiamirrezaalasti/codescribe/skills/coding/nextjs-data-fetching/SKILL.md

nextjs-data-fetching

Skill2 starsChanged 4 months agoMITView on GitHub

Fetch and mutate data in Next.js App Router with correct caching, Server Actions boundaries, and loading/error UX. Use when implementing Next.js data fetching, caching, revalidation, Server Actions, route handlers, or fixing stale/over-fetched data in Next apps.

The file

We split this skill into the rules it gives an agent

6 rules. About 0 are common, 4 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use Server Actions for mutations from the client when the project uses them

    line 20
  2. Distinctive:

    Prefer explicit cache/revalidate choices over accidental defaults

    line 21
  3. Very specific:

    Loading and errors: Use loading.tsx, route-level error.tsx, or Suspense boundaries so users see progress and recoverable failures.

    line 30
  4. Distinctive:

    Client fetching only when needed: Use client SWR/React Query (if present) for highly interactive, frequently updating client state — not as …

    line 31
  5. Distinctive:

    Match auth boundaries: Check session/permissions before returning sensitive data or performing mutations.

    line 32
  6. Very specific:

    Tag unfinished or risky work: Use the global tagged-code-comments convention (🔴 FIXME(P0):, 🟠 TODO(P1):, 🔴 SECURITY(P0):).

    line 33

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Next.js Data Fetching

Defaults

  • Fetch in Server Components when data is needed for render
  • Use Server Actions for mutations from the client when the project uses them
  • Prefer explicit cache/revalidate choices over accidental defaults
  • Pair slow fetches with loading.tsx / Suspense

Instructions

  1. Read on the server. In Server Components, fetch (or the project's data client) during render. Avoid waterfalls: fetch in parallel when requests are independent.
  2. Be explicit about caching. Know whether a fetch is cached or dynamic for the Next version in use. Set cache: 'no-store' or next: { revalidate: N } intentionally — do not guess.
  3. Mutations via Server Actions or route handlers. Validate input on the server. Revalidate tags/paths after successful writes (revalidatePath / revalidateTag as appropriate).
  4. Do not leak secrets. Server-only env vars and privileged clients stay on the server. Never expose service keys to client bundles.
  5. Loading and errors. Use loading.tsx, route-level error.tsx, or Suspense boundaries so users see progress and recoverable failures.
  6. Client fetching only when needed. Use client SWR/React Query (if present) for highly interactive, frequently updating client state — not as the default for initial page data.
  7. Match auth boundaries. Check session/permissions before returning sensitive data or performing mutations.
  8. Tag unfinished or risky work. Use the global tagged-code-comments convention (🔴 FIXME(P0):, 🟠 TODO(P1):, 🔴 SECURITY(P0):). Never leave silent stubs or insecure shortcuts. End with an Open follow-ups table so the developer must check P0/P1 before ship.

Patterns

// Server Component — intentional revalidation
async function Products() {
  const res = await fetch("https://api.example.com/products", {
    next: { revalidate: 60 },
  });
  if (!res.ok) throw new Error("Failed to load products");
  const products = await res.json();
  return <ProductList products={products} />;
}
"use server";

import { revalidatePath } from "next/cache";

export async function createItem(formData: FormData) {
  const title = String(formData.get("title") ?? "").trim();
  if (!title) throw new Error("Title required");
  // await db.insert...
  revalidatePath("/items");
}

Anti-patterns

  • Fetching the same data in many nested clients instead of once on the server
  • Ignoring auth on Server Actions
  • Returning large unneeded payloads to the client
  • Mixing Pages Router data APIs into App Router

Additional resources

  • references/checklist.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.