Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Run the new test npx vitest run src/throttlePromise.test.ts against the src/throttlePromise.ts living in the main branch -> both test cases should fail
Now, run again the same test against the updated src/throttlePromise.ts from this branch -> both test cases should pass correctly
Aside 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.