-
Notifications
You must be signed in to change notification settings - Fork 87
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
fix: fixes cases re throttledPromised: abort misbehaviour and not awaited queue #865
Conversation
commit: |
src/throttlePromise.ts
Outdated
@@ -15,7 +15,7 @@ type Queue = { | |||
|
|||
interface ISbThrottle { | |||
abort: () => any | |||
(args: []): Promise<Queue> | |||
(...args: any): Promise<Queue> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-blocking: @alexjoverm Can we do anything to avoid using any
here? I will leave it to your personal criteria if it's something we should do on the scope of this PR or in the v7 refactor. In normal cases I would block a PR from merging if there are any
on the types
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's do, will need some extra help as I think we can do this type a bit more precise
…blok/storyblok-js-client into fix/PRO-803-throttle-issue
Moving it to #869 for difficulties renaming one of the commits |
We've been reported in #682, and thanks to the discovery of @dojscart in withastro/adapters#43 (comment) (really really thanks 🙏 ) we've managed to identify that the internal queue of the throttle promise wasn't being awaited properly, causing some edge cases to fail (like Cloudflare, and likely the SSG generation).
On the way, I also managed to find another case -> after aborting the queue, promises kept being added and got stuck in the queue unresolved forever.
Solution
Basically, now the promises in the queue are awaited properly after crossing the limit, and no new promises are getting added after aborting the queue.
Fixes #682
How to test the issue
npx vitest run src/throttlePromise.test.ts
against thesrc/throttlePromise.ts
living in themain
branch -> both test cases should failsrc/throttlePromise.ts
from this branch -> both test cases should pass correctlyAside from that, I can recommend to try to break the expected functionality of the throttlePromise and its internal queue. I tried via a local script to heavily load the queue with all kind of scenarios - thousands of calls, randomly make them fail, etc - and so far it worked out, but extra eyes and hands are always great.