nextjs-expert
它能做什么
这个技能指导使用 Next.js 构建 Web 应用,包括 App Router、服务端组件、数据获取、缓存和部署。适合构建快速且对搜索引擎友好的网站和 Web 应用的开发者。
适用场景
- ✓当你开始一个新的 Next.js 应用,或把现有应用迁移到 App Router 时。
- ✓当页面加载缓慢,你希望减少客户端 JavaScript 时。
- ✓当你的 Next.js 项目需要 API 路由或中间件时。
技能链接
https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/nextjs-expert/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请设置一个 Next.js App Router 页面,在服务端加载产品数据,并在获取期间显示加载状态。”
每周 5 个新技能,1 分钟读完。
工作原理
该技能默认推荐服务端组件、基于文件夹的路由、加载和错误边界以及路由处理程序,并提供静态渲染或按需渲染的选项。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Next.js Expert
A seasoned Next.js architect with deep expertise in the App Router paradigm, server-side rendering strategies, and production deployment patterns. This skill provides guidance on building performant, SEO-friendly web applications using Next.js 14+ conventions, including Server Components, Streaming, and the full spectrum of data fetching and caching mechanisms.
Key Principles
- Prefer Server Components by default; only add "use client" when the component requires browser APIs, event handlers, or React state
- Leverage the app/ directory structure where each folder segment maps to a URL route, using layout.tsx for shared UI and page.tsx for unique content
- Design data fetching at the server layer using async Server Components and fetch with Next.js caching semantics
- Use generateStaticParams for static pre-rendering of dynamic routes at build time, falling back to on-demand ISR for long-tail pages
- Keep client bundles small by pushing logic into Server Components and using dynamic imports for heavy client-only libraries
Techniques
- Structure routes with app/[segment]/page.tsx, using route groups (parentheses) to organize without affecting URL paths
- Implement loading.tsx and error.tsx boundaries at each route segment to provide instant loading states and graceful error recovery
- Use Route Handlers (app/api/.../route.ts) with exported GET, POST, PUT, DELETE functions for API endpoints
- Configure middleware in middleware.ts at the project root with a matcher config to intercept requests for auth, redirects, or header injection
- Optimize images with next/image (automatic srcSet, lazy loading, AVIF/WebP) and fonts with next/font (zero layout shift, self-hosted subsets)
- Enable ISR by returning revalidate values from fetch calls or using revalidatePath/revalidateTag for on-demand cache invalidation
- Set up next.config.js with redirects, rewrites, headers, and the experimental options appropriate to your deployment target
Common Patterns
- Parallel Routes: Use @named slots in layouts to render multiple page-level components simultaneously, enabling dashboards and split views
- Intercepting Routes: Place (..) convention routes to show modals on navigation while preserving the direct URL as a full page
- Server Actions: Define async functions with "use server" for form submissions and mutations without building separate API routes
- Streaming with Suspense: Wrap slow data-fetching components in Suspense boundaries to stream HTML progressively and improve TTFB
Pitfalls to Avoid
- Do not use useEffect for data fetching in Server Components; fetch directly in the component body or use server-side utilities
- Do not place "use client" at the layout level unless every child truly requires client interactivity, as this opts out the entire subtree from server rendering
- Do not confuse the Pages Router (pages/ directory) patterns with App Router conventions; they have different data fetching and routing models
- Do not skip setting proper cache headers and revalidation times, as stale data and unnecessary re-renders degrade both performance and user experience
常见问题
什么是服务端组件?
它是在服务器上运行的组件,因此可以获取数据,而无需把额外代码发送到浏览器。
什么时候应该添加 use client?
正如该技能所建议的,只有当组件需要浏览器功能、事件处理程序或 React 状态时才添加。
loading.tsx 和 error.tsx 做什么?
它们在路由加载时显示加载状态,并在出错时显示友好的提示信息。
详情
作者的原始描述
Next.js expert for App Router, SSR/SSG, API routes, middleware, and deployment
repo: RightNow-AI/openfang
热度
- GitHub 星标
- 18k
- 排名
- #10692
- 许可证
- Apache-2.0
- 更新时间
- 2026/7/2
评论
- …
同一仓库的更多技能
browser-automation
18k教你的智能体使用 Playwright 控制网页浏览器,借助 CSS 选择器找到按钮、表单和链接。
clip-hand-skill
18k帮你的智能体制作视频片段:下载视频、转录语音、生成字幕文件,并用 ffmpeg 剪辑片段。
collector-hand-skill
18k帮你的智能体收集某个主题或公司的公开信息,提取关键实体,跟踪变化并判断舆论倾向。
infisical-sync-skill
18k帮你的智能体通过 API 读取和更新 Infisical 保险库中的密钥,包含登录步骤和清晰的错误处理。