Communitygithub.com

Geruyang/agent-skills-library

Next.js App Router 專家指引。在建立、除錯或架構 Next.js 應用程式時使用——包括路由、伺服器元件、伺服器動作、快取元件、版面配置、中介層/代理、資料擷取、渲染策略及在 Vercel 上的部署。

agent-skills-library 是什麼?

此技能提供全面的 Next.js App Router 開發與除錯最佳實踐指南。它涵蓋從檔案結構慣例、React Server Component (RSC) 邊界檢查、非同步模式(params、searchParams、cookies、headers)、執行階段選擇、指令('use client'、'use server'、'use cache'),到導航鉤子、錯誤處理、資料模式、路由處理器、元資料與 OG 圖片、圖片與字型最佳化、打包、指令碼、水合錯誤偵錯、Suspense 邊界、平行與攔截路由、自架設以及偵錯技巧等所有面向。此技能特別適合 Claude Code、Cursor 或 Codex 等 AI Agent,可作為開發 Next.js 應用程式時的權威參考,幫助確保程式碼符合框架最佳實踐,並有效解決常見問題。它透過參考文件組織成多個主題章節,讓開發者能快速查找特定領域的詳細指引。

相容平台~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 Server Component 模式。

參閱 rsc-boundaries.md 了解:

  • 非同步用戶端元件偵測(無效)
  • 不可序列化 props 偵測
  • Server Action 例外

非同步模式

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(驗證錯誤)
  • unstable_rethrow 用於 catch 區塊

資料模式

參閱 data-patterns.md 了解:

  • Server Component vs Server Action vs Route Handler
  • 避免資料瀑布(Promise.all、Suspense、preload)
  • 用戶端元件資料擷取

路由處理器

參閱 route-handlers.md 了解:

  • route.ts 基礎
  • GET 處理器與 page.tsx 的衝突
  • 環境行為(無 React DOM)
  • 何時使用 vs Server Actions

元資料與 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 vs 原生 script 標籤
  • 內聯指令碼需要 id
  • 載入策略
  • 搭配 @next/third-parties 使用 Google Analytics

水合錯誤

參閱 hydration-error.md 了解:

  • 常見原因(瀏覽器 API、日期、無效的 HTML)
  • 使用錯誤疊加層除錯
  • 每種原因的修正方法

Suspense 邊界

參閱 suspense-boundaries.md 了解:

  • 使用 useSearchParams 和 usePathname 時的 CSR 退出
  • 哪些鉤子需要 Suspense 邊界

平行與攔截路由

參閱 parallel-routes.md 了解:

  • 使用 @slot 和 (.) 攔截器的 Modal 模式
  • 用於備用方案的 default.tsx
  • 使用 router.back() 正確關閉 Modal

自架設

參閱 self-hosting.md 了解:

  • 用於 Docker 的 output: 'standalone'
  • 用於多執行個體 ISR 的快取處理器
  • 哪些功能可行 vs 需要額外設定

除錯技巧

參閱 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".

相關技能