Sveltekit remote functions

From spences10/skills · View interactive version

Sveltekit remote functions is an AI agent skill from the GitHub repository spences10/skills. Implement SvelteKit remote functions. Use for query(), query.live(), form(), command(), and prerender() patterns in .remote.ts files.

How to use this skill

Skill file

SvelteKit Remote Functions

Current Status

Remote functions are experimental in SvelteKit 2.58. Prefer enabling them in vite.config.ts via the SvelteKit Vite plugin:

import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vite';

export default defineConfig({
	plugins: [
		sveltekit({
			experimental: { remoteFunctions: true },
			compilerOptions: { experimental: { async: true } } // only for await in components
		})
	]
});

Quick Start

File naming: export remote functions from *.remote.ts or *.remote.js.

Remote files can live anywhere under src except src/lib/server.

Which function?

Example

// posts.remote.ts
import { command, query, requested } from "$app/server";
import * as v from "valibot";

export const getPosts = query(
	v.object({ tag: v.optional(v.string()) }),
	async (filter) => {
		return db.posts.find(filter);
	},
);

export const createPost = command(
	v.object({ title: v.string() }),
	async (data) => {
		await db.posts.create(data);

		for (const { query } of requested(getPosts, 5)) {
			void query.refresh();
		}
	},
);

Client:

<script lang="ts">
	import { createPost, getPosts } from './posts.remote';

	const posts = $derived(await getPosts({ tag: 'svelte' }));
</script>

<button onclick={() => createPost({ title: 'New' }).updates(getPosts)}>
	Create
</button>

Current Rules

Reference Files

<!--

PROGRESSIVE DISCLOSURE GUIDELINES:

LLM WORKFLOW (when editing this file):

  1. Write/edit SKILL.md
  2. Format (if formatter available)
  3. Run: npx skills add . --list
  4. If the skill is not discovered, check SKILL.md frontmatter formatting
  5. Validate again to confirm

-->

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.