SvelteKit Remote Functions
CommunityEnable type-safe client-server calls in SvelteKit.
System Documentation
What problem does it solve?
Remote Functions are a tool for type-safe communication between client and server. They can be called anywhere in your app, but always run on the server, meaning they can safely access server-only modules containing things like environment variables and database clients.
Combined with Svelte's experimental support for await in components, it allows you to load and manipulate data directly inside your components.
This feature is currently experimental, meaning it is likely to contain bugs and is subject to change without notice. You must opt in by adding the kit.experimental.remoteFunctions option in your svelte.config.js and optionally, the compilerOptions.experimental.async option to use await in components:
- You can enable remote functions in svelte.config.js to opt in for this feature.
- Optionally enable
compilerOptions.experimental.asyncto useawaitin components.
Practical takeaway: use remote functions to fetch data or submit actions from the client while keeping server-side security intact.
Quick intuition: think of remote functions as a type-safe bridge between client calls and server-side logic.
For more details, refer to the official SvelteKit Remote Functions docs.
Core Features & Use Cases
- Four flavors:
query,form,commandandprerenderprovide typed read, write, and prerender capabilities. - Server-side execution: Functions run on the server and can access server-only modules and environment variables.
- Frontend integration: Use in SvelteKit components to fetch data or submit forms with typed inputs/outputs.
Quick Start
- Enable remote functions in
svelte.config.js(e.g., setkit.experimental.remoteFunctionsto true). - Create a remote file (e.g.,
src/routes/blog/data.remote.ts) and export a function usingquery,form, orprerender. - Call the remote function from a component using the exported function and handle the response with
awaitor reactive stores.
Dependency Matrix
Required Modules
None requiredComponents
Standard package💻 Claude Code Installation
Recommended: Let Claude install automatically. Simply copy and paste the text below to Claude Code.
Please help me install this Skill: Name: SvelteKit Remote Functions Download link: https://github.com/AdamAugustinsky/a3-stack-kysely/archive/main.zip#sveltekit-remote-functions Please download this .zip file, extract it, and install it in the .claude/skills/ directory.