Communitygithub.com

Next.js 16 Launchpad

使用 Turbopack(預設)、快取元件和 proxy.ts 啟動、遷移及建立 Next.js 16 專案。搭配 App Router 與 React 19 使用。

Next.js 16 Launchpad 是什麼?

這是一個專為 Next.js 16 設計的 AI 助手技能,提供完整的開發引導與遷移指南。它涵蓋了 Next.js 16 的主要新功能:預設啟用 Turbopack(建置速度提升 2-5 倍)、全新的快取元件(使用 `'use cache'` 指令與 `cacheLife()` 函式)以及用於路由邏輯控制的 `proxy.ts` 邊界。此技能可協助開發者從 v15 遷移至 v16,並提供從專案初始化、設定配置、Server Components、Client Components 到串流渲染與生產模式的最佳實務。支援的目標平台包括 Vercel 的零配置部署,以及 Docker/Node 的獨立輸出模式。透過詳細的檢查清單和常見陷阱分析,它能有效引導開發者避免常見錯誤,順利建構高效能、快取的現代化 Next.js 應用程式。

相容平台~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. Proxy 邊界

// 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/ 目錄下為預設、零客戶端 JavaScript
  3. 客戶端元件 - 'use client'、Hooks、瀏覽器 API
  4. 快取元件 - 'use cache' + cacheLife() 實現 PPR
  5. Proxy 邊界 - 用於驗證/重寫/重新導向的 proxy.ts
  6. 部分預渲染 - 靜態 Shell + 動態串流

遷移檢查清單

  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 匯入 ✅ 為 proxy 使用 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 並行化 fetch
  • 使用 <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

相關技能