svelte-effect-runtime

Remote Functions

Choose Query, Command, Form, or Prerender for server work.

Remote functions are SvelteKit server entry points wrapped in Effect. They keep server code on the server while giving clients typed inputs, typed failures, and predictable pending states.

When to use this

Use a remote function when the work needs a database, secret, cookie, session, server service, or build-time data source. Keep purely local UI behavior in component effects.

Minimal working example

import { Query } from "svelte-effect-runtime/server";
import { Effect, Schema } from "effect";

export const get_count = Query(Schema.Struct({ key: Schema.String }), ({ key }) =>
  Effect.succeed({ key, value: 1 }),
);
<script lang="ts" effect>
  import { get_count } from "./counter.remote";

  const count = get_count({ key: "visits" });
</script>

{#await yield* count}
  <p>Loading...</p>
{:then result}
  <p>{result.value}</p>
{/await}

Realistic variant

Pick the shape that matches the user intent:

Decision guide

  • Use Query when the UI needs server data without changing it.
  • Use Query.batch when many small same-kind reads should become one server call.
  • Use Query.live when server data should keep streaming while the UI is connected.
  • Use Command when the user does something that changes server state.
  • Use Form when HTML form semantics, validation, and progressive enhancement matter.
  • Use Prerender when data can be resolved at build time or cached as static output.

Common mistakes

  • Using Query for writes because it is convenient to call.
  • Returning unstructured thrown errors instead of typed failures.
  • Reading cookies or locals from component code instead of the server request context.
  • Forgetting to enable SvelteKit's remote function flag.

On this page