sveltejs / sveltejs/kit

Streamed promises for universal load functions?

Open
#9,782 3 comments 8 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the issue's discussion, the linked pull request comment, and the streaming snapshots blog post to understand how nested promises currently behave in +page.server.js versus +page.js load functions. Trace server execution and client-side navigation for universal load functions; done means server execution streams nested promises while client execution creates them in the browser.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
web-dev
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.