AgentLint 实测验证 100/100基于 439 个 Next.js(App Router) 开源仓库统计
Next.js(App Router) CLAUDE.md & AGENTS.md 模板
Server/Client 组件边界、Server Action 鉴权校验与 next build 验证,提炼自 439 个 Next.js 仓库。
# Next.js App Router Project — Next.js Harness Next.js 15 App Router web application using React Server Components, TypeScript strict mode, Tailwind CSS, and Vitest. ## Commands - Install: `pnpm install --frozen-lockfile` - Fast single test: `npx vitest run src/lib/pricing.test.ts` - Typecheck & lint: `npx tsc --noEmit && pnpm lint` - Production build check: `pnpm next build` ## Rules - Don't add `'use client'` to top-level pages or layouts. Instead push interactivity into small leaf client components. Because unnecessary client boundaries bloat JS bundles and break server data fetching. - Don't read `process.env` secrets inside client components or expose unvalidated Server Actions. Instead validate every action payload with Zod and verify the user session on the server. Because Server Actions are public HTTP endpoints. - Don't edit generated `.next/` files or rely on `dev` mode alone to prove type safety. Instead run `npx tsc --noEmit && pnpm next build` before opening a PR. - When changing auth middleware or caching tags, read `docs/caching-and-auth.md` first. ## Continuity & Safety - Keep `.env.local` and `CLAUDE.local.md` in `.gitignore` — never commit secrets or personal paths. - Record verified build/test outputs and route diffs in `HANDOFF.md` before ending a session.
Next.js(App Router) 开源生态中最常采用的工程规则
基于 4,533 仓库研究中 439 个公开 Next.js(App Router) 仓库的实测统计:
nextjs框架
Next.js App Router & server rendering conventions (measured in 1,533 TS repos)
28.6%439 个仓库
react框架
React Server & Client component boundaries
61.3%940 个仓库
tailwindcss工具链
Tailwind CSS utility tokens
38.8%595 个仓库
eslint工具链
ESLint + next/core-web-vitals checks
36.9%565 个仓库
vitest测试
Vitest for fast unit & route handler tests
32.6%499 个仓库
必写验证命令(对应规则 W1 与 W7)
- 安装依赖
- pnpm install --frozen-lockfile
- 快速单测(秒级迭代)
- npx vitest run src/app/billing/page.test.tsx
- 全量测试
- pnpm test && pnpm exec playwright test
- Lint 与静态检查
- pnpm lint && npx tsc --noEmit
- 生产构建
- pnpm next build
Next.js(App Router) 项目中 AI 代理常见踩坑
- 01AI 动辄在页面或 layout 顶部加
'use client',把服务端数据逻辑拖进客户端大包。 - 02只靠
next dev不跑next build会掩盖 Server Component 序列化与类型错误直到部署失败。 - 03未用 Zod 校验与服务端鉴权保护 Server Action,等于暴露公开 HTTP 接口。