Skip to content

Streamed promises for universal load functions? #9782

@aradalvand

Description

@aradalvand

Describe the problem

Apparently streamed promises only work in +page.server.js load functions. If you return a nested promise in a universal (+page.js) load function, the promise will simply be recreated on the client-side (i.e. in the browser).

Correct me if I'm wrong, but it seems like the benefis that streamed promises offer in theory — which were mentioned in this blog post — aren't limited to server load functions:

There were ways to work around this. In particular, you could fetch the slow data in the component itself, so it first renders with the data from load and then starts fetching the slow data. But this was not ideal: the data is even more delayed since you don’t start fetching until the client renders, and you’re also having to break SvelteKit’s load convention.

(emphasis mine)

Both of the aforementioned shortcomings that streamed promises are meant to rectify would also apply in the context of +page.js load functions.

Describe the proposed solution

Support streamed promises for +page.js load functions.
When a +page.js load function is being executed on the server, the nested promises would behave similarly to +page.server.js load functions, and when the +page.js load function is being executed on the client (e.g. during client-side navigation), the promises would simply be created on the client.

Alternatives considered

No response

Importance

nice to have

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions