SvelteKit Remote Functions

Enable type-safe remote function calls from client to server in SvelteKit.

1|Updated Aug 11, 2025
One-click install
npx skills add https://github.com/AdamAugustinsky/a3-stack-kysely --skill sveltekit-remote-functions-adamaugustinsky
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: SvelteKit Remote Functions
Source: https://github.com/AdamAugustinsky/a3-stack-kysely/tree/main/.claude/skills/sveltekit-remote-functions
Command: npx skills add https://github.com/AdamAugustinsky/a3-stack-kysely --skill sveltekit-remote-functions-adamaugustinsky

SYSTEM DOCUMENTATION & REQUIREMENTS

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.async to use await in 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, command and prerender provide 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

  1. Enable remote functions in svelte.config.js (e.g., set kit.experimental.remoteFunctions to true).
  2. Create a remote file (e.g., src/routes/blog/data.remote.ts) and export a function using query, form, or prerender.
  3. Call the remote function from a component using the exported function and handle the response with await or reactive stores.

Frequently Asked Questions about SvelteKit Remote Functions

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I make type-safe client-server calls in SvelteKit?

Remote Functions enable type-safe client-server calls by letting you define server-side logic in .remote.js/.remote.ts files and call them from components with full type inference. Enable kit.experimental.remoteFunctions in svelte.config.js, create remote files exporting query, form, command, or prerender functions, then call them from your components—the functions always execute on the server and can safely access databases and environment variables.

Can I load data directly in SvelteKit components without writing endpoints?

Yes. Remote Functions let you load and manipulate data directly inside components by combining typed remote calls with Svelte's experimental await support. Create a .remote.ts file with a query function, enable compilerOptions.experimental.async in svelte.config.js, then use await in your component to fetch data server-side while maintaining type safety and security.

What are the different types of remote functions in SvelteKit?

Remote Functions come in four flavors: query for typed read operations, form for mutations with form data, command for direct server-side actions, and prerender for generating static data at build time. Each flavor handles a specific communication pattern between client and server while preserving type safety and running all logic server-side.

Do remote functions in SvelteKit require opt-in configuration?

Yes, Remote Functions are experimental and require explicit opt-in. Set kit.experimental.remoteFunctions to true in svelte.config.js, and optionally enable compilerOptions.experimental.async to use await in components. Place .remote.js or .remote.ts files anywhere in src except src/lib/server to define your typed server-side functions.

How do remote functions access server-only modules like databases in SvelteKit?

Remote Functions run exclusively on the server, so they can safely import and use server-only modules containing database clients, authentication logic, and environment variables. Your client code calls the remote function, but the actual execution happens server-side, keeping secrets and server dependencies inaccessible from the browser.

What's the difference between remote functions and traditional SvelteKit endpoints?

Remote Functions provide end-to-end type safety and eliminate boilerplate by automatically generating typed wrappers for server logic. Unlike manual endpoints, remote functions serialize results automatically and let you call typed functions directly from components instead of managing fetch requests and serialization yourself.