跳到正文
Skillpedia
网站与界面(前端)18k · #10692

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。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/nextjs-expert/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能