Simplified Response#text() implementation (#3705)

* Simplified Response#text() implementation

* Adds a changeset

* Fix tsignore
This commit is contained in:
Matthew Phillips 2022-06-24 16:58:14 -04:00 committed by GitHub
parent b11e3b38eb
commit b5e3403fa1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 32 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fixes build some times breaking in large sites

View file

@ -3,9 +3,9 @@ const renderer = {
serverEntrypoint: 'astro/jsx/server.js',
jsxImportSource: 'astro',
jsxTransformOptions: async () => {
// @ts-ignore
const {
default: { default: jsx },
// @ts-ignore
} = await import('@babel/plugin-transform-react-jsx');
const { default: astroJSX } = await import('./babel.js');
return {

View file

@ -21,36 +21,22 @@ function createResponseClass() {
async text(): Promise<string> {
if (this.#isStream && isNodeJS) {
let decoder = new TextDecoder();
let body = this.#body as ReadableStream<Uint8Array>;
let reader = body.getReader();
let buffer: number[] = [];
while (true) {
let r = await reader.read();
if (r.value) {
buffer.push(...r.value);
}
if (r.done) {
break;
}
let body = this.#body as AsyncIterable<Uint8Array>;
let out = '';
for await(let chunk of body) {
out += decoder.decode(chunk);
}
return decoder.decode(Uint8Array.from(buffer));
return out;
}
return super.text();
}
async arrayBuffer(): Promise<ArrayBuffer> {
if (this.#isStream && isNodeJS) {
let body = this.#body as ReadableStream<Uint8Array>;
let reader = body.getReader();
let body = this.#body as AsyncIterable<Uint8Array>;
let chunks: number[] = [];
while (true) {
let r = await reader.read();
if (r.value) {
chunks.push(...r.value);
}
if (r.done) {
break;
}
for await(let chunk of body) {
chunks.push(...chunk);
}
return Uint8Array.from(chunks);
}

View file

@ -8554,11 +8554,6 @@ packages:
/debug/3.2.7:
resolution: {integrity: sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==}
peerDependencies:
supports-color: '*'
peerDependenciesMeta:
supports-color:
optional: true
dependencies:
ms: 2.1.3
dev: false
@ -11440,8 +11435,6 @@ packages:
debug: 3.2.7
iconv-lite: 0.4.24
sax: 1.2.4
transitivePeerDependencies:
- supports-color
dev: false
/netmask/2.0.2:
@ -11525,8 +11518,6 @@ packages:
rimraf: 2.7.1
semver: 5.7.1
tar: 4.4.19
transitivePeerDependencies:
- supports-color
dev: false
/node-releases/2.0.5: