Skip to content

Return ReadableStream from form action #10279

@robertutterback

Description

@robertutterback

Describe the problem

We can return a ReadableStream from an endpoint in +server.ts, but trying to do the same from a form action in +page.server.ts makes Sveltekit complain that the data returned is not serializable.

I might be missing a reason why this isn't a good idea, but it would be convenient for me. In my case I allow the user to upload many files, some of which might be quite large. I would like to push status messages back to the user as the files are written on the server.

Describe the proposed solution

Allow returning ReadableStream from form actions.

Alternatives considered

I could just use an API route, but then to handle the streamed response I need to use browser-side fetch to submit, which means users without JS can't upload files (I think?).

In an ideal world, users without JS can still upload files, they just can't see any progress updates.

Importance

nice to have

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature / enhancementNew feature or requestformsStuff relating to forms and form actionsneeds-decisionNot sure if we want to do this yet, also design work needed

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions