Communitygithub.com

Anhvu1107/all-agent-skill

当用户提及 Next.js 最佳实践、要求构建、调试、审查、文档化、自动化、测试、配置、迁移或在相关领域做出决策,或任务明确依赖 Next.js 最佳实践时,始终使用此技能;适用范围:Next.js App Router 原则。在最终输出之前,应用捆绑的工作流程、参考资料、脚本、高级大师标准和 Codex 严格审查门禁。

all-agent-skill 是什么?

此技能为 AI 代理(如 Claude Code、Cursor、Codex)提供了一套全面的 Next.js 最佳实践指南,专注于 App Router 架构。它涵盖了从服务器端与客户端组件的选择决策树、数据获取模式(包括静态、ISR 和动态获取)、文件约定(如 page.tsx、layout.tsx)到路由组织、API 路由处理、性能优化(图像和包优化)、元数据管理、缓存策略以及服务器操作等核心主题。该技能通过清晰的表格、决策树和反模式列表,帮助开发者遵循“服务器组件优先”的原则,并避免常见陷阱。它适用于多种 AI 代理平台,作为构建、审查、调试和优化 Next.js 应用时的权威参考。

兼容平台~Claude Code✓Codex CLI~Cursor
npx skills add https://github.com/Anhvu1107/all-agent-skill/tree/HEAD/.agent/skills/nextjs-best-practices

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

Next.js 最佳实践

选择性阅读规则

从以下文件开始:

  • references/senior-master-standard.md
  • references/usage-routing.md
  • references/quality-checklist.md

然后仅加载与用户实际任务匹配的继承文档、脚本、资产或示例。

Next.js App Router 开发的原则。


1. 服务器端与客户端组件

决策树

是否需要...?
│
├── useState、useEffect、事件处理程序
│   └── 客户端组件('use client')
│
├── 直接数据获取,无需交互性
│   └── 服务器端组件(默认)
│
└── 两者都需要?
    └── 拆分:服务器端父组件 + 客户端子组件

默认用法

类型用途
服务器端数据获取、布局、静态内容
客户端表单、按钮、交互式 UI

2. 数据获取模式

获取策略

模式用途
默认静态(构建时缓存)
重新验证ISR(基于时间的刷新)
不存储动态(每次请求)

数据流

来源模式
数据库服务器端组件获取
API带缓存的 fetch
用户输入客户端状态 + 服务器操作

3. 路由原则

文件约定

文件用途
page.tsx路由 UI
layout.tsx共享布局
loading.tsx加载状态
error.tsx错误边界
not-found.tsx404 页面

路由组织

模式用途
路由组 (name)组织而不影响 URL
并行路由 @slot多个同级页面
拦截路由 (.)模态覆盖层

4. API 路由

路由处理器

方法用途
GET读取数据
POST创建数据
PUT/PATCH更新数据
DELETE删除数据

最佳实践

  • 使用 Zod 验证输入
  • 返回正确的状态码
  • 优雅地处理错误
  • 尽可能使用 Edge 运行时

5. 性能原则

图片优化

  • 使用 next/image 组件
  • 为首屏图片设置 priority
  • 提供模糊占位符
  • 使用响应式尺寸

包优化

  • 对大型组件使用动态导入
  • 基于路由的代码分割(自动)
  • 使用包分析器进行分析

6. 元数据

静态与动态

类型用途
静态导出固定元数据
generateMetadata按路由动态生成

必要标签

  • title(50-60 字符)
  • description(150-160 字符)
  • Open Graph 图片
  • 规范 URL

7. 缓存策略

缓存层

层控制方式
请求fetch 选项
数据revalidate/tags
完整路由路由配置

重新验证

方法用途
基于时间revalidate: 60
按需revalidatePath/Tag
无缓存no-store

8. 服务器操作

使用场景

  • 表单提交
  • 数据变更
  • 触发重新验证

最佳实践

  • 使用 'use server' 标记
  • 验证所有输入
  • 返回类型化响应
  • 处理错误

9. 反模式

❌ 不要做✅ 推荐做法
到处使用 'use client'默认使用服务器端组件
在客户端组件中获取数据在服务器端获取数据
跳过加载状态使用 loading.tsx
忽略错误边界使用 error.tsx
大型客户端包使用动态导入

10. 项目结构

app/
├── (marketing)/     # 路由组
│   └── page.tsx
├── (dashboard)/
│   ├── layout.tsx   # 仪表板布局
│   └── page.tsx
├── api/
│   └── [resource]/
│       └── route.ts
└── components/
    └── ui/

请记住: 服务器端组件是默认选择,这是有原因的。从这个开始,仅在需要时添加客户端组件。

何时使用

当任务与概述中描述的工作流程或操作明确匹配时,可以应用此技能。

局限性

  • 仅当任务与上述范围明确匹配时才使用此技能。
  • 不要将输出视为针对特定环境的验证、测试或专家审查的替代方案。
  • 如果缺少所需的输入、权限、安全边界或成功标准,请停下来并要求澄清。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches 007: Security audit, hardening, threat modeling (STRIDE/PASTA), Red/Blue Team, OWASP checks, code review, incident response, and infrastructure security for any project.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Agentfolio: Skill for discovering and researching autonomous AI agents, tools, and ecosystems using the AgentFolio directory.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Animejs Animation: Advanced JavaScript animation library skill for creating complex, high-performance web animations.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Astropy: Astropy is the core Python package for astronomy, providing essential functionality for astronomical research and data analysis.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Astro: Build content-focused websites with Astro — zero JS by default, islands architecture, multi-framework components, and Markdown/MDX support.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Emotional ARC Designer: One sentence - what this skill does and when to invoke it

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Fixing Motion Performance: Audit and fix animation performance issues including layout thrashing, compositor properties, scroll-linked motion, and blur effects.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches I18n Localization: Internationalization and localization patterns.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Interactive Portfolio: Expert in building portfolios that actually land jobs and clients - not just showing work, but creating memorable experiences.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches JQ: Expert jq usage for JSON querying, filtering, transformation, and pipeline integration.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Landing Page Generator: Generates high-converting Next.js/React landing pages with Tailwind CSS.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches LEX: Centralized ''Truth Engine'' for cross-jurisdictional legal context (US, EU, CA) and contract scaffolding.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Magic Animator: AI-powered animation tool for creating motion in logos, UI, icons, and social media assets.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Makepad Animation: CRITICAL: Use for Makepad animation system.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Nextjs APP Router Patterns: Comprehensive patterns for Next.js 14+ App Router architecture, Server Components, and modern full-stack React development.

Anhvu1107/all-agent-skill

description: ALWAYS use this when the work is specifically about modern Next.js or React architecture, data flow, rendering strategy, routing, or performance-sensitive frontend behavior.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Nextjs Supabase Auth: Expert integration of Supabase Auth with Next.js App Router

Anhvu1107/all-agent-skill

ALWAYS use this when the task involves reading, extracting, splitting, merging, rotating, creating, validating, OCR-ing, form-filling, or otherwise producing or modifying PDF files.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches React Nextjs Development: React and Next.js 14+ application development with App Router, Server Components, TypeScript, Tailwind CSS, and modern frontend patterns.

Anhvu1107/all-agent-skill

ALWAYS use this when working with Remotion code, video compositions, rendering logic, timing, media assets, or React-based motion workflows.

相关技能