kit: Defer not working properly when multiple promises are returned
Describe the bug
I’ve tryed the new defer api with vercel edge functions and when a single promise is returned it works as intended. However when you return multiple promises things get’s messy quickly.
For example
const wait = (ms) => new Promise((r) => setTimeout(r, ms));
async function getBlog() {
await wait(2000);
return 'A cool blog post';
}
async function getComments() {
await wait(4000);
return ['Very cool', 'Super', 'Fantastic'];
}
async function getRecommended() {
await wait(1000);
return ['Another post', 'Suh interesting'];
}
async function getFail() {
await wait(8000);
throw new Error('Dang!');
}
export async function load() {
const recommended = getRecommended();
const comments = getComments();
const fail = getFail();
const blog = await getBlog();
return {
blog,
defer: {
recommended,
comments,
fail
}
};
}
this configuration correcly wait 2 seconds before showing the page. The recommended shows a sliver of loading state to than resolve immediately however for getComments and getFail the loading state perpetrate until both of them resolve at the same time. When i was trying this at the beginning i saw the same kind of result with only getRecommended + getComments (in this case getRecommended that should already be resolved was persisting in the loading state for a couple of seconds).
Reproduction
You can see the live version of this on vercel.
You can see the code on my github repo and edit the code on stackblitz
Logs
No logs
System Info
System:
OS: Linux 5.0 undefined
CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 0 Bytes / 0 Bytes
Shell: 1.0 - /bin/jsh
Binaries:
Node: 16.14.2 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 7.17.0 - /usr/local/bin/npm
npmPackages:
@sveltejs/adapter-auto: ^2.0.0 => 2.0.0
@sveltejs/adapter-vercel: ^2.0.4 => 2.0.4
@sveltejs/kit: ^1.5.0 => 1.8.3
svelte: ^3.54.0 => 3.55.1
vite: ^4.0.0 => 4.1.3
Severity
blocking an upgrade
Additional Information
No response
About this issue
- Original URL
- State: open
- Created a year ago
- Reactions: 2
- Comments: 27 (14 by maintainers)
Another intresting difference is that remix html comes already with the data if the promise is already resolved (for example the recommended post if you see the rendered html does not have the loading state)