Simplified Response#text() implementation (#3705)
* Simplified Response#text() implementation * Adds a changeset * Fix tsignore
This commit is contained in:
parent
b11e3b38eb
commit
b5e3403fa1
4 changed files with 14 additions and 32 deletions
5
.changeset/early-teachers-vanish.md
Normal file
5
.changeset/early-teachers-vanish.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fixes build some times breaking in large sites
|
|
@ -3,9 +3,9 @@ const renderer = {
|
||||||
serverEntrypoint: 'astro/jsx/server.js',
|
serverEntrypoint: 'astro/jsx/server.js',
|
||||||
jsxImportSource: 'astro',
|
jsxImportSource: 'astro',
|
||||||
jsxTransformOptions: async () => {
|
jsxTransformOptions: async () => {
|
||||||
// @ts-ignore
|
|
||||||
const {
|
const {
|
||||||
default: { default: jsx },
|
default: { default: jsx },
|
||||||
|
// @ts-ignore
|
||||||
} = await import('@babel/plugin-transform-react-jsx');
|
} = await import('@babel/plugin-transform-react-jsx');
|
||||||
const { default: astroJSX } = await import('./babel.js');
|
const { default: astroJSX } = await import('./babel.js');
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -21,36 +21,22 @@ function createResponseClass() {
|
||||||
async text(): Promise<string> {
|
async text(): Promise<string> {
|
||||||
if (this.#isStream && isNodeJS) {
|
if (this.#isStream && isNodeJS) {
|
||||||
let decoder = new TextDecoder();
|
let decoder = new TextDecoder();
|
||||||
let body = this.#body as ReadableStream<Uint8Array>;
|
let body = this.#body as AsyncIterable<Uint8Array>;
|
||||||
let reader = body.getReader();
|
let out = '';
|
||||||
let buffer: number[] = [];
|
for await(let chunk of body) {
|
||||||
while (true) {
|
out += decoder.decode(chunk);
|
||||||
let r = await reader.read();
|
|
||||||
if (r.value) {
|
|
||||||
buffer.push(...r.value);
|
|
||||||
}
|
|
||||||
if (r.done) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return decoder.decode(Uint8Array.from(buffer));
|
return out;
|
||||||
}
|
}
|
||||||
return super.text();
|
return super.text();
|
||||||
}
|
}
|
||||||
|
|
||||||
async arrayBuffer(): Promise<ArrayBuffer> {
|
async arrayBuffer(): Promise<ArrayBuffer> {
|
||||||
if (this.#isStream && isNodeJS) {
|
if (this.#isStream && isNodeJS) {
|
||||||
let body = this.#body as ReadableStream<Uint8Array>;
|
let body = this.#body as AsyncIterable<Uint8Array>;
|
||||||
let reader = body.getReader();
|
|
||||||
let chunks: number[] = [];
|
let chunks: number[] = [];
|
||||||
while (true) {
|
for await(let chunk of body) {
|
||||||
let r = await reader.read();
|
chunks.push(...chunk);
|
||||||
if (r.value) {
|
|
||||||
chunks.push(...r.value);
|
|
||||||
}
|
|
||||||
if (r.done) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return Uint8Array.from(chunks);
|
return Uint8Array.from(chunks);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8554,11 +8554,6 @@ packages:
|
||||||
|
|
||||||
/debug/3.2.7:
|
/debug/3.2.7:
|
||||||
resolution: {integrity: sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==}
|
resolution: {integrity: sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==}
|
||||||
peerDependencies:
|
|
||||||
supports-color: '*'
|
|
||||||
peerDependenciesMeta:
|
|
||||||
supports-color:
|
|
||||||
optional: true
|
|
||||||
dependencies:
|
dependencies:
|
||||||
ms: 2.1.3
|
ms: 2.1.3
|
||||||
dev: false
|
dev: false
|
||||||
|
@ -11440,8 +11435,6 @@ packages:
|
||||||
debug: 3.2.7
|
debug: 3.2.7
|
||||||
iconv-lite: 0.4.24
|
iconv-lite: 0.4.24
|
||||||
sax: 1.2.4
|
sax: 1.2.4
|
||||||
transitivePeerDependencies:
|
|
||||||
- supports-color
|
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
/netmask/2.0.2:
|
/netmask/2.0.2:
|
||||||
|
@ -11525,8 +11518,6 @@ packages:
|
||||||
rimraf: 2.7.1
|
rimraf: 2.7.1
|
||||||
semver: 5.7.1
|
semver: 5.7.1
|
||||||
tar: 4.4.19
|
tar: 4.4.19
|
||||||
transitivePeerDependencies:
|
|
||||||
- supports-color
|
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
/node-releases/2.0.5:
|
/node-releases/2.0.5:
|
||||||
|
|
Loading…
Reference in a new issue