Add Streaming Support to Remote Functions
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 30/100
- Issue type
- Feature
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- javascript, typescript
- Domain
- api, backend-api-design, full-stack
Research direction
Start by reading the remote-function entry points in the SvelteKit codebase, then compare the proposed server example in src/lib/server/todos.remote.ts with the client example in src/routes/todos/+page.svelte. Review the alternative +server.ts ReadableStream approach and determine the API, serialization, cancellation, and client-consumption requirements. Done would mean an agreed design and tests covering streamed remote-function values.
Written by the indexing model from the issue text.
Description
Describe the problem
Hi SvelteKit team! Remote functions are awesome for server-client calls. I think adding a stream primitive to $app/server for generators to return ReadableStream would be great for things like real-time data or large datasets.
Describe the proposed solution
A stream export that turns generator yields into a JSON stream, consumable as an async iterable on the client.
Server (src/lib/server/todos.remote.ts):
import { stream } from '$app/server';
export const watchTodos = stream(async function* () {
yield { id: 1, title: 'Todo 1', completed: true };
await new Promise(r => setTimeout(r, 1000));
yield { id: 2, title: 'Todo 2', completed: false };
});
Client (src/routes/todos/+page.svelte):
<script lang="ts">
import { watchTodos } from '$lib/server/todos.remote';
</script>
<ul>
{#each watchTodos() as todo}
<li>{todo.title} - {todo.completed ? 'Done' : 'Pending'}</li>
{/each}
</ul>
- Could add cancellation or custom serialization.
- Please close if this duplicates another issue.
Thanks for considering!
Alternatives considered
Manual ReadableStream in a +server.ts route: Verbose, requires custom fetch handling on the client, and doesn't integrate with remote functions' type safety and simplicity.
// +server.ts
export async function GET() {
return new Response(new ReadableStream({
async start(controller) {
controller.enqueue(JSON.stringify({ id: 1, title: 'Todo 1' }));
// More enqueues...
controller.close();
}
}), { headers: { 'Content-Type': 'application/json' } });
}
Importance
would make my life easier
Additional Information
No response
- Dominant language
- JavaScript
- Stars
- 20.8k
- Forks
- 2.3k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 156
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from sveltejs/kit
-
awaiting submitter
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
-
documentation pkg:adapter-vercel
Difficulty 1/5 Under an hour Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Similar issues
-
code-quality refactoring
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
github/gh-aw-firewall#8816 ·
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
optimization optimization:agents-md-curator
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
githubnext/gh-aw-cao#13143 ·
-
status: needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100