sveltekit-remote-functions
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSvelteKit Remote Functions
SvelteKit 远程函数
Quick Start
快速开始
File naming: for remote function files
*.remote.tsWhich function? One-time action → | Repeated reads →
| Forms →
command()query()form()文件命名规则: 远程函数文件使用命名
*.remote.ts如何选择函数? 一次性操作 → | 重复读取操作 → | 表单处理 →
command()query()form()Example
示例
typescript
// actions.remote.ts
import { command } from "$app/server";
import * as v from "valibot";
export const delete_user = command(
v.object({ id: v.string() }),
async ({ id }) => {
await db.users.delete(id);
return { success: true };
}
);
// Call from client: await delete_user({ id: '123' });typescript
// actions.remote.ts
import { command } from "$app/server";
import * as v from "valibot";
export const delete_user = command(
v.object({ id: v.string() }),
async ({ id }) => {
await db.users.delete(id);
return { success: true };
}
);
// 从客户端调用:await delete_user({ id: '123' });Reference Files
参考文档
- references/remote-functions.md - Complete guide with all patterns
- references/remote-functions.md - 包含所有使用模式的完整指南
Notes
注意事项
- Remote functions execute on server when called from browser
- Args/returns must be JSON-serializable
- Schema validation via StandardSchemaV1 (Valibot/Zod)
- available for cookies/headers access
getRequestEvent() - In components: Use +
<svelte:boundary>(no flicker){@const await} - Refresh queries: Call - updates without flicker
query().refresh() - Last verified: 2025-12-24
- 远程函数在从浏览器调用时会在服务器端执行
- 参数/返回值必须是可JSON序列化的
- 可通过StandardSchemaV1(Valibot/Zod)进行 Schema 验证
- 可使用访问Cookie/请求头
getRequestEvent() - 在组件中使用: 结合+
<svelte:boundary>使用(避免页面闪烁){@const await} - 刷新查询: 调用- 无闪烁更新数据
query().refresh() - 最后验证时间: 2025-12-24