From f91615f5c04fde36f115dad9110dd75254efd61d Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 1 Feb 2023 14:26:45 +0100 Subject: [PATCH] fix: Failed to execute 'encode' on 'TextEncoder': parameter 1 is not of type 'String' in Edge Runtime SSR (#6070) * minor fixes for errors related to vercel SSR in core * yielding empty string instead of nothing, to not exit the iterator --------- Co-authored-by: AirBorne04 <> --- .changeset/curvy-owls-grow.md | 6 ++++++ packages/astro/src/runtime/server/render/common.ts | 4 +++- packages/astro/src/runtime/server/render/component.ts | 6 ++++-- 3 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 .changeset/curvy-owls-grow.md diff --git a/.changeset/curvy-owls-grow.md b/.changeset/curvy-owls-grow.md new file mode 100644 index 0000000000..8a5434f3fa --- /dev/null +++ b/.changeset/curvy-owls-grow.md @@ -0,0 +1,6 @@ +--- +'astro': patch +--- + +* safe guard against TextEncode.encode(HTMLString) [errors on vercel edge] +* safe guard against html.replace when html is undefined \ No newline at end of file diff --git a/packages/astro/src/runtime/server/render/common.ts b/packages/astro/src/runtime/server/render/common.ts index 9b1aa1453b..dbb9a6ec59 100644 --- a/packages/astro/src/runtime/server/render/common.ts +++ b/packages/astro/src/runtime/server/render/common.ts @@ -93,5 +93,7 @@ export function chunkToByteArray( if (chunk instanceof Uint8Array) { return chunk as Uint8Array; } - return encoder.encode(stringifyChunk(result, chunk)); + // stringify chunk might return a HTMLString + let stringified = stringifyChunk(result, chunk); + return encoder.encode(stringified.toString()); } diff --git a/packages/astro/src/runtime/server/render/component.ts b/packages/astro/src/runtime/server/render/component.ts index b6a6576f17..a2ab2e3278 100644 --- a/packages/astro/src/runtime/server/render/component.ts +++ b/packages/astro/src/runtime/server/render/component.ts @@ -261,9 +261,11 @@ If you're still stuck, please open an issue on GitHub or join us at https://astr if (isPage || renderer?.name === 'astro:jsx') { yield html; - } else { + } else if(html && html.length > 0) { yield markHTMLString(html.replace(/\<\/?astro-slot\>/g, '')); - } + } else { + yield ''; + } })(); }