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

Streaming promises in load function #502

Open
mihaipoenaru opened this issue Nov 4, 2024 · 2 comments
Open

Streaming promises in load function #502

mihaipoenaru opened this issue Nov 4, 2024 · 2 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@mihaipoenaru
Copy link

Is your feature request related to a problem? Please describe.
I have some slow data that needs to be fetched from a database, which pre-populates the form. I don't want the user to wait 4 seconds for the page to load, since the form itself is not the main feature of the page, so I use an {#await} block to show a spinner while the data is dynamically streamed, like in this documentation: https://svelte.dev/docs/kit/load#Streaming-with-promises

From what I've dug around, zod does support promises but no matter how much I fiddled with it, superforms does not want to accept a promise on the server for superValidate

Describe the solution you'd like
To accept a z.promise and integrate with an await block somehow.

Describe alternatives you've considered
I tried to return the Promise result from superValidate on the server, and then await that on the client, but the resulting code was quite disgusting and didn't really work at all, especially trying to use enhance

@mihaipoenaru mihaipoenaru added the enhancement New feature or request label Nov 4, 2024
@ciscoheat ciscoheat added the help wanted Extra attention is needed label Nov 15, 2024
@ciscoheat
Copy link
Owner

Any ideas how to make this work?

@mihaipoenaru
Copy link
Author

I'd have to have a lot more knowledge about the codebase to even begin forming a relevant opinion, but a 'back of the napkin' thought would be to chain the promise with another then() that would do what superforms needs for its magic to work.

The user would just {#await} and the promise will resolve as normal. "Easier said than done" would be an understatement though, as I don't have an idea on how it works behind the scenes, so this may not be the way to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants