Skip to content

Commit

Permalink
fix: Failed to execute 'encode' on 'TextEncoder': parameter 1 is not …
Browse files Browse the repository at this point in the history
…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 <>
  • Loading branch information
AirBorne04 committed Feb 1, 2023
1 parent 94bcf24 commit f91615f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/curvy-owls-grow.md
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion packages/astro/src/runtime/server/render/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
6 changes: 4 additions & 2 deletions packages/astro/src/runtime/server/render/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 '';
}
})();
}

Expand Down

0 comments on commit f91615f

Please sign in to comment.