sveltejs / sveltejs/kit

Allow static builds to use Remote Functions

Open
#14,336 15 comments 62 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

pkg:adapter-static
Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

Description

Describe the problem

Remote functions query, form, and command are only available when shipping SvelteKit with a server, such as with serverless or Node.js adapters. Anyone shipping desktop applications cannot leverage Remote Functions today.

Describe the proposed solution

Provide an opt-in configuration that allows static builds to consume query, form, and command functions client-side so long as they point to remote functions deployed elsewhere. As an idea, we could add a config option such as kit.remoteFunctions.origin for developers to set their remote server, such as https://api.example.com or an environment variable. Absence of this configuration should fail the build for any prerendered or static pages consuming the above remote function types.

This unlocks being able to maintain a single codebase that can use Remote Functions and conditionally deploy as a native (Capacitor, Electron, Tauri, Wails, etc) app with adapter-static, or a website using any server-like adapter such as adapter-node.

The challenge with ensuring compatibility between the native builds and their corresponding remote site is avoiding drift between breaking changes in remote functions; it's very possible for the remote application to ship before users update their local/native apps. Some mitigation strategies could be:

  1. Check for version when remote functions return a 'not found' error and provide a signal. That way in userland we can show a notice to the end user to refresh or update their application.
  2. Application maintainers could version their remote functions, either in the directory structure such as shipping a v1 and v2 file to coexist until all consumers upgrade (src/lib/v1/todos.remote.ts, src/lib/v2/todos.remote.ts)
  3. Function exports can be versioned in their name (const getTodos = query(/* ... */), const getTodos_v2 = query(/* ... */)).
Alternatives considered

Adopt a third-party querying library.

Importance

nice to have

Additional Information

Related comment: https://github.com/sveltejs/kit/discussions/13897#discussioncomment-13619404

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Begin by tracing SvelteKit's remote-function handling for query, form, and command and the kit configuration path; the issue names no specific file or test. Done means an opt-in origin lets prerendered or static builds consume remote functions, while builds without it fail as described, with compatibility behavior clarified.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api, build-system, web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.