From 1734c49f516ff7d778d6724a0db6d39649921b4b Mon Sep 17 00:00:00 2001 From: Theo Ephraim Date: Tue, 4 Jun 2024 20:17:49 -0700 Subject: [PATCH] fix: better isPromise check for proxy objects (#11178) --- .changeset/green-moose-fetch.md | 5 +++++ packages/astro/src/runtime/server/util.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changeset/green-moose-fetch.md diff --git a/.changeset/green-moose-fetch.md b/.changeset/green-moose-fetch.md new file mode 100644 index 000000000000..b1115cbf800e --- /dev/null +++ b/.changeset/green-moose-fetch.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Improves `isPromise` utility to check the presence of `then` on an object before trying to access it - which can cause undesired side-effects on Proxy objects diff --git a/packages/astro/src/runtime/server/util.ts b/packages/astro/src/runtime/server/util.ts index 97b953c726f4..e75b10f57eb7 100644 --- a/packages/astro/src/runtime/server/util.ts +++ b/packages/astro/src/runtime/server/util.ts @@ -1,5 +1,5 @@ export function isPromise(value: any): value is Promise { - return !!value && typeof value === 'object' && typeof value.then === 'function'; + return !!value && typeof value === 'object' && 'then' in value && typeof value.then === 'function'; } export async function* streamAsyncIterator(stream: ReadableStream) {