Communitygithub.com

Geruyang/agent-skills-library

Next.js App Router 专家指导。用于构建、调试或架构 Next.js 应用程序 — 路由、服务器组件、服务器操作、缓存组件、布局、中间件/代理、数据获取、渲染策略以及 Vercel 部署。

agent-skills-library 是什么?

该技能旨在为使用 Next.js App Router 的开发者提供全面的专家级指导。它覆盖了从项目结构、文件约定到高级渲染策略(如 RSC 边界、异步模式)的方方面面,并详细解释了运行时选择、指令和关键函数的使用方法。技能文档将 Next.js 开发中常见的复杂概念,如并行与拦截路由、缓存、错误处理和数据模式,分解为易于理解和参考的模块。它特别强调了 Next.js 15+ 中的异步 API 变更,并提供了针对路由处理器、元数据、图片和字体优化的具体实践指南。此技能适用于 Claude Code 等 AI 编码代理环境,通过提供结构化的参考文件链,帮助开发者避免常见陷阱,并在构建复杂应用时做出正确的架构决策。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/Geruyang/agent-skills-library/tree/HEAD/original-skills/x-openai-nextjs-0babc94

在你喜欢的 AI 中提问

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

文档

Next.js 最佳实践

在编写或审查 Next.js 代码时应用这些规则。

文件约定

参见 file-conventions.md 以了解:

  • 项目结构和特殊文件
  • 路由段(动态、捕获所有、分组)
  • 并行与拦截路由
  • v16 中的中间件重命名(middleware → proxy)

RSC 边界

检测无效的 React 服务器组件模式。

参见 rsc-boundaries.md 以了解:

  • 异步客户端组件检测(无效)
  • 不可序列化 props 检测
  • 服务器操作异常

异步模式

Next.js 15+ 异步 API 变更。

参见 async-patterns.md 以了解:

  • 异步 params 和 searchParams
  • 异步 cookies() 和 headers()
  • 迁移 codemod

运行时选择

参见 runtime-selection.md 以了解:

  • 默认使用 Node.js 运行时
  • 何时适合使用 Edge 运行时

指令

参见 directives.md 以了解:

  • 'use client'、'use server'(React)
  • 'use cache'(Next.js)

函数

参见 functions.md 以了解:

  • 导航钩子:useRouter、usePathname、useSearchParams、useParams
  • 服务器函数:cookies、headers、draftMode、after
  • 生成函数:generateStaticParams、generateMetadata

错误处理

参见 error-handling.md 以了解:

  • error.tsx、global-error.tsx、not-found.tsx
  • redirect、permanentRedirect、notFound
  • forbidden、unauthorized(认证错误)
  • 用于 catch 块的 unstable_rethrow

数据模式

参见 data-patterns.md 以了解:

  • 服务器组件 vs 服务器操作 vs 路由处理器
  • 避免数据瀑布(Promise.all、Suspense、预加载)
  • 客户端组件数据获取

路由处理器

参见 route-handlers.md 以了解:

  • route.ts 基础
  • GET 处理器与 page.tsx 的冲突
  • 环境行为(无 React DOM)
  • 何时使用 vs 服务器操作

元数据与 OG 图片

参见 metadata.md 以了解:

  • 静态和动态元数据
  • generateMetadata 函数
  • 使用 next/og 生成 OG 图片
  • 基于文件的元数据约定

图片优化

参见 image.md 以了解:

  • 始终使用 next/image 而非 <img>
  • 远程图片配置
  • 响应式 sizes 属性
  • 模糊占位符
  • LCP 优先级加载

字体优化

参见 font.md 以了解:

  • next/font 设置
  • Google 字体、本地字体
  • Tailwind CSS 集成
  • 预加载子集

打包

参见 bundling.md 以了解:

  • 服务器不兼容的包
  • CSS 导入(非 link 标签)
  • Polyfills(已包含)
  • ESM/CommonJS 问题
  • 包分析

脚本

参见 scripts.md 以了解:

  • next/script 与原生 script 标签
  • 内联脚本需要 id
  • 加载策略
  • 使用 @next/third-parties 的 Google Analytics

水合错误

参见 hydration-error.md 以了解:

  • 常见原因(浏览器 API、日期、无效 HTML)
  • 使用错误覆盖层调试
  • 针对每种原因的修复方法

Suspense 边界

参见 suspense-boundaries.md 以了解:

  • 使用 useSearchParams 和 usePathname 时的 CSR 回退
  • 哪些钩子需要 Suspense 边界

并行与拦截路由

参见 parallel-routes.md 以了解:

  • 使用 @slot 和 (.) 拦截器的模态框模式
  • 用于回退的 default.tsx
  • 使用 router.back() 正确关闭模态框

自托管

参见 self-hosting.md 以了解:

  • Docker 的 output: 'standalone'
  • 多实例 ISR 的缓存处理器
  • 哪些功能开箱即用,哪些需要额外配置

调试技巧

参见 debug-tricks.md 以了解:

  • 用于 AI 辅助调试的 MCP 端点
  • 使用 --debug-build-paths 重建特定路由

Individual skills in this repo

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

Geruyang/agent-skills-library

Guidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults.

Geruyang/agent-skills-library

Set up Tailwind CSS v4 in Expo with react-native-css and NativeWind v5 for universal styling

Geruyang/agent-skills-library

Use for new frontend applications, dashboards, games, creative websites, hero sections, and visually driven UI from scratch, or when the user explicitly asks for a redesign/restyle/modernization. Builds from clean, airy, high-taste, readable image-generated concept design with section-specific references, faithful implementation, and browser testing.

Geruyang/agent-skills-library

Use when testing, debugging, or making targeted improvements to rendered frontend apps through the Build Web Apps or web dev plugin: local dev servers, UI regressions, interaction bugs, console errors, responsive layout, and visual QA. Check whether the Browser plugin is available and use it first when it is; otherwise use regular Playwright with the recorded reason.

Geruyang/agent-skills-library

Design UI surfaces for browser games. Use when the user asks for HUDs, menus, overlays, responsive layouts, or visual direction that must protect the playfield.

Geruyang/agent-skills-library

GSAP animation reference for HyperFrames. Covers gsap.to(), from(), fromTo(), easing, stagger, defaults, timelines (gsap.timeline(), position parameter, labels, nesting, playback), and performance (transforms, will-change, quickTo). Use when writing GSAP animations in HyperFrames compositions.

Geruyang/agent-skills-library

Guide for building, configuring, and deploying microfrontends on Vercel. Use this skill when the user mentions microfrontends, multi-zones, splitting an app across teams, independent deployments, cross-app routing, incremental migration, composing multiple frontends under one domain, microfrontends.json, @vercel/microfrontends, the microfrontends local proxy, or path-based routing between Vercel projects. Also use when the user asks about shared layouts across projects, navigation between microfrontends, fallback environments, asset prefixes, or feature flag controlled routing.

Geruyang/agent-skills-library

Use when sizing Public Equity Investing positions, finding equity hedges, or building an integrated position-and-hedge risk plan from a listed-equity thesis. Do not use for thesis construction, standalone event underwriting, trade execution, personal investment advice, or credit-instrument risk.

Geruyang/agent-skills-library

Integrate data visualizations into React and Next.js applications. Use when the user needs chart components, UML-like or architecture diagram components, React integration patterns, Next.js client or server boundaries, hydration-safe rendering, lazy loading, framework-aware performance, scroll-driven visual stories, or export guidance.

Geruyang/agent-skills-library

shadcn/ui expert guidance — CLI, component installation, composition patterns, custom registries, theming, Tailwind CSS integration, and high-quality interface design. Use when initializing shadcn, adding components, composing product UI, building custom registries, configuring themes, or troubleshooting component issues.

Geruyang/agent-skills-library

v0 by Vercel expert guidance. Use when discussing AI code generation, generating UI components from prompts, v0 CLI usage, v0 SDK/API integration, or integrating v0 into development workflows with GitHub and Vercel deployment.

Geruyang/agent-skills-library

Manages shadcn components and projects — adding, searching, fixing, debugging, styling, and composing UI. Provides project context, component docs, and usage examples. Applies when working with shadcn/ui, component registries, presets, --preset codes, or any project with a components.json file. Also triggers for "shadcn init", "create an app with --preset", or "switch to --preset".

相关技能