ams-nextjs-pro
暂无简介
- License 许可
- MIT
- 最近更新
- 2026-11-07
- Stars
- ★ 0
- Forks
- 1
03 SKILL.md 正文
Next.js Pro
Overview
Next.js App Router's model — React Server Components by default, client components as opt-in, and granular caching — rewards thinking carefully about where code runs. Professional Next.js means mastering the server/client boundary, using the caching model deliberately (not accidentally), colocating data fetching with the components that need it, and treating Server Actions as the mutation story.
The through-line: server by default, client by necessity, cached by design.
When to use
- Writing or reviewing Next.js App Router code.
- Designing server/client component boundaries.
- Debugging caching issues (stale data, over-fetching) or hydration errors.
- Structuring routes, layouts, data fetching, and mutations.
- Optimizing Next.js performance and deployment.
Core concepts
- Server Components by default. Async components fetching data directly (
await db.query()in the component) — no useEffect waterfalls, no API round-trip for your own database. Client components ('use client') only for interactivity, browser APIs, and hooks — pushed to the leaves, not the root. - The caching model, deliberate.
fetchcaching, route segment config (revalidate,dynamic), andunstable_cache— understand what caches what, or you'll debug stale data forever. Default to static where possible; opt into dynamic explicitly; revalidate withrevalidatePath/revalidateTagon mutation. - Colocated data fetching. Fetch next to the component that renders the data; parallelize independent fetches (same-tick promises); Suspense boundaries for streaming independent sections. Request waterfalls are a design smell — hoist and parallelize.
- Server Actions for mutations.
'use server'functions called directly from client components — form submissions, updates — withrevalidatePathafter mutation anduseFormStatus/useActionStatefor pending/error UI. Validate inputs server-side (zod); never trust the client. - Route groups and layouts.
(group)for organization without URL impact; layouts for persistent UI;loading.tsx/error.tsxper segment for granular states;not-found.tsxfor 404s. Parallel/intercepting routes for advanced patterns (modals over pages) — powerful but only when the UX demands it. - Middleware sparingly. Auth checks, redirects, A/B headers — middleware runs on every matched request (edge runtime limits apply). Don't put business logic there; it's a gate, not a service layer.
Practical workflow
- Scaffold:
create-next-appwith TypeScript, App Router, and your styling choice; strict TS; ESLint with Next.js rules in CI. - Draw the server/client boundary. Page shells and data components → server; interactive widgets → client leaves. Props cross the boundary (serializable only — no functions, no class instances).
- Fetch deliberately. Server components fetch directly; parallelize with
Promise.allor same-tick awaits; wrap independent sections in<Suspense>for streaming; set revalidation per data freshness needs. - Mutate with Server Actions. Validate → mutate → revalidate → redirect/return state;
optimistic updates via
useOptimisticwhere rollback is well-defined. - Handle all states per segment.
loading.tsxskeletons,error.tsxwith reset, andnot-found.tsx— users should never see a blank segment or raw error. - Deploy and observe. Vercel or self-hosted (standalone output); monitor Core Web Vitals, server action errors, and cache hit rates; set up ISR/revalidation monitoring for stale-data detection.
Server/client sketch:
// app/orders/page.tsx — Server Component: fetches directly
export default async function OrdersPage({ searchParams }) {
const orders = await getOrders(searchParams.status); // runs on server
return (
<>
<FilterBar /> {/* 'use client' leaf: interactive */}
<Suspense fallback={<OrdersSkeleton />}>
<OrderTable orders={orders} />
</Suspense>
</>
);
}
Common pitfalls
'use client'at the root. Making the whole page client-rendered "to use hooks" — forfeits SSR, streaming, and direct data access. Push the boundary to the leaves.- Waterfall fetching. Sequential awaits for independent data, or client components fetching in effects what the server component could fetch directly. Parallelize; colocate.
- Cache confusion. Stale data blamed on "Next.js bugs" that's actually default static caching;
or
revalidate = 0everywhere "to be safe," forfeiting the performance story. Learn the model; set it per route deliberately. - Non-serializable props across the boundary. Passing functions, Dates-as-class-instances, or complex objects from server to client components — serialization errors or subtle bugs. Plain data only.
- Hydration mismatches.
new Date(),Math.random(), ortypeof windowchecks rendering different HTML on server vs client. Render deterministically; defer client-only bits. - Server Actions without validation. Trusting client-submitted data in actions. Validate every input server-side; authorize every mutation (the action runs with server privileges).
- Middleware bloat. Business logic, DB queries, and heavy computation in middleware — it runs on every request at the edge. Keep it to routing/auth decisions.
04 同仓库更多 Skills
web-scrape
Turn web pages into LLM-ready markdown via the Firecrawl API (renders JS, anti-bot handling). Use when browser_open/fetch fails on JS-heavy pages, or when you need clean markdown/structured extraction from a site. Requires FIRECRAWL_API_KEY.
design-taste-frontend
tasteskill v2, the anti-slop frontend skill. Art direction for websites, distilled from a study of 247 curated gallery sites (One Page Love, Awwwards Sites of the Day). Deals researched directions (idea, composition, type, palette, photographs, section blueprints) from a library, enforces a strict no-slop house style with a real-browser inspector, and runs a look-and-fix loop on screenshots. Use this whenever you build, design, redesign, restyle, polish or review a landing page, marketing site, portfolio, product page, one-pager, hero or any public-facing web page, in any stack (HTML/CSS, React, Next.js, Vue, Svelte, Astro, Tailwind) — also when the user says a page looks generic, templated, "AI-made", sloppy, or asks to make it look designed, premium, award-level or less like every other site. Not for dashboards or app screens.
test-driven-development
Use when implementing any feature or bugfix, before writing implementation code
systematic-debugging
Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes
requesting-code-review
Use when completing tasks, implementing major features, or before merging to verify work meets requirements
brainstorming
You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).