agentleFS
SkillMedevSkillMedev/vercel-platform/skills/nextjs-app-router/SKILL.md

nextjs-app-router

Skill1 starsChanged 38 days agoMITView on GitHub

Builds and reviews Next.js App Router code - server/client component boundaries, data fetching, caching and revalidation choices, streaming with Suspense, and Server Action mutations - and delivers routes where every dynamic-vs-cached decision is explicit. Use when someone asks "should this be a client component", "why is my data stale", "where do I put use client", "how do I stream this page", or "how do server actions work". Do NOT use for Vercel-specific runtime and cost tuning of an already-built app - use next-on-vercel-perf instead; for edge middleware and ISR deployment topology - use vercel-edge-and-isr instead; for framework-agnostic Core Web Vitals work - use web-performance instead; for designing an application-wide cache layer beyond the framework - use caching-strategy instead.

13 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use skill-creator.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • SentrySkill

    skill-creator

    Create new agent skills following the Agent Skills specification. Use when asked to "create a skill", "add a new skill", "write a skill", "make a skill", "build a skill", or scaffold a new skill with SKILL.md. Guides through requirements, writing, registration, and verification.

    Also in 3 projects that use this

The file

Show its rules and text

We split this skill into the rules it gives an agent

15 rules. 0 are common, 6 are distinctive, and 9 are very specific to this project.

  • 0

    Common

    Most of the 10 edited versions we read keep these.

  • 6

    Distinctive

    This author's own choices. Worth a look.

  • 9

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    If a client component needs server-rendered content inside it, pass it as children - composition keeps the inner tree on the server.

    line 26
  2. Very specific:

    Must be fresh or per-user: { cache: 'no-store' }, or export const dynamic = 'force-dynamic' when the whole route is per-request.

    line 55
  3. Very specific:

    Add loading.tsx for every route with async work - the shell should render immediately while data streams in.

    line 62
  4. Distinctive:

    Use Server Actions for mutations.

    line 68
  5. Distinctive:

    Check authorization inside the action, not only in the page that renders the form.

    line 69
  6. Very specific:

    After a successful mutation, call revalidatePath or revalidateTag for exactly the data that changed - tags from Step 3 make this precise …

    line 70
  7. Very specific:

    Do not put 'use client' on a page or layout to fix one interactive widget - extract the widget instead.

    line 79
  8. Very specific:

    Do not fetch in useEffect what a server component could fetch - it adds a client-server waterfall and a loading spinner where streamed HTML …

    line 80
  9. Very specific:

    Do not "fix" stale data with force-dynamic route-wide when one fetch needed no-store - you lose caching for everything else on the page.

    line 81
  10. Distinctive:

    Do not skip validation or auth checks in Server Actions because "only my form calls it" - actions are callable endpoints.

    line 82
  11. Distinctive:

    Do not store server data in client state and manually sync it.

    line 83
  12. Very specific:

    Every 'use client' directive is at a leaf and justified by interactivity, state, or a browser API.

    line 87
  13. Very specific:

    Every fetch has an explicit caching decision.

    line 88
  14. Distinctive:

    Every async boundary has a loading state.

    line 89
  15. Distinctive:

    Every mutation revalidates the specific paths/tags it affects, and validates + authorizes on the server.

    line 90

“Common” is measured: kept by at least 6 in 10 of the 10 edited versions of this file we could read. “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 App Router

Default to Server Components; reach for Client Components only for interactivity, state, or browser APIs. The two costly mistakes this skill prevents are the accidental client tree - one 'use client' placed high that drags the whole page into the browser bundle - and accidental caching, where fetch's default caching silently serves stale data and the team "fixes" it by sprinkling force-dynamic everywhere, losing all caching.

Operating procedure

Step 1: gather inputs

Collect before writing a route (label guesses as guesses):

  1. Per piece of data on the page: is it per-request/per-user, or shared and cacheable? If cacheable, what staleness is acceptable (seconds, minutes, hours)?
  2. Which UI elements genuinely need interactivity, state, effects, or browser APIs.
  3. Mutations on the page and what data they invalidate.
  4. Auth model: does rendering depend on cookies/headers (forces dynamic rendering)?

Step 2: draw the client boundary at the leaves

  • Mark 'use client' only at the smallest component that needs it. Everything imported by a client component becomes client code, so a high boundary silently ships the subtree to the browser.
  • If a client component needs server-rendered content inside it, pass it as children - composition keeps the inner tree on the server.
  • Pass data down as props; do not lift server data into client state just to share it.

Bad:

'use client'                    // whole page is now client code
export default function Page() {
  const [open, setOpen] = useState(false)
  // 40 KB of product listing logic dragged into the bundle for one toggle
}

Good:

// page.tsx - server component, fetches and renders
export default async function Page() {
  const products = await getProducts()
  return <ProductList products={products} action={<FilterToggle />} />
}
// FilterToggle.tsx - 'use client', only the toggle ships to the browser

Step 3: fetch on the server, choose caching explicitly

  • Fetch in server components with async/await. No useEffect data fetching unless the data is genuinely client-driven (e.g. depends on live client state).
  • fetch is cached by default - every fetch call must make a deliberate choice:
    • Shared, tolerates staleness: { next: { revalidate: N } }. Pick N from acceptable staleness in Step 1 - 60 s for dashboards-ish freshness, 3600 s for marketing/content.
    • Must be fresh or per-user: { cache: 'no-store' }, or export const dynamic = 'force-dynamic' when the whole route is per-request.
    • Tag cacheable data (next: { tags: ['products'] }) when a mutation will need to invalidate it precisely.
  • Reading cookies() or headers() makes the route dynamic - expect it, don't fight it.
  • Deduplicate: a fetch with identical args is memoized per request, so fetch where the data is used rather than prop-drilling from the top.

Step 4: stream instead of blocking

  • Add loading.tsx for every route with async work - the shell should render immediately while data streams in.
  • Wrap independently-slow sections in <Suspense> with their own fallbacks so one slow query does not hold the whole page. If any single data dependency takes over ~300 ms, it is a streaming candidate; never let one slow fetch block first paint past 1 s when the rest of the page is ready.
  • error.tsx for route-level error boundaries; not-found.tsx plus notFound() for 404s.

Step 5: mutate with Server Actions and revalidate

  • Use Server Actions for mutations. Validate input on the server with a schema - never trust the client; the action is a public endpoint regardless of which form calls it.
  • Check authorization inside the action, not only in the page that renders the form.
  • After a successful mutation, call revalidatePath or revalidateTag for exactly the data that changed - tags from Step 3 make this precise instead of nuking whole routes.
  • Return typed error state from actions for the form to render; do not throw for expected validation failures.

Deliverable

Produce the route implementation plus a one-table caching manifest: for each data source on the page - cached or dynamic, revalidate interval or no-store, tags, and which mutation invalidates it. Every choice explicit, none accidental.

Do NOT

  • Do not put 'use client' on a page or layout to fix one interactive widget - extract the widget instead; the directive is transitive to every import.
  • Do not fetch in useEffect what a server component could fetch - it adds a client-server waterfall and a loading spinner where streamed HTML would do.
  • Do not "fix" stale data with force-dynamic route-wide when one fetch needed no-store - you lose caching for everything else on the page.
  • Do not skip validation or auth checks in Server Actions because "only my form calls it" - actions are callable endpoints.
  • Do not store server data in client state and manually sync it; revalidation after mutation is the sync mechanism.

Quality bar

  • Every 'use client' directive is at a leaf and justified by interactivity, state, or a browser API.
  • Every fetch has an explicit caching decision; grep for bare fetches with none.
  • Every async boundary has a loading state; no route blanks while awaiting data.
  • Every mutation revalidates the specific paths/tags it affects, and validates + authorizes on the server.
  • The caching manifest exists and matches the code.

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.