From b5e3403fa151710be4837f6ad265d836adb08025 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Fri, 24 Jun 2022 16:58:14 -0400 Subject: [PATCH] Simplified Response#text() implementation (#3705) * Simplified Response#text() implementation * Adds a changeset * Fix tsignore --- .changeset/early-teachers-vanish.md | 5 ++++ packages/astro/src/jsx/renderer.ts | 2 +- packages/astro/src/runtime/server/response.ts | 30 +++++-------------- pnpm-lock.yaml | 9 ------ 4 files changed, 14 insertions(+), 32 deletions(-) create mode 100644 .changeset/early-teachers-vanish.md diff --git a/.changeset/early-teachers-vanish.md b/.changeset/early-teachers-vanish.md new file mode 100644 index 000000000..851541c21 --- /dev/null +++ b/.changeset/early-teachers-vanish.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes build some times breaking in large sites diff --git a/packages/astro/src/jsx/renderer.ts b/packages/astro/src/jsx/renderer.ts index 54f4d6a3d..3aee8520f 100644 --- a/packages/astro/src/jsx/renderer.ts +++ b/packages/astro/src/jsx/renderer.ts @@ -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 { diff --git a/packages/astro/src/runtime/server/response.ts b/packages/astro/src/runtime/server/response.ts index 084ea7436..1369f3f05 100644 --- a/packages/astro/src/runtime/server/response.ts +++ b/packages/astro/src/runtime/server/response.ts @@ -21,36 +21,22 @@ function createResponseClass() { async text(): Promise { if (this.#isStream && isNodeJS) { let decoder = new TextDecoder(); - let body = this.#body as ReadableStream; - 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; + 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 { if (this.#isStream && isNodeJS) { - let body = this.#body as ReadableStream; - let reader = body.getReader(); + let body = this.#body as AsyncIterable; 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); } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7be62432c..fcedb9ab3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -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: