Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can load return async iterators? #13156

Open
CNSeniorious000 opened this issue Dec 12, 2024 · 3 comments
Open

Can load return async iterators? #13156

CNSeniorious000 opened this issue Dec 12, 2024 · 3 comments

Comments

@CNSeniorious000
Copy link

Describe the problem

In the era of generative AI, we often need to stream data to the client. In SvelteKit routes can return promises inside load transparently, that's good. I think it won't be hard to support async generators too.

For example, I use Svelte in a lot of GenAI related sites of mine. Usually I invoke streaming responses on the client side, via an API endpoint, but that's neither the most performant way, nor the besy UX. The API calling only happens after the full hydration, which is even slower on hardwares with bad network environment. If we can stream async iterators inside page load functions, that would save several seconds from users for each page load!

For now, there is actually a possible workaround:

Let's say you want to return a iterator which wouldn't yield more than 10,000 times. You can return a list with 10,000 promise instead, inside which the [i]-th promise will resolves when the async iterator yield the [i]-th times, or the iterator exhausted before that.

Describe the proposed solution

The same as how promises inside route loaders in sveltekit, like using trailing <script> with SSR.

Importance

would make my life easier

@Ocean-OS
Copy link

This issue should probably be moved to SvelteKit's repo.

@paoloricciuti
Copy link
Member

This issue should probably be moved to SvelteKit's repo.

Correct

@paoloricciuti
Copy link
Member

Ugh I can't do it, since I don't have access to kit

@Rich-Harris Rich-Harris transferred this issue from sveltejs/svelte Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants