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

Only one promise resolves when streamed from load (using Promise.resolve) #9330

Closed
dreitzner opened this issue Mar 6, 2023 · 0 comments · Fixed by #9332
Closed

Only one promise resolves when streamed from load (using Promise.resolve) #9330

dreitzner opened this issue Mar 6, 2023 · 0 comments · Fixed by #9332
Labels
bug Something isn't working

Comments

@dreitzner
Copy link
Contributor

Describe the bug

I am using SvelteKit with the adapter/node.
I am connecting to an external API and cache the responses.
On the first request (no cache) I return the promises of the api calls.
All of them are resolved correctly.

On the second request (valid cache) I return the cache value wrapped in a Promise.resolve().
If I use that for only one Promise, this promise resolves in the {#await} block.
If I have more than one Promise, only the first promise resolves in the {#await} block, all others show the loading state.

Reproduction

Stackblitz: https://stackblitz.com/edit/sveltejs-kit-template-default-fgdj1s?file=src/routes/+page.server.js

image

the second promise never resolves

got to /only-one => everything resolves correctly

Logs

No response

System Info

Should not be relevant, as it can be reproduced on stackblitz.

  System:
    OS: Windows 10 10.0.19045
    CPU: (16) x64 AMD Ryzen 7 PRO 5850U with Radeon Graphics     
    Memory: 11.05 GB / 31.56 GB
  Binaries:
    Node: 18.12.1 - ~\AppData\Local\Volta\tools\image\node\18.12.1\node.EXE    
    Yarn: 1.22.18 - ~\AppData\Local\Volta\tools\image\yarn\1.22.18\bin\yarn.CMD
    npm: 8.19.2 - ~\AppData\Local\Volta\tools\image\node\18.12.1\npm.CMD       
  Browsers:
    Edge: Spartan (44.19041.1266.0), Chromium (110.0.1587.63)
    Internet Explorer: 11.0.19041.1566
  npmPackages:
    @sveltejs/adapter-node: ^1.2.0 => 1.2.0 
    @sveltejs/kit: ^1.10.0 => 1.10.0 
    svelte: ^3.55.0 => 3.55.1

Severity

serious, but I can work around it

Additional Information

can be worked around with a promise wrapper

const promiseWrap = <T>(value: T): Promise<T> => new Promise((resolve) => {
    setTimeout(() => resolve(value));
})
@dreitzner dreitzner changed the title Promise does not resolve Only one promise resolves when streamed from load (using Promise.resolve) Mar 6, 2023
@dummdidumm dummdidumm added the bug Something isn't working label Mar 6, 2023
Rich-Harris pushed a commit that referenced this issue Mar 6, 2023
…9332)

* fix: deal with fast consecutive promise resolutions when streaming

fixes #9330

* Update packages/kit/src/utils/streaming.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants