From 2726098bc82f910edda4198b9fb94f2bfd048976 Mon Sep 17 00:00:00 2001 From: Matteo Manfredi Date: Tue, 27 Jun 2023 16:16:41 +0200 Subject: [PATCH] Update `setTimeout()` to `queueMicrotask()` (#7494) --- .changeset/sixty-tips-play.md | 5 +++++ packages/astro/src/runtime/server/render/util.ts | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 .changeset/sixty-tips-play.md diff --git a/.changeset/sixty-tips-play.md b/.changeset/sixty-tips-play.md new file mode 100644 index 0000000000..31ebef4dac --- /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 1f0aae047b..182700976c 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; }