Skip to content

Commit b9680ae

Browse files
authored
Cache react-fetch results in the Node version (#20407)
1 parent cdae31a commit b9680ae

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

packages/react-fetch/src/ReactFetchNode.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ function Response(nativeResponse) {
100100
this.url = nativeResponse.url;
101101

102102
this._response = nativeResponse;
103-
this._blob = null;
104103
this._json = null;
105104
this._text = null;
106105

@@ -151,12 +150,22 @@ Response.prototype = {
151150
throw new Error('Not implemented.');
152151
},
153152
json() {
153+
if (this._json !== null) {
154+
return this._json;
155+
}
154156
const buffer = readResult(this._result);
155-
return JSON.parse(buffer.toString());
157+
const json = JSON.parse(buffer.toString());
158+
this._json = json;
159+
return json;
156160
},
157161
text() {
162+
if (this._text !== null) {
163+
return this._text;
164+
}
158165
const buffer = readResult(this._result);
159-
return buffer.toString();
166+
const text = buffer.toString();
167+
this._text = text;
168+
return text;
160169
},
161170
};
162171

0 commit comments

Comments
 (0)