Cache react-fetch results in the Node version (#20407)
Dan Abramov committed
Dec 8, 2020 at 22:37 UTC
b9680aef7dfc180ab4d4a7957611ad024db7e8db
1 file changed
+12
-3
packages/react-fetch/src/ReactFetchNode.js
+12
-3
@@ -100,7 +100,6 @@ function Response(nativeResponse) {
100
this.url = nativeResponse.url;
101
102
this._response = nativeResponse;
103
- this._blob = null;
103
this._json = null;
104
this._text = null;
105
@@ -151,12 +150,22 @@ Response.prototype = {
150
throw new Error('Not implemented.');
151
},
152
json() {
153
+ if (this._json !== null) {
154
+ return this._json;
155
+ }
156
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;
160
},
161
text() {
162
+ if (this._text !== null) {
163
+ return this._text;
164
+ }
165
const buffer = readResult(this._result);
159
- return buffer.toString();
166
+ const text = buffer.toString();
167
+ this._text = text;
168
+ return text;
169
},
170
};
171