diff --git a/.changeset/sixty-tips-play.md b/.changeset/sixty-tips-play.md new file mode 100644 index 000000000..31ebef4da --- /dev/null +++ b/.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. diff --git a/packages/astro/src/runtime/server/render/util.ts b/packages/astro/src/runtime/server/render/util.ts index 1f0aae047..182700976 100644 --- a/packages/astro/src/runtime/server/render/util.ts +++ b/packages/astro/src/runtime/server/render/util.ts @@ -149,10 +149,10 @@ export function bufferIterators(iterators: AsyncIterable[]): 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; }