-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Followup optimizations for new experimentalPrerender #8287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Member
Author
Stats from current PRClick to expand stats ✅ Total Bundle Size Decrease ✅
Click to expand serverless stats ✅ Total Bundle Size Decrease ✅
Diff for main.js@@ -1,5 +1,20 @@
(window["webpackJsonp"] = window["webpackJsonp"] || []).push([[8],{
+/***/ "+iuc":
+/***/ (function(module, exports, __webpack_require__) {
+
+__webpack_require__("wgeU");
+__webpack_require__("FlQf");
+__webpack_require__("bBy9");
+__webpack_require__("B9jh");
+__webpack_require__("dL40");
+__webpack_require__("xvv9");
+__webpack_require__("V+O7");
+module.exports = __webpack_require__("WEpk").Set;
+
+
+/***/ }),
+
/***/ "+oT+":
/***/ (function(module, exports, __webpack_require__) {
@@ -54,6 +69,28 @@ __webpack_require__("cHUd")('Map');
/***/ }),
+/***/ "B9jh":
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+var strong = __webpack_require__("Wu5q");
+var validate = __webpack_require__("n3ko");
+var SET = 'Set';
+
+// 23.2 Set Objects
+module.exports = __webpack_require__("raTm")(SET, function (get) {
+ return function Set() { return get(this, arguments.length > 0 ? arguments[0] : undefined); };
+}, {
+ // 23.2.3.1 Set.prototype.add(value)
+ add: function add(value) {
+ return strong.def(validate(this, SET), value = value === 0 ? 0 : value, value);
+ }
+}, strong);
+
+
+/***/ }),
+
/***/ "BMP1":
/***/ (function(module, exports, __webpack_require__) {
@@ -418,7 +455,7 @@ function (_react$default$Compon) {
this.scrollToHash(); // If page was exported and has a querystring
// If it's a dynamic route or has a querystring
- if (data.nextExport && ((0, _isDynamic.isDynamicRoute)(router.pathname) || location.search)) {
+ if (data.nextExport && ((0, _isDynamic.isDynamicRoute)(router.pathname) || location.search || data.skeleton)) {
// update query on mount for exported pages
router.replace(router.pathname + '?' + (0, _querystring.stringify)((0, _extends2["default"])({}, router.query, (0, _querystring.parse)(location.search.substr(1)))), asPath, {
// WARNING: `_h` is an internal option for handing Next.js
@@ -466,7 +503,7 @@ function () {
var _ref2 = (0, _asyncToGenerator2["default"])(
/*#__PURE__*/
_regenerator["default"].mark(function _callee(_temp) {
- var _ref, passedWebpackHMR, initialErr, _require, isValidElementType, renderCtx, appCtx;
+ var _ref, passedWebpackHMR, initialErr, _require, isValidElementType, renderCtx;
return _regenerator["default"].wrap(function _callee$(_context) {
while (1) {
@@ -555,33 +592,9 @@ function () {
emitter: emitter
};
render(renderCtx);
-
- if (!(window.__NEXT_DATA__.skeleton && Component.getInitialProps)) {
- _context.next = 32;
- break;
- }
-
- appCtx = {
- router: router,
- AppTree: wrapApp(App),
- Component: Component,
- ctx: {
- pathname: page,
- asPath: asPath,
- query: query
- }
- };
- _context.next = 30;
- return App.getInitialProps(appCtx);
-
- case 30:
- props.pageProps = _context.sent.pageProps;
- render(renderCtx);
-
- case 32:
return _context.abrupt("return", emitter);
- case 33:
+ case 27:
case "end":
return _context.stop();
}
@@ -882,6 +895,15 @@ module.exports = __webpack_require__("WEpk").Map;
/***/ }),
+/***/ "V+O7":
+/***/ (function(module, exports, __webpack_require__) {
+
+// https://tc39.github.io/proposal-setmap-offrom/#sec-set.from
+__webpack_require__("aPfg")('Set');
+
+
+/***/ }),
+
/***/ "XLbu":
/***/ (function(module, exports, __webpack_require__) {
@@ -949,6 +971,17 @@ exports.DataManager = DataManager;
/***/ }),
+/***/ "dL40":
+/***/ (function(module, exports, __webpack_require__) {
+
+// https://github.com/DavidBruant/Map-Set.prototype.toJSON
+var $export = __webpack_require__("Y7ZC");
+
+$export($export.P + $export.R, 'Set', { toJSON: __webpack_require__("8iia")('Set') });
+
+
+/***/ }),
+
/***/ "dVTT":
/***/ (function(module, exports, __webpack_require__) {
@@ -1026,6 +1059,22 @@ exports.DataManagerContext = React.createContext(null);
/***/ }),
+/***/ "ttDY":
+/***/ (function(module, exports, __webpack_require__) {
+
+module.exports = __webpack_require__("+iuc");
+
+/***/ }),
+
+/***/ "xvv9":
+/***/ (function(module, exports, __webpack_require__) {
+
+// https://tc39.github.io/proposal-setmap-offrom/#sec-set.of
+__webpack_require__("cHUd")('Set');
+
+
+/***/ }),
+
/***/ "zmvN":
/***/ (function(module, exports, __webpack_require__) {
@@ -1049,10 +1098,12 @@ var _asyncToGenerator2 = _interopRequireDefault(__webpack_require__("+oT+"));
var _promise = _interopRequireDefault(__webpack_require__("eVuF"));
+var _set = _interopRequireDefault(__webpack_require__("ttDY"));
+
var _mitt = _interopRequireDefault(__webpack_require__("kiME"));
var _unfetch = _interopRequireDefault(__webpack_require__("m/Gl"));
-/* global document, window */
+/* global document */
function supportsPreload(el) {
@@ -1082,24 +1133,13 @@ function () {
this.buildId = buildId;
this.assetPrefix = assetPrefix;
this.pageCache = {};
+ this.prefetchCache = new _set["default"]();
this.pageRegisterEvents = (0, _mitt["default"])();
this.loadingRoutes = {};
this.promisedBuildId = _promise["default"].resolve();
-
- if (false) {}
- } // Returns a promise for the dependencies for a particular route
-
+ }
(0, _createClass2["default"])(PageLoader, [{
- key: "getDependencies",
- value: function getDependencies(route) {
- return this.promisedBuildManifest.then(function (man) {
- return man[route] && man[route].map(function (url) {
- return "/_next/" + url;
- }) || [];
- });
- }
- }, {
key: "normalizeRoute",
value: function normalizeRoute(route) {
if (route[0] !== '/') {
@@ -1149,14 +1189,13 @@ function () {
if (document.getElementById("__NEXT_PAGE__" + route)) {
return;
- }
+ } // Load the script if not asked to load yet.
+
if (!_this3.loadingRoutes[route]) {
- if (false) {} else {
- _this3.loadRoute(route);
+ _this3.loadScript(route);
- _this3.loadingRoutes[route] = true;
- }
+ _this3.loadingRoutes[route] = true;
}
});
}
@@ -1186,14 +1225,14 @@ function () {
});
}
}, {
- key: "loadRoute",
- value: function loadRoute(route) {
+ key: "loadScript",
+ value: function loadScript(route) {
var _this = this;
return (0, _asyncToGenerator2["default"])(
/*#__PURE__*/
_regenerator["default"].mark(function _callee() {
- var scriptRoute, url;
+ var scriptRoute, script, url;
return _regenerator["default"].wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
@@ -1204,51 +1243,41 @@ function () {
case 2:
route = _this.normalizeRoute(route);
scriptRoute = route === '/' ? '/index.js' : route + ".js";
+ script = document.createElement('script');
+
+ if ( true && 'noModule' in script) {
+ script.type = 'module';
+ scriptRoute = scriptRoute.replace(/\.js$/, '.module.js');
+ }
+
url = _this.assetPrefix + "/_next/static/" + encodeURIComponent(_this.buildId) + "/pages" + scriptRoute;
+ script.crossOrigin = "anonymous";
+ script.src = url;
+
+ script.onerror = function () {
+ var error = new Error("Error loading script " + url);
+ error.code = 'PAGE_LOAD_ERROR';
+
+ _this.pageRegisterEvents.emit(route, {
+ error: error
+ });
+ };
- _this.loadScript(url, route, true);
+ document.body.appendChild(script);
- case 6:
+ case 11:
case "end":
return _context.stop();
}
}
}, _callee);
}))();
- }
- }, {
- key: "loadScript",
- value: function loadScript(url, route, isPage) {
- var _this5 = this;
-
- var script = document.createElement('script');
-
- if ( true && 'noModule' in script) {
- script.type = 'module'; // Only page bundle scripts need to have .module added to url,
- // dependencies already have it added during build manifest creation
-
- if (isPage) url = url.replace(/\.js$/, '.module.js');
- }
-
- script.crossOrigin = "anonymous";
- script.src = url;
-
- script.onerror = function () {
- var error = new Error("Error loading script " + url);
- error.code = 'PAGE_LOAD_ERROR';
-
- _this5.pageRegisterEvents.emit(route, {
- error: error
- });
- };
-
- document.body.appendChild(script);
} // This method if called by the route code.
}, {
key: "registerPage",
value: function registerPage(route, regFn) {
- var _this6 = this;
+ var _this5 = this;
var register = function register() {
try {
@@ -1256,21 +1285,21 @@ function () {
error = _regFn.error,
page = _regFn.page;
- _this6.pageCache[route] = {
+ _this5.pageCache[route] = {
error: error,
page: page
};
- _this6.pageRegisterEvents.emit(route, {
+ _this5.pageRegisterEvents.emit(route, {
error: error,
page: page
});
} catch (error) {
- _this6.pageCache[route] = {
+ _this5.pageCache[route] = {
error: error
};
- _this6.pageRegisterEvents.emit(route, {
+ _this5.pageRegisterEvents.emit(route, {
error: error
});
}
@@ -1282,21 +1311,17 @@ function () {
}
}, {
key: "prefetch",
- value: function prefetch(route, isDependency) {
+ value: function prefetch(route) {
var _this2 = this;
return (0, _asyncToGenerator2["default"])(
/*#__PURE__*/
_regenerator["default"].mark(function _callee2() {
- var scriptRoute, url, cn;
+ var scriptRoute, cn;
return _regenerator["default"].wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
- _context2.next = 2;
- return _this2.promisedBuildId;
-
- case 2:
route = _this2.normalizeRoute(route);
scriptRoute = (route === '/' ? '/index' : route) + ".js";
@@ -1304,72 +1329,51 @@ function () {
scriptRoute = scriptRoute.replace(/\.js$/, '.module.js');
}
- url = isDependency ? route : _this2.assetPrefix + "/_next/static/" + encodeURIComponent(_this2.buildId) + "/pages" + scriptRoute; // n.b. If preload is not supported, we fall back to `loadPage` which has
- // its own deduping mechanism.
-
- if (!(document.querySelector("link[rel=\"preload\"][href^=\"" + url + "\"]") || document.getElementById("__NEXT_PAGE__" + route))) {
- _context2.next = 8;
+ if (!(_this2.prefetchCache.has(scriptRoute) || document.getElementById("__NEXT_PAGE__" + route))) {
+ _context2.next = 5;
break;
}
return _context2.abrupt("return");
- case 8:
+ case 5:
+ _this2.prefetchCache.add(scriptRoute); // Inspired by quicklink, license: https://github.com/GoogleChromeLabs/quicklink/blob/master/LICENSE
+
+
if (!(cn = navigator.connection)) {
- _context2.next = 11;
+ _context2.next = 9;
break;
}
if (!((cn.effectiveType || '').indexOf('2g') !== -1 || cn.saveData)) {
- _context2.next = 11;
+ _context2.next = 9;
break;
}
return _context2.abrupt("return");
- case 11:
- if (true) {
- _context2.next = 17;
- break;
- }
-
- ;
- _context2.next = 15;
- return _this2.getDependencies(route);
-
- case 15:
- _context2.t0 = function (url) {
- _this2.prefetch(url, true);
- };
-
- _context2.sent.forEach(_context2.t0);
-
- case 17:
+ case 9:
if (!hasPreload) {
- _context2.next = 20;
+ _context2.next = 14;
break;
}
- preloadScript(url);
- return _context2.abrupt("return");
-
- case 20:
- if (!isDependency) {
- _context2.next = 22;
- break;
- }
+ _context2.next = 12;
+ return _this2.promisedBuildId;
+ case 12:
+ preloadScript(_this2.assetPrefix + "/_next/static/" + encodeURIComponent(_this2.buildId) + "/pages" + scriptRoute);
return _context2.abrupt("return");
- case 22:
+ case 14:
if (!(document.readyState === 'complete')) {
- _context2.next = 26;
+ _context2.next = 18;
break;
}
return _context2.abrupt("return", _this2.loadPage(route)["catch"](function () {}));
- case 26:
+ case 18:
return _context2.abrupt("return", new _promise["default"](function (resolve) {
window.addEventListener('load', function () {
_this2.loadPage(route).then(function () {
@@ -1380,7 +1384,7 @@ function () {
});
}));
- case 27:
+ case 19:
case "end":
return _context2.stop();
}
Diff for commons.js@@ -3576,7 +3576,7 @@ function () {
var _getInitialProps = (0, _asyncToGenerator2["default"])(
/*#__PURE__*/
_regenerator["default"].mark(function _callee2(Component, ctx) {
- var cancelled, cancel, App, props, url, res, err;
+ var cancelled, cancel, App, props, status, url, err;
return _regenerator["default"].wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
@@ -3590,13 +3590,13 @@ function () {
this.clc = cancel;
App = this.components['/_app'].Component;
- if (!Component.__NEXT_PRERENDER) {
- _context2.next = 20;
+ if (!Component.__NEXT_SPR) {
+ _context2.next = 11;
break;
}
- url = url_1.format({
- pathname: ctx.asPath,
+ url = ctx.asPath ? ctx.asPath : url_1.format({
+ pathname: ctx.pathname,
query: ctx.query
});
_context2.next = 8;
@@ -3604,44 +3604,31 @@ function () {
headers: {
'content-type': 'application/json'
}
- });
-
- case 8:
- res = _context2.sent;
-
- if (!res.ok) {
- _context2.next = 15;
- break;
- }
+ }).then(function (res) {
+ if (!res.ok) {
+ status = res.status;
+ throw new Error('failed to load prerender data');
+ }
- _context2.next = 12;
- return res.json()["catch"](function (err) {
+ return res.json();
+ }).then(function (pageProps) {
return {
- error: err.message
+ pageProps: pageProps
+ };
+ })["catch"](function (err) {
+ return {
+ error: err.message,
+ status: status
};
});
- case 12:
- _context2.t0 = _context2.sent;
- _context2.next = 16;
- break;
-
- case 15:
- _context2.t0 = {
- error: 'failed to load prerender',
- statusCode: res.status
- };
-
- case 16:
- _context2.t1 = _context2.t0;
- props = {
- pageProps: _context2.t1
- };
- _context2.next = 23;
+ case 8:
+ props = _context2.sent;
+ _context2.next = 14;
break;
- case 20:
- _context2.next = 22;
+ case 11:
+ _context2.next = 13;
return utils_1.loadGetInitialProps(App, {
AppTree: this._wrapApp(App),
Component: Component,
@@ -3649,16 +3636,16 @@ function () {
ctx: ctx
});
- case 22:
+ case 13:
props = _context2.sent;
- case 23:
+ case 14:
if (cancel === this.clc) {
this.clc = null;
}
if (!cancelled) {
- _context2.next = 28;
+ _context2.next = 19;
break;
}
@@ -3666,10 +3653,10 @@ function () {
err.cancelled = true;
throw err;
- case 28:
+ case 19:
return _context2.abrupt("return", props);
- case 29:
+ case 20:
case "end":
return _context2.stop();
}
Diff for mainModern.js@@ -1,5 +1,20 @@
(window["webpackJsonp"] = window["webpackJsonp"] || []).push([[8],{
+/***/ "+iuc":
+/***/ (function(module, exports, __webpack_require__) {
+
+__webpack_require__("wgeU");
+__webpack_require__("FlQf");
+__webpack_require__("bBy9");
+__webpack_require__("B9jh");
+__webpack_require__("dL40");
+__webpack_require__("xvv9");
+__webpack_require__("V+O7");
+module.exports = __webpack_require__("WEpk").Set;
+
+
+/***/ }),
+
/***/ "+oT+":
/***/ (function(module, exports, __webpack_require__) {
@@ -54,6 +69,28 @@ __webpack_require__("cHUd")('Map');
/***/ }),
+/***/ "B9jh":
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+var strong = __webpack_require__("Wu5q");
+var validate = __webpack_require__("n3ko");
+var SET = 'Set';
+
+// 23.2 Set Objects
+module.exports = __webpack_require__("raTm")(SET, function (get) {
+ return function Set() { return get(this, arguments.length > 0 ? arguments[0] : undefined); };
+}, {
+ // 23.2.3.1 Set.prototype.add(value)
+ add: function add(value) {
+ return strong.def(validate(this, SET), value = value === 0 ? 0 : value, value);
+ }
+}, strong);
+
+
+/***/ }),
+
/***/ "BMP1":
/***/ (function(module, exports, __webpack_require__) {
@@ -369,7 +406,7 @@ class Container extends _react.default.Component {
this.scrollToHash(); // If page was exported and has a querystring
// If it's a dynamic route or has a querystring
- if (data.nextExport && ((0, _isDynamic.isDynamicRoute)(router.pathname) || location.search)) {
+ if (data.nextExport && ((0, _isDynamic.isDynamicRoute)(router.pathname) || location.search || data.skeleton)) {
// update query on mount for exported pages
router.replace(router.pathname + '?' + (0, _querystring.stringify)((0, _extends2.default)({}, router.query, (0, _querystring.parse)(location.search.substr(1)))), asPath, {
// WARNING: `_h` is an internal option for handing Next.js
@@ -466,22 +503,6 @@ function () {
emitter
};
render(renderCtx);
-
- if (window.__NEXT_DATA__.skeleton && Component.getInitialProps) {
- const appCtx = {
- router,
- AppTree: wrapApp(App),
- Component: Component,
- ctx: {
- pathname: page,
- asPath,
- query
- }
- };
- props.pageProps = (yield App.getInitialProps(appCtx)).pageProps;
- render(renderCtx);
- }
-
return emitter;
});
@@ -692,6 +713,15 @@ module.exports = __webpack_require__("WEpk").Map;
/***/ }),
+/***/ "V+O7":
+/***/ (function(module, exports, __webpack_require__) {
+
+// https://tc39.github.io/proposal-setmap-offrom/#sec-set.from
+__webpack_require__("aPfg")('Set');
+
+
+/***/ }),
+
/***/ "XLbu":
/***/ (function(module, exports, __webpack_require__) {
@@ -746,6 +776,17 @@ exports.DataManager = DataManager;
/***/ }),
+/***/ "dL40":
+/***/ (function(module, exports, __webpack_require__) {
+
+// https://github.com/DavidBruant/Map-Set.prototype.toJSON
+var $export = __webpack_require__("Y7ZC");
+
+$export($export.P + $export.R, 'Set', { toJSON: __webpack_require__("8iia")('Set') });
+
+
+/***/ }),
+
/***/ "dVTT":
/***/ (function(module, exports, __webpack_require__) {
@@ -821,6 +862,22 @@ exports.DataManagerContext = React.createContext(null);
/***/ }),
+/***/ "ttDY":
+/***/ (function(module, exports, __webpack_require__) {
+
+module.exports = __webpack_require__("+iuc");
+
+/***/ }),
+
+/***/ "xvv9":
+/***/ (function(module, exports, __webpack_require__) {
+
+// https://tc39.github.io/proposal-setmap-offrom/#sec-set.of
+__webpack_require__("cHUd")('Set');
+
+
+/***/ }),
+
/***/ "zmvN":
/***/ (function(module, exports, __webpack_require__) {
@@ -836,10 +893,12 @@ var _asyncToGenerator2 = _interopRequireDefault(__webpack_require__("+oT+"));
var _promise = _interopRequireDefault(__webpack_require__("eVuF"));
+var _set = _interopRequireDefault(__webpack_require__("ttDY"));
+
var _mitt = _interopRequireDefault(__webpack_require__("kiME"));
var _unfetch = _interopRequireDefault(__webpack_require__("m/Gl"));
-/* global document, window */
+/* global document */
function supportsPreload(el) {
@@ -866,16 +925,10 @@ class PageLoader {
this.buildId = buildId;
this.assetPrefix = assetPrefix;
this.pageCache = {};
+ this.prefetchCache = new _set.default();
this.pageRegisterEvents = (0, _mitt.default)();
this.loadingRoutes = {};
this.promisedBuildId = _promise.default.resolve();
-
- if (false) {}
- } // Returns a promise for the dependencies for a particular route
-
-
- getDependencies(route) {
- return this.promisedBuildManifest.then(man => man[route] && man[route].map(url => "/_next/" + url) || []);
}
normalizeRoute(route) {
@@ -924,13 +977,12 @@ class PageLoader {
if (document.getElementById("__NEXT_PAGE__" + route)) {
return;
- }
+ } // Load the script if not asked to load yet.
+
if (!this.loadingRoutes[route]) {
- if (false) {} else {
- this.loadRoute(route);
- this.loadingRoutes[route] = true;
- }
+ this.loadScript(route);
+ this.loadingRoutes[route] = true;
}
});
}
@@ -955,41 +1007,35 @@ class PageLoader {
});
}
- loadRoute(route) {
+ loadScript(route) {
var _this = this;
return (0, _asyncToGenerator2.default)(function* () {
yield _this.promisedBuildId;
route = _this.normalizeRoute(route);
let scriptRoute = route === '/' ? '/index.js' : route + ".js";
- const url = _this.assetPrefix + "/_next/static/" + encodeURIComponent(_this.buildId) + "/pages" + scriptRoute;
+ const script = document.createElement('script');
- _this.loadScript(url, route, true);
- })();
- }
-
- loadScript(url, route, isPage) {
- const script = document.createElement('script');
-
- if ( true && 'noModule' in script) {
- script.type = 'module'; // Only page bundle scripts need to have .module added to url,
- // dependencies already have it added during build manifest creation
+ if ( true && 'noModule' in script) {
+ script.type = 'module';
+ scriptRoute = scriptRoute.replace(/\.js$/, '.module.js');
+ }
- if (isPage) url = url.replace(/\.js$/, '.module.js');
- }
+ const url = _this.assetPrefix + "/_next/static/" + encodeURIComponent(_this.buildId) + "/pages" + scriptRoute;
+ script.crossOrigin = "anonymous";
+ script.src = url;
- script.crossOrigin = "anonymous";
- script.src = url;
+ script.onerror = () => {
+ const error = new Error("Error loading script " + url);
+ error.code = 'PAGE_LOAD_ERROR';
- script.onerror = () => {
- const error = new Error("Error loading script " + url);
- error.code = 'PAGE_LOAD_ERROR';
- this.pageRegisterEvents.emit(route, {
- error
- });
- };
+ _this.pageRegisterEvents.emit(route, {
+ error
+ });
+ };
- document.body.appendChild(script);
+ document.body.appendChild(script);
+ })();
} // This method if called by the route code.
@@ -1023,11 +1069,10 @@ class PageLoader {
register();
}
- prefetch(route, isDependency) {
+ prefetch(route) {
var _this2 = this;
return (0, _asyncToGenerator2.default)(function* () {
- yield _this2.promisedBuildId;
route = _this2.normalizeRoute(route);
let scriptRoute = (route === '/' ? '/index' : route) + ".js";
@@ -1035,12 +1080,11 @@ class PageLoader {
scriptRoute = scriptRoute.replace(/\.js$/, '.module.js');
}
- const url = isDependency ? route : _this2.assetPrefix + "/_next/static/" + encodeURIComponent(_this2.buildId) + "/pages" + scriptRoute; // n.b. If preload is not supported, we fall back to `loadPage` which has
- // its own deduping mechanism.
-
- if (document.querySelector("link[rel=\"preload\"][href^=\"" + url + "\"]") || document.getElementById("__NEXT_PAGE__" + route)) {
+ if (_this2.prefetchCache.has(scriptRoute) || document.getElementById("__NEXT_PAGE__" + route)) {
return;
- } // Inspired by quicklink, license: https://github.com/GoogleChromeLabs/quicklink/blob/master/LICENSE
+ }
+
+ _this2.prefetchCache.add(scriptRoute); // Inspired by quicklink, license: https://github.com/GoogleChromeLabs/quicklink/blob/master/LICENSE
let cn;
@@ -1050,21 +1094,14 @@ class PageLoader {
if ((cn.effectiveType || '').indexOf('2g') !== -1 || cn.saveData) {
return;
}
- }
-
- if (false) {} // Feature detection is used to see if preload is supported
+ } // Feature detection is used to see if preload is supported
// If not fall back to loading script tags before the page is loaded
// https://caniuse.com/#feat=link-rel-preload
if (hasPreload) {
- preloadScript(url);
- return;
- }
-
- if (isDependency) {
- // loadPage will automatically handle depencies, so no need to
- // preload them manually
+ yield _this2.promisedBuildId;
+ preloadScript(_this2.assetPrefix + "/_next/static/" + encodeURIComponent(_this2.buildId) + "/pages" + scriptRoute);
return;
}
Diff for commonsModern.js@@ -3007,24 +3007,33 @@ class Router {
} = this.components['/_app'];
let props;
- if (Component.__NEXT_PRERENDER) {
- const url = url_1.format({
- pathname: ctx.asPath,
+ if (Component.__NEXT_SPR) {
+ let status;
+ const url = ctx.asPath ? ctx.asPath : url_1.format({
+ pathname: ctx.pathname,
query: ctx.query
});
- const res = await fetch(url, {
+ props = await fetch(url, {
headers: {
'content-type': 'application/json'
}
- });
- props = {
- pageProps: res.ok ? await res.json().catch(err => ({
- error: err.message
- })) : {
- error: 'failed to load prerender',
- statusCode: res.status
+ }).then(res => {
+ if (!res.ok) {
+ status = res.status;
+ throw new Error('failed to load prerender data');
}
- };
+
+ return res.json();
+ }).then(pageProps => {
+ return {
+ pageProps
+ };
+ }).catch(err => {
+ return {
+ error: err.message,
+ status
+ };
+ });
} else {
props = await utils_1.loadGetInitialProps(App, {
AppTree: this._wrapApp(App),
|
Member
Author
Stats from current PRClick to expand stats ✅ Total Bundle Size Decrease ✅
Click to expand serverless stats ✅ Total Bundle Size Decrease ✅
Diff for main.js@@ -418,7 +418,7 @@ function (_react$default$Compon) {
this.scrollToHash(); // If page was exported and has a querystring
// If it's a dynamic route or has a querystring
- if (data.nextExport && ((0, _isDynamic.isDynamicRoute)(router.pathname) || location.search)) {
+ if (data.nextExport && ((0, _isDynamic.isDynamicRoute)(router.pathname) || location.search || data.skeleton)) {
// update query on mount for exported pages
router.replace(router.pathname + '?' + (0, _querystring.stringify)((0, _extends2["default"])({}, router.query, (0, _querystring.parse)(location.search.substr(1)))), asPath, {
// WARNING: `_h` is an internal option for handing Next.js
@@ -466,7 +466,7 @@ function () {
var _ref2 = (0, _asyncToGenerator2["default"])(
/*#__PURE__*/
_regenerator["default"].mark(function _callee(_temp) {
- var _ref, passedWebpackHMR, initialErr, _require, isValidElementType, renderCtx, appCtx;
+ var _ref, passedWebpackHMR, initialErr, _require, isValidElementType, renderCtx;
return _regenerator["default"].wrap(function _callee$(_context) {
while (1) {
@@ -555,33 +555,9 @@ function () {
emitter: emitter
};
render(renderCtx);
-
- if (!(window.__NEXT_DATA__.skeleton && Component.getInitialProps)) {
- _context.next = 32;
- break;
- }
-
- appCtx = {
- router: router,
- AppTree: wrapApp(App),
- Component: Component,
- ctx: {
- pathname: page,
- asPath: asPath,
- query: query
- }
- };
- _context.next = 30;
- return App.getInitialProps(appCtx);
-
- case 30:
- props.pageProps = _context.sent.pageProps;
- render(renderCtx);
-
- case 32:
return _context.abrupt("return", emitter);
- case 33:
+ case 27:
case "end":
return _context.stop();
}
Diff for commons.js@@ -3585,7 +3585,7 @@ function () {
var _getInitialProps = (0, _asyncToGenerator2["default"])(
/*#__PURE__*/
_regenerator["default"].mark(function _callee2(Component, ctx) {
- var cancelled, cancel, App, props, url, res, err;
+ var cancelled, cancel, App, props, status, url, err;
return _regenerator["default"].wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
@@ -3599,13 +3599,13 @@ function () {
this.clc = cancel;
App = this.components['/_app'].Component;
- if (!Component.__NEXT_PRERENDER) {
- _context2.next = 20;
+ if (!Component.__NEXT_SPR) {
+ _context2.next = 11;
break;
}
- url = url_1.format({
- pathname: ctx.asPath,
+ url = ctx.asPath ? ctx.asPath : url_1.format({
+ pathname: ctx.pathname,
query: ctx.query
});
_context2.next = 8;
@@ -3613,44 +3613,31 @@ function () {
headers: {
'content-type': 'application/json'
}
- });
-
- case 8:
- res = _context2.sent;
-
- if (!res.ok) {
- _context2.next = 15;
- break;
- }
+ }).then(function (res) {
+ if (!res.ok) {
+ status = res.status;
+ throw new Error('failed to load prerender data');
+ }
- _context2.next = 12;
- return res.json()["catch"](function (err) {
+ return res.json();
+ }).then(function (pageProps) {
return {
- error: err.message
+ pageProps: pageProps
+ };
+ })["catch"](function (err) {
+ return {
+ error: err.message,
+ status: status
};
});
- case 12:
- _context2.t0 = _context2.sent;
- _context2.next = 16;
- break;
-
- case 15:
- _context2.t0 = {
- error: 'failed to load prerender',
- statusCode: res.status
- };
-
- case 16:
- _context2.t1 = _context2.t0;
- props = {
- pageProps: _context2.t1
- };
- _context2.next = 23;
+ case 8:
+ props = _context2.sent;
+ _context2.next = 14;
break;
- case 20:
- _context2.next = 22;
+ case 11:
+ _context2.next = 13;
return utils_1.loadGetInitialProps(App, {
AppTree: this._wrapApp(App),
Component: Component,
@@ -3658,16 +3645,16 @@ function () {
ctx: ctx
});
- case 22:
+ case 13:
props = _context2.sent;
- case 23:
+ case 14:
if (cancel === this.clc) {
this.clc = null;
}
if (!cancelled) {
- _context2.next = 28;
+ _context2.next = 19;
break;
}
@@ -3675,10 +3662,10 @@ function () {
err.cancelled = true;
throw err;
- case 28:
+ case 19:
return _context2.abrupt("return", props);
- case 29:
+ case 20:
case "end":
return _context2.stop();
}
Diff for mainModern.js@@ -369,7 +369,7 @@ class Container extends _react.default.Component {
this.scrollToHash(); // If page was exported and has a querystring
// If it's a dynamic route or has a querystring
- if (data.nextExport && ((0, _isDynamic.isDynamicRoute)(router.pathname) || location.search)) {
+ if (data.nextExport && ((0, _isDynamic.isDynamicRoute)(router.pathname) || location.search || data.skeleton)) {
// update query on mount for exported pages
router.replace(router.pathname + '?' + (0, _querystring.stringify)((0, _extends2.default)({}, router.query, (0, _querystring.parse)(location.search.substr(1)))), asPath, {
// WARNING: `_h` is an internal option for handing Next.js
@@ -466,22 +466,6 @@ function () {
emitter
};
render(renderCtx);
-
- if (window.__NEXT_DATA__.skeleton && Component.getInitialProps) {
- const appCtx = {
- router,
- AppTree: wrapApp(App),
- Component: Component,
- ctx: {
- pathname: page,
- asPath,
- query
- }
- };
- props.pageProps = (yield App.getInitialProps(appCtx)).pageProps;
- render(renderCtx);
- }
-
return emitter;
});
Diff for commonsModern.js@@ -3016,24 +3016,33 @@ class Router {
} = this.components['/_app'];
let props;
- if (Component.__NEXT_PRERENDER) {
- const url = url_1.format({
- pathname: ctx.asPath,
+ if (Component.__NEXT_SPR) {
+ let status;
+ const url = ctx.asPath ? ctx.asPath : url_1.format({
+ pathname: ctx.pathname,
query: ctx.query
});
- const res = await fetch(url, {
+ props = await fetch(url, {
headers: {
'content-type': 'application/json'
}
- });
- props = {
- pageProps: res.ok ? await res.json().catch(err => ({
- error: err.message
- })) : {
- error: 'failed to load prerender',
- statusCode: res.status
+ }).then(res => {
+ if (!res.ok) {
+ status = res.status;
+ throw new Error('failed to load prerender data');
}
- };
+
+ return res.json();
+ }).then(pageProps => {
+ return {
+ pageProps
+ };
+ }).catch(err => {
+ return {
+ error: err.message,
+ status
+ };
+ });
} else {
props = await utils_1.loadGetInitialProps(App, {
AppTree: this._wrapApp(App),
|
Member
Author
Stats from current PRClick to expand stats ✅ Total Bundle Size Decrease ✅
Click to expand serverless stats ✅ Total Bundle Size Decrease ✅
Diff for main.js@@ -418,7 +418,7 @@ function (_react$default$Compon) {
this.scrollToHash(); // If page was exported and has a querystring
// If it's a dynamic route or has a querystring
- if (data.nextExport && ((0, _isDynamic.isDynamicRoute)(router.pathname) || location.search)) {
+ if (data.nextExport && ((0, _isDynamic.isDynamicRoute)(router.pathname) || location.search || data.skeleton)) {
// update query on mount for exported pages
router.replace(router.pathname + '?' + (0, _querystring.stringify)((0, _extends2["default"])({}, router.query, (0, _querystring.parse)(location.search.substr(1)))), asPath, {
// WARNING: `_h` is an internal option for handing Next.js
@@ -466,7 +466,7 @@ function () {
var _ref2 = (0, _asyncToGenerator2["default"])(
/*#__PURE__*/
_regenerator["default"].mark(function _callee(_temp) {
- var _ref, passedWebpackHMR, initialErr, _require, isValidElementType, renderCtx, appCtx;
+ var _ref, passedWebpackHMR, initialErr, _require, isValidElementType, renderCtx;
return _regenerator["default"].wrap(function _callee$(_context) {
while (1) {
@@ -553,33 +553,9 @@ function () {
emitter: emitter
};
render(renderCtx);
-
- if (!(window.__NEXT_DATA__.skeleton && Component.getInitialProps)) {
- _context.next = 32;
- break;
- }
-
- appCtx = {
- router: router,
- AppTree: wrapApp(App),
- Component: Component,
- ctx: {
- pathname: page,
- asPath: asPath,
- query: query
- }
- };
- _context.next = 30;
- return App.getInitialProps(appCtx);
-
- case 30:
- props.pageProps = _context.sent.pageProps;
- render(renderCtx);
-
- case 32:
return _context.abrupt("return", emitter);
- case 33:
+ case 27:
case "end":
return _context.stop();
}
Diff for commons.js@@ -3586,7 +3586,7 @@ function () {
var _getInitialProps = (0, _asyncToGenerator2["default"])(
/*#__PURE__*/
_regenerator["default"].mark(function _callee2(Component, ctx) {
- var cancelled, cancel, App, props, url, res, err;
+ var cancelled, cancel, App, props, status, url, err;
return _regenerator["default"].wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
@@ -3600,13 +3600,13 @@ function () {
this.clc = cancel;
App = this.components['/_app'].Component;
- if (!Component.__NEXT_PRERENDER) {
- _context2.next = 20;
+ if (!Component.__NEXT_SPR) {
+ _context2.next = 11;
break;
}
- url = url_1.format({
- pathname: ctx.asPath,
+ url = ctx.asPath ? ctx.asPath : url_1.format({
+ pathname: ctx.pathname,
query: ctx.query
});
_context2.next = 8;
@@ -3614,44 +3614,31 @@ function () {
headers: {
'content-type': 'application/json'
}
- });
-
- case 8:
- res = _context2.sent;
-
- if (!res.ok) {
- _context2.next = 15;
- break;
- }
+ }).then(function (res) {
+ if (!res.ok) {
+ status = res.status;
+ throw new Error('failed to load prerender data');
+ }
- _context2.next = 12;
- return res.json()["catch"](function (err) {
+ return res.json();
+ }).then(function (pageProps) {
return {
- error: err.message
+ pageProps: pageProps
+ };
+ })["catch"](function (err) {
+ return {
+ error: err.message,
+ status: status
};
});
- case 12:
- _context2.t0 = _context2.sent;
- _context2.next = 16;
- break;
-
- case 15:
- _context2.t0 = {
- error: 'failed to load prerender',
- statusCode: res.status
- };
-
- case 16:
- _context2.t1 = _context2.t0;
- props = {
- pageProps: _context2.t1
- };
- _context2.next = 23;
+ case 8:
+ props = _context2.sent;
+ _context2.next = 14;
break;
- case 20:
- _context2.next = 22;
+ case 11:
+ _context2.next = 13;
return utils_1.loadGetInitialProps(App, {
AppTree: this._wrapApp(App),
Component: Component,
@@ -3659,16 +3646,16 @@ function () {
ctx: ctx
});
- case 22:
+ case 13:
props = _context2.sent;
- case 23:
+ case 14:
if (cancel === this.clc) {
this.clc = null;
}
if (!cancelled) {
- _context2.next = 28;
+ _context2.next = 19;
break;
}
@@ -3676,10 +3663,10 @@ function () {
err.cancelled = true;
throw err;
- case 28:
+ case 19:
return _context2.abrupt("return", props);
- case 29:
+ case 20:
case "end":
return _context2.stop();
}
Diff for mainModern.js@@ -369,7 +369,7 @@ class Container extends _react.default.Component {
this.scrollToHash(); // If page was exported and has a querystring
// If it's a dynamic route or has a querystring
- if (data.nextExport && ((0, _isDynamic.isDynamicRoute)(router.pathname) || location.search)) {
+ if (data.nextExport && ((0, _isDynamic.isDynamicRoute)(router.pathname) || location.search || data.skeleton)) {
// update query on mount for exported pages
router.replace(router.pathname + '?' + (0, _querystring.stringify)((0, _extends2.default)({}, router.query, (0, _querystring.parse)(location.search.substr(1)))), asPath, {
// WARNING: `_h` is an internal option for handing Next.js
@@ -464,22 +464,6 @@ function () {
emitter
};
render(renderCtx);
-
- if (window.__NEXT_DATA__.skeleton && Component.getInitialProps) {
- const appCtx = {
- router,
- AppTree: wrapApp(App),
- Component: Component,
- ctx: {
- pathname: page,
- asPath,
- query
- }
- };
- props.pageProps = (yield App.getInitialProps(appCtx)).pageProps;
- render(renderCtx);
- }
-
return emitter;
});
Diff for commonsModern.js@@ -3017,24 +3017,33 @@ class Router {
} = this.components['/_app'];
let props;
- if (Component.__NEXT_PRERENDER) {
- const url = url_1.format({
- pathname: ctx.asPath,
+ if (Component.__NEXT_SPR) {
+ let status;
+ const url = ctx.asPath ? ctx.asPath : url_1.format({
+ pathname: ctx.pathname,
query: ctx.query
});
- const res = await fetch(url, {
+ props = await fetch(url, {
headers: {
'content-type': 'application/json'
}
- });
- props = {
- pageProps: res.ok ? await res.json().catch(err => ({
- error: err.message
- })) : {
- error: 'failed to load prerender',
- statusCode: res.status
+ }).then(res => {
+ if (!res.ok) {
+ status = res.status;
+ throw new Error('failed to load prerender data');
}
- };
+
+ return res.json();
+ }).then(pageProps => {
+ return {
+ pageProps
+ };
+ }).catch(err => {
+ return {
+ error: err.message,
+ status
+ };
+ });
} else {
props = await utils_1.loadGetInitialProps(App, {
AppTree: this._wrapApp(App),
|
Timer
requested changes
Aug 11, 2019
packages/next/build/webpack/plugins/terser-webpack-plugin/src/index.js
Outdated
Show resolved
Hide resolved
Member
Author
Stats from current PRClick to expand stats ✅ Total Bundle Size Decrease ✅
Click to expand serverless stats ✅ Total Bundle Size Decrease ✅
Diff for main.js@@ -418,7 +418,7 @@ function (_react$default$Compon) {
this.scrollToHash(); // If page was exported and has a querystring
// If it's a dynamic route or has a querystring
- if (data.nextExport && ((0, _isDynamic.isDynamicRoute)(router.pathname) || location.search)) {
+ if (data.nextExport && ((0, _isDynamic.isDynamicRoute)(router.pathname) || location.search || data.skeleton)) {
// update query on mount for exported pages
router.replace(router.pathname + '?' + (0, _querystring.stringify)((0, _extends2["default"])({}, router.query, (0, _querystring.parse)(location.search.substr(1)))), asPath, {
// WARNING: `_h` is an internal option for handing Next.js
@@ -466,7 +466,7 @@ function () {
var _ref2 = (0, _asyncToGenerator2["default"])(
/*#__PURE__*/
_regenerator["default"].mark(function _callee(_temp) {
- var _ref, passedWebpackHMR, initialErr, _require, isValidElementType, renderCtx, appCtx;
+ var _ref, passedWebpackHMR, initialErr, _require, isValidElementType, renderCtx;
return _regenerator["default"].wrap(function _callee$(_context) {
while (1) {
@@ -553,33 +553,9 @@ function () {
emitter: emitter
};
render(renderCtx);
-
- if (!(window.__NEXT_DATA__.skeleton && Component.getInitialProps)) {
- _context.next = 32;
- break;
- }
-
- appCtx = {
- router: router,
- AppTree: wrapApp(App),
- Component: Component,
- ctx: {
- pathname: page,
- asPath: asPath,
- query: query
- }
- };
- _context.next = 30;
- return App.getInitialProps(appCtx);
-
- case 30:
- props.pageProps = _context.sent.pageProps;
- render(renderCtx);
-
- case 32:
return _context.abrupt("return", emitter);
- case 33:
+ case 27:
case "end":
return _context.stop();
}
Diff for commons.js@@ -3586,7 +3586,7 @@ function () {
var _getInitialProps = (0, _asyncToGenerator2["default"])(
/*#__PURE__*/
_regenerator["default"].mark(function _callee2(Component, ctx) {
- var cancelled, cancel, App, props, url, res, err;
+ var cancelled, cancel, App, props, status, url, err;
return _regenerator["default"].wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
@@ -3600,13 +3600,14 @@ function () {
this.clc = cancel;
App = this.components['/_app'].Component;
- if (!Component.__NEXT_PRERENDER) {
- _context2.next = 20;
+ if (!( // @ts-ignore workaround for dead-code elimination
+ (self.__HAS_SPR || "production" !== 'production') && Component.__NEXT_SPR)) {
+ _context2.next = 11;
break;
}
- url = url_1.format({
- pathname: ctx.asPath,
+ url = ctx.asPath ? ctx.asPath : url_1.format({
+ pathname: ctx.pathname,
query: ctx.query
});
_context2.next = 8;
@@ -3614,44 +3615,31 @@ function () {
headers: {
'content-type': 'application/json'
}
- });
-
- case 8:
- res = _context2.sent;
-
- if (!res.ok) {
- _context2.next = 15;
- break;
- }
+ }).then(function (res) {
+ if (!res.ok) {
+ status = res.status;
+ throw new Error('failed to load prerender data');
+ }
- _context2.next = 12;
- return res.json()["catch"](function (err) {
+ return res.json();
+ }).then(function (pageProps) {
return {
- error: err.message
+ pageProps: pageProps
+ };
+ })["catch"](function (err) {
+ return {
+ error: err.message,
+ status: status
};
});
- case 12:
- _context2.t0 = _context2.sent;
- _context2.next = 16;
- break;
-
- case 15:
- _context2.t0 = {
- error: 'failed to load prerender',
- statusCode: res.status
- };
-
- case 16:
- _context2.t1 = _context2.t0;
- props = {
- pageProps: _context2.t1
- };
- _context2.next = 23;
+ case 8:
+ props = _context2.sent;
+ _context2.next = 14;
break;
- case 20:
- _context2.next = 22;
+ case 11:
+ _context2.next = 13;
return utils_1.loadGetInitialProps(App, {
AppTree: this._wrapApp(App),
Component: Component,
@@ -3659,16 +3647,16 @@ function () {
ctx: ctx
});
- case 22:
+ case 13:
props = _context2.sent;
- case 23:
+ case 14:
if (cancel === this.clc) {
this.clc = null;
}
if (!cancelled) {
- _context2.next = 28;
+ _context2.next = 19;
break;
}
@@ -3676,10 +3664,10 @@ function () {
err.cancelled = true;
throw err;
- case 28:
+ case 19:
return _context2.abrupt("return", props);
- case 29:
+ case 20:
case "end":
return _context2.stop();
}
Diff for mainModern.js@@ -369,7 +369,7 @@ class Container extends _react.default.Component {
this.scrollToHash(); // If page was exported and has a querystring
// If it's a dynamic route or has a querystring
- if (data.nextExport && ((0, _isDynamic.isDynamicRoute)(router.pathname) || location.search)) {
+ if (data.nextExport && ((0, _isDynamic.isDynamicRoute)(router.pathname) || location.search || data.skeleton)) {
// update query on mount for exported pages
router.replace(router.pathname + '?' + (0, _querystring.stringify)((0, _extends2.default)({}, router.query, (0, _querystring.parse)(location.search.substr(1)))), asPath, {
// WARNING: `_h` is an internal option for handing Next.js
@@ -464,22 +464,6 @@ function () {
emitter
};
render(renderCtx);
-
- if (window.__NEXT_DATA__.skeleton && Component.getInitialProps) {
- const appCtx = {
- router,
- AppTree: wrapApp(App),
- Component: Component,
- ctx: {
- pathname: page,
- asPath,
- query
- }
- };
- props.pageProps = (yield App.getInitialProps(appCtx)).pageProps;
- render(renderCtx);
- }
-
return emitter;
});
Diff for commonsModern.js@@ -3017,24 +3017,34 @@ class Router {
} = this.components['/_app'];
let props;
- if (Component.__NEXT_PRERENDER) {
- const url = url_1.format({
- pathname: ctx.asPath,
+ if ( // @ts-ignore workaround for dead-code elimination
+ (self.__HAS_SPR || "production" !== 'production') && Component.__NEXT_SPR) {
+ let status;
+ const url = ctx.asPath ? ctx.asPath : url_1.format({
+ pathname: ctx.pathname,
query: ctx.query
});
- const res = await fetch(url, {
+ props = await fetch(url, {
headers: {
'content-type': 'application/json'
}
- });
- props = {
- pageProps: res.ok ? await res.json().catch(err => ({
- error: err.message
- })) : {
- error: 'failed to load prerender',
- statusCode: res.status
+ }).then(res => {
+ if (!res.ok) {
+ status = res.status;
+ throw new Error('failed to load prerender data');
}
- };
+
+ return res.json();
+ }).then(pageProps => {
+ return {
+ pageProps
+ };
+ }).catch(err => {
+ return {
+ error: err.message,
+ status
+ };
+ });
} else {
props = await utils_1.loadGetInitialProps(App, {
AppTree: this._wrapApp(App),
|
Member
Author
Stats from current PRClick to expand stats ✅ Total Bundle Size Decrease ✅
Click to expand serverless stats ✅ Total Bundle Size Decrease ✅
Diff for main.js@@ -418,7 +418,7 @@ function (_react$default$Compon) {
this.scrollToHash(); // If page was exported and has a querystring
// If it's a dynamic route or has a querystring
- if (data.nextExport && ((0, _isDynamic.isDynamicRoute)(router.pathname) || location.search)) {
+ if (data.nextExport && ((0, _isDynamic.isDynamicRoute)(router.pathname) || location.search || data.skeleton)) {
// update query on mount for exported pages
router.replace(router.pathname + '?' + (0, _querystring.stringify)((0, _extends2["default"])({}, router.query, (0, _querystring.parse)(location.search.substr(1)))), asPath, {
// WARNING: `_h` is an internal option for handing Next.js
@@ -466,7 +466,7 @@ function () {
var _ref2 = (0, _asyncToGenerator2["default"])(
/*#__PURE__*/
_regenerator["default"].mark(function _callee(_temp) {
- var _ref, passedWebpackHMR, initialErr, _require, isValidElementType, renderCtx, appCtx;
+ var _ref, passedWebpackHMR, initialErr, _require, isValidElementType, renderCtx;
return _regenerator["default"].wrap(function _callee$(_context) {
while (1) {
@@ -553,33 +553,9 @@ function () {
emitter: emitter
};
render(renderCtx);
-
- if (!(window.__NEXT_DATA__.skeleton && Component.getInitialProps)) {
- _context.next = 32;
- break;
- }
-
- appCtx = {
- router: router,
- AppTree: wrapApp(App),
- Component: Component,
- ctx: {
- pathname: page,
- asPath: asPath,
- query: query
- }
- };
- _context.next = 30;
- return App.getInitialProps(appCtx);
-
- case 30:
- props.pageProps = _context.sent.pageProps;
- render(renderCtx);
-
- case 32:
return _context.abrupt("return", emitter);
- case 33:
+ case 27:
case "end":
return _context.stop();
}
Diff for commons.js@@ -3586,7 +3586,7 @@ function () {
var _getInitialProps = (0, _asyncToGenerator2["default"])(
/*#__PURE__*/
_regenerator["default"].mark(function _callee2(Component, ctx) {
- var cancelled, cancel, App, props, url, res, err;
+ var cancelled, cancel, App, props, status, url, err;
return _regenerator["default"].wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
@@ -3600,13 +3600,14 @@ function () {
this.clc = cancel;
App = this.components['/_app'].Component;
- if (!Component.__NEXT_PRERENDER) {
- _context2.next = 20;
+ if (!( // @ts-ignore workaround for dead-code elimination
+ (self.__HAS_SPR || "production" !== 'production') && Component.__NEXT_SPR)) {
+ _context2.next = 11;
break;
}
- url = url_1.format({
- pathname: ctx.asPath,
+ url = ctx.asPath ? ctx.asPath : url_1.format({
+ pathname: ctx.pathname,
query: ctx.query
});
_context2.next = 8;
@@ -3614,44 +3615,31 @@ function () {
headers: {
'content-type': 'application/json'
}
- });
-
- case 8:
- res = _context2.sent;
-
- if (!res.ok) {
- _context2.next = 15;
- break;
- }
+ }).then(function (res) {
+ if (!res.ok) {
+ status = res.status;
+ throw new Error('failed to load prerender data');
+ }
- _context2.next = 12;
- return res.json()["catch"](function (err) {
+ return res.json();
+ }).then(function (pageProps) {
return {
- error: err.message
+ pageProps: pageProps
+ };
+ })["catch"](function (err) {
+ return {
+ error: err.message,
+ status: status
};
});
- case 12:
- _context2.t0 = _context2.sent;
- _context2.next = 16;
- break;
-
- case 15:
- _context2.t0 = {
- error: 'failed to load prerender',
- statusCode: res.status
- };
-
- case 16:
- _context2.t1 = _context2.t0;
- props = {
- pageProps: _context2.t1
- };
- _context2.next = 23;
+ case 8:
+ props = _context2.sent;
+ _context2.next = 14;
break;
- case 20:
- _context2.next = 22;
+ case 11:
+ _context2.next = 13;
return utils_1.loadGetInitialProps(App, {
AppTree: this._wrapApp(App),
Component: Component,
@@ -3659,16 +3647,16 @@ function () {
ctx: ctx
});
- case 22:
+ case 13:
props = _context2.sent;
- case 23:
+ case 14:
if (cancel === this.clc) {
this.clc = null;
}
if (!cancelled) {
- _context2.next = 28;
+ _context2.next = 19;
break;
}
@@ -3676,10 +3664,10 @@ function () {
err.cancelled = true;
throw err;
- case 28:
+ case 19:
return _context2.abrupt("return", props);
- case 29:
+ case 20:
case "end":
return _context2.stop();
}
Diff for mainModern.js@@ -369,7 +369,7 @@ class Container extends _react.default.Component {
this.scrollToHash(); // If page was exported and has a querystring
// If it's a dynamic route or has a querystring
- if (data.nextExport && ((0, _isDynamic.isDynamicRoute)(router.pathname) || location.search)) {
+ if (data.nextExport && ((0, _isDynamic.isDynamicRoute)(router.pathname) || location.search || data.skeleton)) {
// update query on mount for exported pages
router.replace(router.pathname + '?' + (0, _querystring.stringify)((0, _extends2.default)({}, router.query, (0, _querystring.parse)(location.search.substr(1)))), asPath, {
// WARNING: `_h` is an internal option for handing Next.js
@@ -464,22 +464,6 @@ function () {
emitter
};
render(renderCtx);
-
- if (window.__NEXT_DATA__.skeleton && Component.getInitialProps) {
- const appCtx = {
- router,
- AppTree: wrapApp(App),
- Component: Component,
- ctx: {
- pathname: page,
- asPath,
- query
- }
- };
- props.pageProps = (yield App.getInitialProps(appCtx)).pageProps;
- render(renderCtx);
- }
-
return emitter;
});
Diff for commonsModern.js@@ -3017,24 +3017,34 @@ class Router {
} = this.components['/_app'];
let props;
- if (Component.__NEXT_PRERENDER) {
- const url = url_1.format({
- pathname: ctx.asPath,
+ if ( // @ts-ignore workaround for dead-code elimination
+ (self.__HAS_SPR || "production" !== 'production') && Component.__NEXT_SPR) {
+ let status;
+ const url = ctx.asPath ? ctx.asPath : url_1.format({
+ pathname: ctx.pathname,
query: ctx.query
});
- const res = await fetch(url, {
+ props = await fetch(url, {
headers: {
'content-type': 'application/json'
}
- });
- props = {
- pageProps: res.ok ? await res.json().catch(err => ({
- error: err.message
- })) : {
- error: 'failed to load prerender',
- statusCode: res.status
+ }).then(res => {
+ if (!res.ok) {
+ status = res.status;
+ throw new Error('failed to load prerender data');
}
- };
+
+ return res.json();
+ }).then(pageProps => {
+ return {
+ pageProps
+ };
+ }).catch(err => {
+ return {
+ error: err.message,
+ status
+ };
+ });
} else {
props = await utils_1.loadGetInitialProps(App, {
AppTree: this._wrapApp(App),
|
Timer
approved these changes
Aug 12, 2019
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds checking if page is hybrid AMP to static checking, going to server for skeleton
getInitialPropscall, and removing of SPR code when not used at allCloses: #8267
Closes: #8265
Closes: #8264
x-ref: #7983