Communitygithub.com

Next.js 16 启动工具包

用于引导、迁移和构建基于 Next.js 16 + Turbopack、缓存组件和 proxy.ts 的应用。

Next.js 16 启动工具包 是什么?

这是一个专门为 Next.js 16 设计的 AI 智能体技能,旨在帮助开发者快速启动新项目、从旧版本迁移,或使用最新的 React 19 和 App Router 构建高性能应用。该技能集成了 Next.js 16 的核心新特性:默认启用 Turbopack(构建速度提升 2-5 倍)、'use cache' 驱动的缓存组件以实现部分预渲染(PPR)、以及用于精细控制认证和重定向的 proxy.ts 替代旧的 middleware.ts。技能提供了从项目初始化、配置文件修改到生产模式(如电商、认证仪表盘)的完整代码示例和迁移清单。它特别强调了对 Node.js 20.9+、TypeScript 5.1+ 和 React 19.2+ 的依赖,并建议使用 TypeScript、ESLint、Tailwind 和 App Router。该技能适用于 Cursor、Claude Code 等主流 AI 代码助手,通过清晰的步骤和模式帮助开发者避免常见陷阱,如混合 'use cache' 与运行时 API 或遗漏 <Suspense> 边界。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/ComeOnOliver/skillshub/tree/HEAD/skills/aiskillstore/marketplace/calel33/next-js-16-launchpad

在你喜欢的 AI 中提问

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

文档

Next.js 16 启动工具包 是做什么的?

Next.js 16:默认启用 Turbopack(构建速度提升 2-5 倍)、缓存组件('use cache')和用于显式控制的 proxy.ts。

何时使用

✅ Next.js 16、Turbopack、缓存组件、proxy 迁移、App Router、React 19.2

❌ Pages Router、Next.js ≤15、通用 React 问题

要求

工具版本
Node.js20.9.0+
TypeScript5.1.0+
React19.2+

快速开始

# 新项目
npx create-next-app@latest my-app

# 升级现有项目
npx @next/codemod@canary upgrade latest
npm install next@latest react@latest react-dom@latest

推荐:TypeScript、ESLint、Tailwind、App Router、Turbopack、@/* 别名。

最小设置

// app/layout.tsx
export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <body>{children}</body>
    </html>
  )
}
// app/page.tsx
export default function Page() {
  return <h1>Hello, Next.js 16!</h1>
}

配置

// next.config.ts
import type { NextConfig } from 'next'

const nextConfig: NextConfig = {
  cacheComponents: true,
  reactCompiler: true,
}

export default nextConfig

v15 → v16 变化

v15v16
experimental.turbopack默认启用
experimental.pprcacheComponents
middleware.ts (Edge)proxy.ts (Node)
同步 paramsawait params

核心模式

1. 服务器组件(默认)

export default async function BlogPage() {
  const res = await fetch('https://api.example.com/posts')
  const posts = await res.json()
  return <PostList posts={posts} />
}

2. 缓存组件

import { cacheLife } from 'next/cache'

export default async function BlogPage() {
  'use cache'
  cacheLife('hours')
  const posts = await fetch('https://api.example.com/posts').then(r => r.json())
  return <PostList posts={posts} />
}

3. 客户端组件

'use client'
import { useState } from 'react'

export default function Counter() {
  const [count, setCount] = useState(0)
  return (
    <div>
      <p>Count: {count}</p>
      <button onClick={() => setCount(count + 1)}>+</button>
    </div>
  )
}

4. 代理边界

// app/proxy.ts
export function proxy(request: NextRequest) {
  if (!request.cookies.get('auth') && request.nextUrl.pathname.startsWith('/dashboard')) {
    return NextResponse.redirect(new URL('/login', request.url))
  }
  return NextResponse.next()
}

5. 缓存标签 + 服务器操作

// app/blog/page.tsx
'use cache'
cacheLife('hours')
cacheTag('blog-posts')

export default async function BlogList() {
  const posts = await db.posts.findMany()
  return <PostList posts={posts} />
}
// app/actions.ts
'use server'
import { updateTag } from 'next/cache'

export async function createPost(data: PostData) {
  await db.posts.create(data)
  updateTag('blog-posts')
}

6. 使用 Suspense 实现流式传输

export default function Dashboard() {
  return (
    <div>
      <Suspense fallback={<Skeleton />}>
        <RevenueCard />
      </Suspense>
      <Suspense fallback={<Skeleton />}>
        <UsersCard />
      </Suspense>
    </div>
  )
}

async function RevenueCard() {
  const data = await db.analytics.revenue()
  return <div>{data}</div>
}

关键概念

  1. Turbopack - Rust 打包器,增量编译,快速刷新
  2. 服务器组件 - app/ 目录下的默认组件,零客户端 JS
  3. 客户端组件 - 'use client',hooks,浏览器 API
  4. 缓存组件 - 'use cache' + cacheLife() 实现 PPR
  5. 代理边界 - proxy.ts 用于认证/重写/重定向
  6. 部分预渲染 - 静态外壳 + 动态流式传输

迁移清单

  1. 异步请求 API

    npx @next/codemod@canary async-request-api
    

    更新:const { slug } = await params

  2. middleware.ts → proxy.ts

    • 重命名文件,导出 proxy
    • 仅使用 Node 运行时(非 Edge)
  3. 配置更新

    • 移除 experimental.* 标志
    • 启用 cacheComponents、reactCompiler
    • 移除 serverRuntimeConfig/publicRuntimeConfig
  4. 缓存组件

    • 将 experimental.ppr 替换为 cacheComponents: true
    • 用 <Suspense> 包裹动态部分
  5. 图片

    • 为查询字符串配置 images.localPatterns

查看 references/nextjs16-migration-playbook.md 获取完整指南。

常见陷阱

❌ 在缓存组件中混合使用运行时 API(cookies()、headers()) ❌ 启用缓存组件后缺少 <Suspense> ❌ 在 Turbopack 下使用 Tilde Sass 导入 ❌ 在 Edge 运行时运行 proxy.ts

✅ 首先读取 cookies/headers,然后作为 props 传递给缓存组件 ✅ 用 <Suspense> 包裹动态子组件 ✅ 使用标准 Sass 导入 ✅ 为代理使用 Node 运行时

决策指南

是否启用缓存组件? → 是:适用于静态/半静态内容 → 否:适用于完全动态的仪表盘

认证逻辑放在哪里? → proxy.ts:用于跨路由检查 → 路由处理器:用于特定 API 的逻辑

何时使用 'use client'? → 仅当你需要 hooks、状态或浏览器 API 时 → 保持展示组件在服务端

生产模式

电商

// 带流式传输的产品页面
export default async function Product({ params }) {
  const { id } = await params
  const product = await db.products.findById(id)
  
  return (
    <>
      <ProductInfo product={product} />
      <Suspense fallback={<ReviewsSkeleton />}>
        <Reviews productId={id} />
      </Suspense>
    </>
  )
}

认证仪表盘

// proxy.ts
export function proxy(request: NextRequest) {
  const session = request.cookies.get('session')
  if (!session && request.nextUrl.pathname.startsWith('/dashboard')) {
    return NextResponse.redirect(new URL('/login', request.url))
  }
}

查看 references/nextjs16-advanced-patterns.md 获取更多模板。

性能

  • 保持 Turbopack 启用(仅在必要时使用 --webpack 选择退出)
  • 使用 Promise.all 并行化数据获取
  • 使用 <Suspense> 作为流式传输边界
  • 为大型仓库启用文件系统缓存

安全

  • 使用 server-only 包 + React Taint API
  • 将认证逻辑保留在 proxy.ts 中
  • 在服务器操作中验证输入
  • 使用 NEXT_PUBLIC_ 前缀限定环境变量
  • 在缓存作用域之前提取 cookies/headers

部署

  • Vercel:零配置
  • Docker/Node:output: 'standalone'
  • 监控构建时间(预计提速 2-5 倍)
  • 配置缓存生命周期以匹配 CDN

参考文件

  • references/nextjs16-reference.md - 安装/配置/清单
  • references/nextjs16-migration-playbook.md - 包含 codemod 的迁移指南
  • references/nextjs16-advanced-patterns.md - 流式传输、缓存和认证模式
  • references/NEXTJS_16_COMPLETE_GUIDE.md - 完整文档
  • scripts/bootstrap-nextjs16.ps1 - 自动设置脚本
  • assets/app-router-starter/ - 参考实现

资源

版本: 1.1.0 | 更新日期: 2025-12-27

Individual skills in this repo

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

ComeOnOliver/skillshub

Create stunning, animation-rich HTML presentations from scratch or by converting PowerPoint files. Use when the user wants to build a presentation, convert a PPT/PPTX to web, or create slides for a talk/pitch. Helps non-designers discover their aesthetic through visual exploration rather than abstract choices.

ComeOnOliver/skillshub

Next.js 16+ 和 Turbopack — 增量打包、文件系统缓存、开发速度,以及何时使用 Turbopack 与 webpack。

ComeOnOliver/skillshub

SwiftUI architecture patterns, state management with @Observable, view composition, navigation, performance optimization, and modern iOS/macOS UI best practices.

ComeOnOliver/skillshub

See, Understand, Act on video and audio. See- ingest from local files, URLs, RTSP/live feeds, or live record desktop; return realtime context and playable stream links. Understand- extract frames, build visual/semantic/temporal indexes, and search moments with timestamps and auto-clips. Act- transcode and normalize (codec, fps, resolution, aspect ratio), perform timeline edits (subtitles, text/image overlays, branding, audio overlays, dubbing, translation), generate media assets (image, audio, video), and create real time alerts for events from live streams or desktop capture.

ComeOnOliver/skillshub

AI-assisted video editing workflows for cutting, structuring, and augmenting real footage. Covers the full pipeline from raw capture through FFmpeg, Remotion, ElevenLabs, fal.ai, and final polish in Descript or CapCut. Use when the user wants to edit video, cut footage, create vlogs, or build video content.

ComeOnOliver/skillshub

Next.js 15 애플리케이션을 위한 프론트엔드 개발 가이드라인. React 19, TypeScript, Shadcn/ui, Tailwind CSS를 사용한 모던 패턴. Server Components, Client Components, App Router, 파일 구조, Shadcn/ui 컴포넌트, 성능 최적화, TypeScript 모범 사례 포함. 컴포넌트, 페이지, 기능 생성, 데이터 페칭, 스타일링, 라우팅, 프론트엔드 코드 작업 시 사용.

ComeOnOliver/skillshub

Provides Tamagui patterns for config v4, compiler optimization, styled context, and cross-platform styling. Must use when working with Tamagui projects (tamagui.config.ts, @tamagui imports).

ComeOnOliver/skillshub

Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.

ComeOnOliver/skillshub

Create high-converting, visually distinctive landing pages. Use when building marketing pages, product launches, SaaS homepages, or any single-page conversion-focused website. Guides section-by-section composition with anti-AI-slop principles.

ComeOnOliver/skillshub

Auto-loaded context for Portfolio Buddy 2 development. Use for ANY task involving: React 19 development, TypeScript, portfolio analysis features, metrics calculations, trading strategy comparison, or working with the Portfolio Buddy 2 codebase. Contains tech stack, known issues, and architectural constraints.

ComeOnOliver/skillshub

Next.js development tooling via MCP. Inspect routes, components, build info, and debug Next.js apps. Use when working on Next.js applications, debugging routing, or inspecting app structure. NOT for general React or non-Next.js projects.

ComeOnOliver/skillshub

Implement UI using Shadcn MCP (atoms/theme) and 21st.dev MCP (complex sections). Use when adding buttons, layouts, or generating landing pages.

ComeOnOliver/skillshub

A conceptual skill for building an API client in Next.js that handles JWT tokens

ComeOnOliver/skillshub

Best practices and patterns for Next.js App Router, Server Actions, and Routing in this project.

ComeOnOliver/skillshub

The Design System, Theme, and UX rules for the Physical AI Hub.

ComeOnOliver/skillshub

Comprehensive frontend development skill for building modern, performant web applications using ReactJS, NextJS, TypeScript, Tailwind CSS. Includes component scaffolding, performance optimization, bundle analysis, and UI best practices. Use when developing frontend features, optimizing performance, implementing UI/UX designs, managing state, or reviewing frontend code.

ComeOnOliver/skillshub

This document captures learnings from fixing keyboard navigation issues when floating components (Select, DropdownMenu, Popover) have CSS open/close animations.

ComeOnOliver/skillshub

Build Next.js 16 applications with correct patterns and distinctive design. Use when creating pages, layouts, dynamic routes, upgrading from Next.js 15, or implementing proxy.ts. Covers breaking changes (async params/searchParams, Turbopack, cacheComponents) and frontend aesthetics. NOT when building non-React or backend-only applications.

ComeOnOliver/skillshub

Comprehensive Framer Motion animation library for React. Covers motion components, variants, gestures, page transitions, and scroll animations. Use when adding animations to React/Next.js applications.

ComeOnOliver/skillshub

Build interfaces that resonate, not just render. This skill enforces bold, intentional

相关技能