Skip to content

Commit

Permalink
Update setTimeout() to queueMicrotask() (#7494)
Browse files Browse the repository at this point in the history
  • Loading branch information
itsmatteomanf committed Jun 27, 2023
1 parent a82c6df commit 2726098
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/sixty-tips-play.md
@@ -0,0 +1,5 @@
---
"astro": patch
---

Replaces the instance of `setTimeout()` in the runtime to use `queueMicrotask()`, to resolve limitations on Cloudflare Workers.
4 changes: 2 additions & 2 deletions packages/astro/src/runtime/server/render/util.ts
Expand Up @@ -149,10 +149,10 @@ export function bufferIterators<T>(iterators: AsyncIterable<T>[]): AsyncIterable
const eagerIterators = iterators.map((it) => new EagerAsyncIterableIterator(it));
// once the execution of the next for loop is suspended due to an async component,
// this timeout triggers and we start buffering the other iterators
setTimeout(() => {
queueMicrotask(() => {
// buffer all iterators that haven't started yet
eagerIterators.forEach((it) => !it.isStarted() && it.buffer());
}, 0);
});
return eagerIterators;
}

Expand Down

0 comments on commit 2726098

Please sign in to comment.