Communitygithub.com

ComeOnOliver/skillshub

處理表單提交、突變與 RPC 風格的資料操作。在 Next.js 中實作 Server Actions、表單突變或 RPC 風格的資料操作時使用。(觸發條件:app/**/actions.ts、src/app/**/actions.ts、app/**/*.tsx、src/app/**/*.tsx、use server、Server Action、revalidatePath、useFormStatus)

skillshub 是什麼?

此技能專門為 Next.js 開發者設計,用於在 App Router 環境下實作 Server Actions,讓開發者能夠在不建立 API 端點的情況下處理表單提交和資料突變。它涵蓋了從基礎的 `'use server'` 指令使用、表單處理(包括 `action` prop、`useFormStatus` 監聽按鈕 loading 狀態、`useActionState` 管理表單狀態)、資料刷新(`revalidatePath`、`revalidateTag`)到進階功能如非表單觸發(`useTransition`)、樂觀更新(`useOptimistic`)以及安全性(輸入消毒、權限檢查)等完整實現指南。支援的平台包括 Next.js 13+(App Router)與 React 19/Next.js 15 的新 API。此技能透過詳細的實作準則、運算標準(P1 優先級)、限制條件(如閉包避免與重新導向處理)及反模式提醒,確保開發者能撰寫出正確、高效且安全的 Server Actions 程式碼。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/ComeOnOliver/skillshub/tree/HEAD/skills/HoangNguyen0403/agent-skills-standard/nextjs-server-actions

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

Server Actions

優先級:P1(高)

[!WARNING] 如果專案使用 pages/ 目錄而非 App Router,請忽略此技能。

處理表單提交與突變,無需建立 API 端點。

實作指南

  • 指令:始終以 'use server' 開頭開始檔案或函式。使用 formData.get('title') 存取型別化的表單欄位。匯出非同步函式以進行突變。

  • 表單處理:使用 <form> 的 action prop 透過 action={createPost} 觸發動作。使用 useFormStatus() 處理 pending 狀態 — 在按鈕上使用 disabled={pending}。使用 useActionState(React 19/Next.js 15)搭配 <form action={action}> 處理表單狀態。

  • 資料刷新:在成功的突變後,使用 revalidatePath('/') 或 revalidateTag('tag-name') 觸發 UI 更新。

  • 互動性:對於非表單觸發,使用 useTransition Hook 來處理載入 UI 並防止頁面阻塞。

  • 樂觀更新:使用 useOptimistic 在伺服器確認突變之前立即顯示預期的 UI 狀態。

  • 安全性:清理所有來自 FormData 的輸入。在每個動作內執行 身份驗證檢查(await auth())。限制檔案上傳的大小和 MIME 類型。

  • 表單:<form action={createPost}>(漸進增強在無 JS 時也能運作)。

  • 事件處理器:onClick={() => createPost(data)}。

  • 等待狀態:使用 useFormStatus Hook(必須在表單內渲染的元件中使用)。

P1:運算標準

1. 安全與驗證

始終使用 z.object({ 架構和 safeParse 驗證輸入,然後再進行處理。在動作內部檢查授權。請參閱安全動作範例。

2. 等待狀態

使用 useActionState(React 19/Next.js 15+)處理狀態,並使用 useFormStatus 處理按鈕載入狀態。

限制條件

  • 閉包:避免在元件內部定義動作,以防止隱藏的閉包加密開銷和序列化錯誤。
  • 重新導向:使用 redirect() 進行成功導航;它會拋出一個 Next.js 捕獲的錯誤來處理重新導向。

反模式

  • 未經驗證的 Server Action 輸入:始終在處理前使用 Zod 進行驗證。
  • 跳過身份驗證檢查:在每個動作內部驗證 session/使用者,而不僅僅是中介軟體。
  • 在元件內部定義動作:在 actions.ts 中定義以避免閉包錯誤。
  • 在 try/catch 中使用 redirect():redirect() 會拋出錯誤;捕獲它會抑制重新導向。

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

相關技能