diff --git a/lib/router/router.js b/lib/router/router.js index aaba0862f65daff2d01a7f980fe48692b1a5bd7a..b54f741387b83c98a530bce0b3a9916184500b9f 100644 --- a/lib/router/router.js +++ b/lib/router/router.js @@ -288,7 +288,14 @@ export default class Router { } const jsonPageRes = await this.fetchRoute(route) - const jsonData = await jsonPageRes.json() + let jsonData + // We can call .json() only once for a response. + // That's why we need to keep a copy of data if we already parsed it. + if (jsonPageRes.data) { + jsonData = jsonPageRes.data + } else { + jsonData = jsonPageRes.data = await jsonPageRes.json() + } if (jsonData.buildIdMismatch) { _notifyBuildIdMismatch(as) @@ -336,16 +343,13 @@ export default class Router { return props } - async fetchRoute (route) { + fetchRoute (route) { let promise = this.fetchingRoutes[route] if (!promise) { promise = this.fetchingRoutes[route] = this.doFetchRoute(route) } - const res = await promise - // We need to clone this to prevent reading the body twice - // Because it's possible only once to read res.json() or a similar method. - return res.clone() + return promise } doFetchRoute (route) {