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 项目中高效处理 Server Actions、表单变异及 RPC 风格的数据变更。它优先适用于使用 App Router 的项目,提供了从文件或函数开头添加 `'use server'` 指令,到使用 `formData.get()` 获取表单数据、通过 `<form action={createPost}>` 触发变异,以及利用 `useFormStatus` 和 `useActionState` 管理提交状态等完整的实施指南。技能还强调了数据刷新(`revalidatePath`、`revalidateTag`)、非表单触发(`useTransition`)、乐观更新(`useOptimistic`)以及安全验证(Zod schema、权限检查)的最佳实践。支持平台包括 Claude Code、Cursor 和 Codex 等主流 AI 编码代理,旨在帮助开发者避免反模式,如未经验证的输入、跳过权限检查、在组件内定义动作以及错误捕获 `redirect()`。

兼容平台~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 属性通过 action={createPost} 触发操作。使用 useFormStatus() 处理 pending 状态 —— 在按钮上使用 disabled={pending}。使用 useActionState(React 19/Next.js 15)处理 <form action={action}> 的表单状态。

  • 数据刷新:在成功变异后使用 revalidatePath('/') 或 revalidateTag('tag-name') 触发 UI 更新。

  • 交互性:对于非表单触发器,使用 useTransition 钩子调用操作,以处理加载 UI 并防止页面阻塞。

  • 乐观更新:使用 useOptimistic 在服务器确认变异之前立即显示预期的 UI 状态。

  • 安全性:对 FormData 中的所有输入进行消毒。在每个操作中执行身份验证检查(await auth())。按大小和 MIME 类型限制文件上传。

  • 表单:<form action={createPost}>(即使没有 JS,渐进增强也能工作)。

  • 事件处理程序:onClick={() => createPost(data)}。

  • 挂起状态:使用 useFormStatus 钩子(必须在表单内渲染的组件中使用)。

P1:操作标准

1. 安全与验证

在处理之前,始终使用 z.object({ 模式和 safeParse 验证输入。在操作中检查授权。参见安全操作示例。

2. 挂起状态

使用 useActionState(React 19/Next.js 15+)处理状态,使用 useFormStatus 处理按钮加载状态。

约束

  • 闭包:避免在组件内定义操作,以防止隐藏的闭包加密开销和序列化错误。
  • 重定向:使用 redirect() 进行成功导航;它会抛出一个错误,Next.js 捕获该错误以处理重定向。

反模式

  • 不要有未验证的 Server Action 输入:始终在使用 Zod 处理之前进行验证。
  • 不要跳过权限检查:在每个操作中验证会话/用户,而不仅仅是在中间件中。
  • 不要在组件内定义操作:在 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

相关技能