Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d32e69e

Browse files
arunodaleo
authored andcommitted
Get rid of res.clone() (vercel#1567)
Usually res.clone() should work. But it's not working with the laster Safari (10.1) We need to use a method we do not clone
1 parent 66ab661 commit d32e69e

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

lib/router/router.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,14 @@ export default class Router {
288288
}
289289

290290
const jsonPageRes = await this.fetchRoute(route)
291-
const jsonData = await jsonPageRes.json()
291+
let jsonData
292+
// We can call .json() only once for a response.
293+
// That's why we need to keep a copy of data if we already parsed it.
294+
if (jsonPageRes.data) {
295+
jsonData = jsonPageRes.data
296+
} else {
297+
jsonData = jsonPageRes.data = await jsonPageRes.json()
298+
}
292299

293300
if (jsonData.buildIdMismatch) {
294301
_notifyBuildIdMismatch(as)
@@ -336,16 +343,13 @@ export default class Router {
336343
return props
337344
}
338345

339-
async fetchRoute (route) {
346+
fetchRoute (route) {
340347
let promise = this.fetchingRoutes[route]
341348
if (!promise) {
342349
promise = this.fetchingRoutes[route] = this.doFetchRoute(route)
343350
}
344351

345-
const res = await promise
346-
// We need to clone this to prevent reading the body twice
347-
// Because it's possible only once to read res.json() or a similar method.
348-
return res.clone()
352+
return promise
349353
}
350354

351355
doFetchRoute (route) {

0 commit comments

Comments
 (0)