重要前提
安装AI Skills的关键前提是:必须科学上网,且开启TUN模式,这一点至关重要,直接决定安装能否顺利完成,在此郑重提醒三遍:科学上网,科学上网,科学上网。查看完整安装教程 →
safe-action-advanced by next-safe-action/skills
npx skills add https://github.com/next-safe-action/skills --skill safe-action-advanced广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
export const createPost = authActionClient
.inputSchema(schema)
.action(
async ({ parsedInput, ctx }) => {
const post = await db.post.create(parsedInput);
return post;
},
{
onSuccess: async ({ data, parsedInput, ctx, metadata, clientInput }) => {
// 成功执行后在服务器端运行
await invalidateCache("posts");
},
onError: async ({ error, metadata, ctx, clientInput, bindArgsClientInputs }) => {
// error: { serverError?, validationErrors? }
await logError(error);
},
onSettled: async ({ result }) => {
// 总是运行
await recordMetrics(result);
},
onNavigation: async ({ navigationKind }) => {
// 当发生框架错误(重定向、notFound 等)时运行
console.log("Navigation:", navigationKind);
},
}
);
这些与钩子回调(useAction({ onSuccess }))不同——服务器回调在 Node.js 运行时中运行,钩子回调在浏览器中运行。
重新抛出服务器错误,而不是将其作为 result.serverError 返回:
export const myAction = actionClient
.inputSchema(schema)
.action(serverCodeFn, {
throwServerError: true,
// 处理后的服务器错误(handleServerError 的返回值)将被抛出
});
每周安装量
55
仓库
首次出现
2026年3月6日
安全审计
安装于
opencode54
gemini-cli54
github-copilot54
amp54
codex54
kimi-cli54
| Feature | Use Case |
|---|---|
| Bind arguments | Pass extra args to actions via .bind() (e.g., resource IDs) |
| Metadata | Attach typed metadata to actions for use in middleware |
| Framework errors | Handle redirect, notFound, forbidden, unauthorized in actions |
| Type utilities | Infer types from action functions and middleware |
The second argument to .action() accepts callbacks that run on the server (not client-side hooks):
export const createPost = authActionClient
.inputSchema(schema)
.action(
async ({ parsedInput, ctx }) => {
const post = await db.post.create(parsedInput);
return post;
},
{
onSuccess: async ({ data, parsedInput, ctx, metadata, clientInput }) => {
// Runs on the server after successful execution
await invalidateCache("posts");
},
onError: async ({ error, metadata, ctx, clientInput, bindArgsClientInputs }) => {
// error: { serverError?, validationErrors? }
await logError(error);
},
onSettled: async ({ result }) => {
// Always runs
await recordMetrics(result);
},
onNavigation: async ({ navigationKind }) => {
// Runs when a framework error (redirect, notFound, etc.) occurs
console.log("Navigation:", navigationKind);
},
}
);
These are distinct from hook callbacks (useAction({ onSuccess })) — server callbacks run in the Node.js runtime, hook callbacks run in the browser.
Re-throw server errors instead of returning them as result.serverError:
export const myAction = actionClient
.inputSchema(schema)
.action(serverCodeFn, {
throwServerError: true,
// The handled server error (return of handleServerError) is thrown
});
Weekly Installs
55
Repository
First Seen
Mar 6, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode54
gemini-cli54
github-copilot54
amp54
codex54
kimi-cli54
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
125,600 周安装