Skip to content

Commit 8cd79d3

Browse files
authored
Fix race condition issue with .json() (#731)
1 parent a87d9e9 commit 8cd79d3

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

source/core/Ky.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,16 @@ export class Ky {
112112
return '';
113113
}
114114

115-
const arrayBuffer = await response.clone().arrayBuffer();
116-
const responseSize = arrayBuffer.byteLength;
117-
if (responseSize === 0) {
115+
const text = await response.text();
116+
if (text === '') {
118117
return '';
119118
}
120119

121120
if (options.parseJson) {
122-
return options.parseJson(await response.text());
121+
return options.parseJson(text);
123122
}
123+
124+
return JSON.parse(text);
124125
}
125126

126127
return response[type]();

0 commit comments

Comments
 (0)