Skip to content

Conversation

@ijjk
Copy link
Member

@ijjk ijjk commented Aug 8, 2019

Adds checking if page is hybrid AMP to static checking, going to server for skeleton getInitialProps call, and removing of SPR code when not used at all

Closes: #8267
Closes: #8265
Closes: #8264

x-ref: #7983

@ijjk
Copy link
Member Author

ijjk commented Aug 8, 2019

Stats from current PR

Click to expand stats ✅ Total Bundle Size Decrease ✅
zeit/next.js canary ijjk/next.js prerender-followup Change
Build Duration 20.6s 20.4s -199ms
node_modules Size 43.6 MB 43.6 MB -11.4 kB
Total Bundle (main, webpack, commons) Size 206 kB 206 kB -404 B
Total Bundle (main, webpack, commons) gzip Size 68.2 kB 67.9 kB -284 B
Total Bundle (main, webpack, commons) Modern Size 181 kB 181 kB -24 B
Total Bundle (main, webpack, commons) Modern gzip Size 59.9 kB 59.7 kB -135 B
Client _app Size 2.39 kB 2.39 kB
Client _app gzip Size 1.08 kB 1.08 kB
Client _app Modern Size 1.83 kB 1.83 kB
Client _app gzip Modern Size 890 B 890 B
Client _error Size 8.22 kB 8.22 kB
Client _error gzip Size 3.16 kB 3.16 kB
Client _error Modern Size 5.85 kB 5.85 kB
Client _error gzip Modern Size 2.33 kB 2.33 kB
Client pages/index Size 343 B 343 B
Client pages/index gzip Size 246 B 246 B
Client pages/index Modern Size 319 B 319 B
Client pages/index gzip Modern Size 254 B 254 B
Client pages/link Size 4.08 kB 4.08 kB
Client pages/link gzip Size 1.8 kB 1.8 kB
Client pages/link Modern Size 3.7 kB 3.7 kB
Client pages/link gzip Modern Size 1.7 kB 1.7 kB
Client pages/routerDirect Size 423 B 423 B
Client pages/routerDirect gzip Size 306 B 306 B
Client pages/routerDirect Modern Size 411 B 411 B
Client pages/routerDirect gzip Modern Size 314 B 314 B
Client pages/withRouter Size 435 B 435 B
Client pages/withRouter gzip Size 301 B 301 B
Client pages/withRouter Modern Size 423 B 423 B
Client pages/withRouter gzip Modern Size 309 B 309 B
Client main Size 15.6 kB 15.6 kB -22 B
Client main gzip Size 5.5 kB 5.4 kB -94 B
Client main Modern Size 12.4 kB 12.7 kB ⚠️ +238 B
Client main Modern gzip Size 4.78 kB 4.78 kB -3 B
Client commons Size 188 kB 188 kB -382 B
Client commons gzip Size 61.3 kB 61.1 kB -190 B
Client commons Modern Size 169 kB 168 kB -262 B
Client commons Modern gzip Size 55.1 kB 54.9 kB -132 B
Client webpack Size 1.53 kB 1.53 kB
Client webpack gzip Size 778 B 778 B
Client webpack Modern Size 1.53 kB 1.53 kB
Client webpack Modern gzip Size 785 B 785 B
Base Rendered Size 2.76 kB 2.76 kB
Build Dir Size 1.39 MB 1.39 MB -5.37 kB
Click to expand serverless stats ✅ Total Bundle Size Decrease ✅
zeit/next.js canary ijjk/next.js prerender-followup Change
Build Duration 21.3s 21.8s ⚠️ +535ms
node_modules Size 43.6 MB 43.6 MB -11.4 kB
Total Bundle (main, webpack, commons) Size 206 kB 206 kB -404 B
Total Bundle (main, webpack, commons) gzip Size 68.2 kB 67.9 kB -284 B
Total Bundle (main, webpack, commons) Modern Size 181 kB 181 kB -24 B
Total Bundle (main, webpack, commons) Modern gzip Size 59.9 kB 59.7 kB -135 B
Client _app Size 2.39 kB 2.39 kB
Client _app gzip Size 1.08 kB 1.08 kB
Client _app Modern Size 1.83 kB 1.83 kB
Client _app gzip Modern Size 890 B 890 B
Client _error Size 8.22 kB 8.22 kB
Client _error gzip Size 3.16 kB 3.16 kB
Client _error Modern Size 5.85 kB 5.85 kB
Client _error gzip Modern Size 2.33 kB 2.33 kB
Client pages/index Size 343 B 343 B
Client pages/index gzip Size 246 B 246 B
Client pages/index Modern Size 319 B 319 B
Client pages/index gzip Modern Size 254 B 254 B
Client pages/link Size 4.08 kB 4.08 kB
Client pages/link gzip Size 1.8 kB 1.8 kB
Client pages/link Modern Size 3.7 kB 3.7 kB
Client pages/link gzip Modern Size 1.7 kB 1.7 kB
Client pages/routerDirect Size 423 B 423 B
Client pages/routerDirect gzip Size 306 B 306 B
Client pages/routerDirect Modern Size 411 B 411 B
Client pages/routerDirect gzip Modern Size 314 B 314 B
Client pages/withRouter Size 435 B 435 B
Client pages/withRouter gzip Size 301 B 301 B
Client pages/withRouter Modern Size 423 B 423 B
Client pages/withRouter gzip Modern Size 309 B 309 B
Client main Size 15.6 kB 15.6 kB -22 B
Client main gzip Size 5.5 kB 5.4 kB -94 B
Client main Modern Size 12.4 kB 12.7 kB ⚠️ +238 B
Client main Modern gzip Size 4.78 kB 4.78 kB -3 B
Client commons Size 188 kB 188 kB -382 B
Client commons gzip Size 61.3 kB 61.1 kB -190 B
Client commons Modern Size 169 kB 168 kB -262 B
Client commons Modern gzip Size 55.1 kB 54.9 kB -132 B
Client webpack Size 1.53 kB 1.53 kB
Client webpack gzip Size 778 B 778 B
Client webpack Modern Size 1.53 kB 1.53 kB
Client webpack Modern gzip Size 785 B 785 B
Serverless pages/link Size 255 kB 255 kB ⚠️ +347 B
Serverless pages/link gzip Size 68.6 kB 68.6 kB ⚠️ +55 B
Serverless pages/index Size 248 kB 248 kB ⚠️ +347 B
Serverless pages/index gzip Size 66.4 kB 66.4 kB ⚠️ +55 B
Serverless pages/_error Size 247 kB 247 kB ⚠️ +347 B
Serverless pages/_error gzip Size 66.1 kB 66.2 kB ⚠️ +55 B
Serverless pages/routerDirect Size 248 kB 249 kB ⚠️ +347 B
Serverless pages/routerDirect gzip Size 66.3 kB 66.4 kB ⚠️ +55 B
Serverless pages/withRouter Size 248 kB 249 kB ⚠️ +347 B
Serverless pages/withRouter gzip Size 66.4 kB 66.5 kB ⚠️ +48 B
Build Dir Size 2.6 MB 2.59 MB -3.46 kB
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),

@Timer Timer added this to the 9.0.4 milestone Aug 11, 2019
@ijjk
Copy link
Member Author

ijjk commented Aug 11, 2019

Stats from current PR

Click to expand stats ✅ Total Bundle Size Decrease ✅
zeit/next.js canary ijjk/next.js prerender-followup Change
Build Duration 23.1s 22.9s -202ms
node_modules Size 41.6 MB 41.6 MB ⚠️ +1.24 kB
Total Bundle (main, webpack, commons) Size 214 kB 214 kB -610 B
Total Bundle (main, webpack, commons) gzip Size 70.6 kB 70.4 kB -253 B
Total Bundle (main, webpack, commons) Modern Size 189 kB 189 kB -448 B
Total Bundle (main, webpack, commons) Modern gzip Size 62.4 kB 62.2 kB -188 B
Client _app Size 2.35 kB 2.35 kB
Client _app gzip Size 1.07 kB 1.07 kB
Client _app Modern Size 1.79 kB 1.79 kB
Client _app gzip Modern Size 880 B 880 B
Client _error Size 8.22 kB 8.22 kB
Client _error gzip Size 3.16 kB 3.16 kB
Client _error Modern Size 5.85 kB 5.85 kB
Client _error gzip Modern Size 2.33 kB 2.33 kB
Client pages/index Size 343 B 343 B
Client pages/index gzip Size 246 B 246 B
Client pages/index Modern Size 319 B 319 B
Client pages/index gzip Modern Size 254 B 254 B
Client pages/link Size 4.18 kB 4.18 kB
Client pages/link gzip Size 1.82 kB 1.82 kB
Client pages/link Modern Size 3.81 kB 3.81 kB
Client pages/link gzip Modern Size 1.72 kB 1.72 kB
Client pages/routerDirect Size 423 B 423 B
Client pages/routerDirect gzip Size 306 B 306 B
Client pages/routerDirect Modern Size 411 B 411 B
Client pages/routerDirect gzip Modern Size 314 B 314 B
Client pages/withRouter Size 435 B 435 B
Client pages/withRouter gzip Size 301 B 301 B
Client pages/withRouter Modern Size 423 B 423 B
Client pages/withRouter gzip Modern Size 309 B 309 B
Client main Size 16.3 kB 16 kB -228 B
Client main gzip Size 5.73 kB 5.66 kB -64 B
Client main Modern Size 13.1 kB 12.9 kB -186 B
Client main Modern gzip Size 4.99 kB 4.93 kB -60 B
Client commons Size 195 kB 195 kB -382 B
Client commons gzip Size 63.6 kB 63.4 kB -189 B
Client commons Modern Size 176 kB 176 kB -262 B
Client commons Modern gzip Size 57.4 kB 57.3 kB -128 B
Client webpack Size 1.53 kB 1.53 kB
Client webpack gzip Size 778 B 778 B
Client webpack Modern Size 1.53 kB 1.53 kB
Client webpack Modern gzip Size 785 B 785 B
Base Rendered Size 2.76 kB 2.76 kB
Build Dir Size 1.44 MB 1.43 MB -3.63 kB
Click to expand serverless stats ✅ Total Bundle Size Decrease ✅
zeit/next.js canary ijjk/next.js prerender-followup Change
Build Duration 25.2s 25s -177ms
node_modules Size 41.6 MB 41.6 MB ⚠️ +1.24 kB
Total Bundle (main, webpack, commons) Size 214 kB 214 kB -610 B
Total Bundle (main, webpack, commons) gzip Size 70.6 kB 70.4 kB -253 B
Total Bundle (main, webpack, commons) Modern Size 189 kB 189 kB -448 B
Total Bundle (main, webpack, commons) Modern gzip Size 62.4 kB 62.2 kB -188 B
Client _app Size 2.35 kB 2.35 kB
Client _app gzip Size 1.07 kB 1.07 kB
Client _app Modern Size 1.79 kB 1.79 kB
Client _app gzip Modern Size 880 B 880 B
Client _error Size 8.22 kB 8.22 kB
Client _error gzip Size 3.16 kB 3.16 kB
Client _error Modern Size 5.85 kB 5.85 kB
Client _error gzip Modern Size 2.33 kB 2.33 kB
Client pages/index Size 343 B 343 B
Client pages/index gzip Size 246 B 246 B
Client pages/index Modern Size 319 B 319 B
Client pages/index gzip Modern Size 254 B 254 B
Client pages/link Size 4.18 kB 4.18 kB
Client pages/link gzip Size 1.82 kB 1.82 kB
Client pages/link Modern Size 3.81 kB 3.81 kB
Client pages/link gzip Modern Size 1.72 kB 1.72 kB
Client pages/routerDirect Size 423 B 423 B
Client pages/routerDirect gzip Size 306 B 306 B
Client pages/routerDirect Modern Size 411 B 411 B
Client pages/routerDirect gzip Modern Size 314 B 314 B
Client pages/withRouter Size 435 B 435 B
Client pages/withRouter gzip Size 301 B 301 B
Client pages/withRouter Modern Size 423 B 423 B
Client pages/withRouter gzip Modern Size 309 B 309 B
Client main Size 16.3 kB 16 kB -228 B
Client main gzip Size 5.73 kB 5.66 kB -64 B
Client main Modern Size 13.1 kB 12.9 kB -186 B
Client main Modern gzip Size 4.99 kB 4.93 kB -60 B
Client commons Size 195 kB 195 kB -382 B
Client commons gzip Size 63.6 kB 63.4 kB -189 B
Client commons Modern Size 176 kB 176 kB -262 B
Client commons Modern gzip Size 57.4 kB 57.3 kB -128 B
Client webpack Size 1.53 kB 1.53 kB
Client webpack gzip Size 778 B 778 B
Client webpack Modern Size 1.53 kB 1.53 kB
Client webpack Modern gzip Size 785 B 785 B
Serverless pages/link Size 256 kB 256 kB ⚠️ +347 B
Serverless pages/link gzip Size 68.8 kB 68.9 kB ⚠️ +58 B
Serverless pages/index Size 249 kB 249 kB ⚠️ +347 B
Serverless pages/index gzip Size 66.6 kB 66.6 kB ⚠️ +58 B
Serverless pages/_error Size 248 kB 248 kB ⚠️ +347 B
Serverless pages/_error gzip Size 66.3 kB 66.4 kB ⚠️ +58 B
Serverless pages/routerDirect Size 249 kB 249 kB ⚠️ +347 B
Serverless pages/routerDirect gzip Size 66.5 kB 66.6 kB ⚠️ +58 B
Serverless pages/withRouter Size 249 kB 249 kB ⚠️ +347 B
Serverless pages/withRouter gzip Size 66.6 kB 66.7 kB ⚠️ +52 B
Build Dir Size 2.64 MB 2.64 MB -1.72 kB
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),

@ijjk
Copy link
Member Author

ijjk commented Aug 11, 2019

Stats from current PR

Click to expand stats ✅ Total Bundle Size Decrease ✅
zeit/next.js canary ijjk/next.js prerender-followup Change
Build Duration 22.5s 22.2s -252ms
node_modules Size 41.6 MB 41.6 MB ⚠️ +1.24 kB
Total Bundle (main, webpack, commons) Size 213 kB 212 kB -609 B
Total Bundle (main, webpack, commons) gzip Size 70 kB 69.7 kB -246 B
Total Bundle (main, webpack, commons) Modern Size 188 kB 187 kB -448 B
Total Bundle (main, webpack, commons) Modern gzip Size 61.8 kB 61.6 kB -180 B
Client _app Size 2.35 kB 2.35 kB
Client _app gzip Size 1.07 kB 1.07 kB
Client _app Modern Size 1.79 kB 1.79 kB
Client _app gzip Modern Size 880 B 880 B
Client _error Size 8.22 kB 8.22 kB
Client _error gzip Size 3.16 kB 3.16 kB
Client _error Modern Size 5.85 kB 5.85 kB
Client _error gzip Modern Size 2.33 kB 2.33 kB
Client pages/index Size 343 B 343 B
Client pages/index gzip Size 246 B 246 B
Client pages/index Modern Size 319 B 319 B
Client pages/index gzip Modern Size 254 B 254 B
Client pages/link Size 4.18 kB 4.18 kB
Client pages/link gzip Size 1.82 kB 1.82 kB
Client pages/link Modern Size 3.81 kB 3.81 kB
Client pages/link gzip Modern Size 1.72 kB 1.72 kB
Client pages/routerDirect Size 423 B 423 B
Client pages/routerDirect gzip Size 306 B 306 B
Client pages/routerDirect Modern Size 411 B 411 B
Client pages/routerDirect gzip Modern Size 314 B 314 B
Client pages/withRouter Size 435 B 435 B
Client pages/withRouter gzip Size 301 B 301 B
Client pages/withRouter Modern Size 423 B 423 B
Client pages/withRouter gzip Modern Size 309 B 309 B
Client main Size 14.7 kB 14.5 kB -227 B
Client main gzip Size 5.08 kB 5.03 kB -57 B
Client main Modern Size 11.6 kB 11.4 kB -186 B
Client main Modern gzip Size 4.37 kB 4.32 kB -52 B
Client commons Size 195 kB 195 kB -382 B
Client commons gzip Size 63.6 kB 63.4 kB -189 B
Client commons Modern Size 176 kB 176 kB -262 B
Client commons Modern gzip Size 57.4 kB 57.3 kB -128 B
Client webpack Size 1.53 kB 1.53 kB
Client webpack gzip Size 778 B 778 B
Client webpack Modern Size 1.53 kB 1.53 kB
Client webpack Modern gzip Size 785 B 785 B
Base Rendered Size 2.76 kB 2.76 kB
Build Dir Size 1.43 MB 1.43 MB -3.63 kB
Click to expand serverless stats ✅ Total Bundle Size Decrease ✅
zeit/next.js canary ijjk/next.js prerender-followup Change
Build Duration 23s 22.6s -470ms
node_modules Size 41.6 MB 41.6 MB ⚠️ +1.24 kB
Total Bundle (main, webpack, commons) Size 213 kB 212 kB -609 B
Total Bundle (main, webpack, commons) gzip Size 70 kB 69.7 kB -246 B
Total Bundle (main, webpack, commons) Modern Size 188 kB 187 kB -448 B
Total Bundle (main, webpack, commons) Modern gzip Size 61.8 kB 61.6 kB -179 B
Client _app Size 2.35 kB 2.35 kB
Client _app gzip Size 1.07 kB 1.07 kB
Client _app Modern Size 1.79 kB 1.79 kB
Client _app gzip Modern Size 880 B 880 B
Client _error Size 8.22 kB 8.22 kB
Client _error gzip Size 3.16 kB 3.16 kB
Client _error Modern Size 5.85 kB 5.85 kB
Client _error gzip Modern Size 2.33 kB 2.33 kB
Client pages/index Size 343 B 343 B
Client pages/index gzip Size 246 B 246 B
Client pages/index Modern Size 319 B 319 B
Client pages/index gzip Modern Size 254 B 254 B
Client pages/link Size 4.18 kB 4.18 kB
Client pages/link gzip Size 1.82 kB 1.82 kB
Client pages/link Modern Size 3.81 kB 3.81 kB
Client pages/link gzip Modern Size 1.72 kB 1.72 kB ⚠️ +1 B
Client pages/routerDirect Size 423 B 423 B
Client pages/routerDirect gzip Size 306 B 306 B
Client pages/routerDirect Modern Size 411 B 411 B
Client pages/routerDirect gzip Modern Size 314 B 314 B
Client pages/withRouter Size 435 B 435 B
Client pages/withRouter gzip Size 300 B 301 B ⚠️ +1 B
Client pages/withRouter Modern Size 423 B 423 B
Client pages/withRouter gzip Modern Size 309 B 309 B
Client main Size 14.7 kB 14.5 kB -227 B
Client main gzip Size 5.08 kB 5.03 kB -57 B
Client main Modern Size 11.6 kB 11.4 kB -186 B
Client main Modern gzip Size 4.37 kB 4.32 kB -51 B
Client commons Size 195 kB 195 kB -382 B
Client commons gzip Size 63.6 kB 63.4 kB -189 B
Client commons Modern Size 176 kB 176 kB -262 B
Client commons Modern gzip Size 57.4 kB 57.3 kB -128 B
Client webpack Size 1.53 kB 1.53 kB
Client webpack gzip Size 778 B 778 B
Client webpack Modern Size 1.53 kB 1.53 kB
Client webpack Modern gzip Size 785 B 785 B
Serverless pages/link Size 256 kB 256 kB ⚠️ +347 B
Serverless pages/link gzip Size 68.9 kB 68.9 kB ⚠️ +61 B
Serverless pages/index Size 249 kB 249 kB ⚠️ +347 B
Serverless pages/index gzip Size 66.6 kB 66.7 kB ⚠️ +61 B
Serverless pages/_error Size 248 kB 248 kB ⚠️ +347 B
Serverless pages/_error gzip Size 66.3 kB 66.4 kB ⚠️ +60 B
Serverless pages/routerDirect Size 249 kB 250 kB ⚠️ +347 B
Serverless pages/routerDirect gzip Size 66.6 kB 66.6 kB ⚠️ +61 B
Serverless pages/withRouter Size 249 kB 249 kB ⚠️ +347 B
Serverless pages/withRouter gzip Size 66.6 kB 66.7 kB ⚠️ +57 B
Build Dir Size 2.64 MB 2.64 MB -1.72 kB
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),

@ijjk
Copy link
Member Author

ijjk commented Aug 12, 2019

Stats from current PR

Click to expand stats ✅ Total Bundle Size Decrease ✅
zeit/next.js canary ijjk/next.js prerender-followup Change
Build Duration 23.1s 24s ⚠️ +867ms
node_modules Size 41.6 MB 41.6 MB ⚠️ +1.7 kB
Total Bundle (main, webpack, commons) Size 213 kB 212 kB -609 B
Total Bundle (main, webpack, commons) gzip Size 70 kB 69.7 kB -246 B
Total Bundle (main, webpack, commons) Modern Size 188 kB 187 kB -448 B
Total Bundle (main, webpack, commons) Modern gzip Size 61.8 kB 61.6 kB -180 B
Client _app Size 2.35 kB 2.35 kB
Client _app gzip Size 1.07 kB 1.07 kB
Client _app Modern Size 1.79 kB 1.79 kB
Client _app gzip Modern Size 880 B 880 B
Client _error Size 8.22 kB 8.22 kB
Client _error gzip Size 3.16 kB 3.16 kB
Client _error Modern Size 5.85 kB 5.85 kB
Client _error gzip Modern Size 2.33 kB 2.33 kB
Client pages/index Size 343 B 343 B
Client pages/index gzip Size 246 B 246 B
Client pages/index Modern Size 319 B 319 B
Client pages/index gzip Modern Size 254 B 254 B
Client pages/link Size 4.18 kB 4.18 kB
Client pages/link gzip Size 1.82 kB 1.82 kB
Client pages/link Modern Size 3.81 kB 3.81 kB
Client pages/link gzip Modern Size 1.72 kB 1.72 kB
Client pages/routerDirect Size 423 B 423 B
Client pages/routerDirect gzip Size 306 B 306 B
Client pages/routerDirect Modern Size 411 B 411 B
Client pages/routerDirect gzip Modern Size 314 B 314 B
Client pages/withRouter Size 435 B 435 B
Client pages/withRouter gzip Size 301 B 301 B
Client pages/withRouter Modern Size 423 B 423 B
Client pages/withRouter gzip Modern Size 309 B 309 B
Client main Size 14.7 kB 14.5 kB -227 B
Client main gzip Size 5.08 kB 5.03 kB -57 B
Client main Modern Size 11.6 kB 11.4 kB -186 B
Client main Modern gzip Size 4.37 kB 4.32 kB -52 B
Client commons Size 195 kB 195 kB -382 B
Client commons gzip Size 63.6 kB 63.4 kB -189 B
Client commons Modern Size 176 kB 176 kB -262 B
Client commons Modern gzip Size 57.4 kB 57.3 kB -128 B
Client webpack Size 1.53 kB 1.53 kB
Client webpack gzip Size 778 B 778 B
Client webpack Modern Size 1.53 kB 1.53 kB
Client webpack Modern gzip Size 785 B 785 B
Base Rendered Size 2.76 kB 2.76 kB
Build Dir Size 1.43 MB 1.43 MB -3.38 kB
Click to expand serverless stats ✅ Total Bundle Size Decrease ✅
zeit/next.js canary ijjk/next.js prerender-followup Change
Build Duration 24.3s 25.8s ⚠️ +1.5s
node_modules Size 41.6 MB 41.6 MB ⚠️ +1.7 kB
Total Bundle (main, webpack, commons) Size 213 kB 212 kB -609 B
Total Bundle (main, webpack, commons) gzip Size 70 kB 69.7 kB -246 B
Total Bundle (main, webpack, commons) Modern Size 188 kB 187 kB -448 B
Total Bundle (main, webpack, commons) Modern gzip Size 61.8 kB 61.6 kB -180 B
Client _app Size 2.35 kB 2.35 kB
Client _app gzip Size 1.07 kB 1.07 kB
Client _app Modern Size 1.79 kB 1.79 kB
Client _app gzip Modern Size 880 B 880 B
Client _error Size 8.22 kB 8.22 kB
Client _error gzip Size 3.16 kB 3.16 kB
Client _error Modern Size 5.85 kB 5.85 kB
Client _error gzip Modern Size 2.33 kB 2.33 kB
Client pages/index Size 343 B 343 B
Client pages/index gzip Size 246 B 246 B
Client pages/index Modern Size 319 B 319 B
Client pages/index gzip Modern Size 254 B 254 B
Client pages/link Size 4.18 kB 4.18 kB
Client pages/link gzip Size 1.82 kB 1.82 kB
Client pages/link Modern Size 3.81 kB 3.81 kB
Client pages/link gzip Modern Size 1.72 kB 1.72 kB
Client pages/routerDirect Size 423 B 423 B
Client pages/routerDirect gzip Size 306 B 306 B
Client pages/routerDirect Modern Size 411 B 411 B
Client pages/routerDirect gzip Modern Size 314 B 314 B
Client pages/withRouter Size 435 B 435 B
Client pages/withRouter gzip Size 301 B 301 B
Client pages/withRouter Modern Size 423 B 423 B
Client pages/withRouter gzip Modern Size 309 B 309 B
Client main Size 14.7 kB 14.5 kB -227 B
Client main gzip Size 5.08 kB 5.03 kB -57 B
Client main Modern Size 11.6 kB 11.4 kB -186 B
Client main Modern gzip Size 4.37 kB 4.32 kB -52 B
Client commons Size 195 kB 195 kB -382 B
Client commons gzip Size 63.6 kB 63.4 kB -189 B
Client commons Modern Size 176 kB 176 kB -262 B
Client commons Modern gzip Size 57.4 kB 57.3 kB -128 B
Client webpack Size 1.53 kB 1.53 kB
Client webpack gzip Size 778 B 778 B
Client webpack Modern Size 1.53 kB 1.53 kB
Client webpack Modern gzip Size 785 B 785 B
Serverless pages/link Size 256 kB 257 kB ⚠️ +456 B
Serverless pages/link gzip Size 68.8 kB 69 kB ⚠️ +119 B
Serverless pages/index Size 249 kB 249 kB ⚠️ +456 B
Serverless pages/index gzip Size 66.6 kB 66.7 kB ⚠️ +118 B
Serverless pages/_error Size 248 kB 248 kB ⚠️ +456 B
Serverless pages/_error gzip Size 66.3 kB 66.4 kB ⚠️ +119 B
Serverless pages/routerDirect Size 249 kB 250 kB ⚠️ +456 B
Serverless pages/routerDirect gzip Size 66.5 kB 66.6 kB ⚠️ +119 B
Serverless pages/withRouter Size 249 kB 250 kB ⚠️ +456 B
Serverless pages/withRouter gzip Size 66.6 kB 66.7 kB ⚠️ +108 B
Build Dir Size 2.64 MB 2.64 MB -804 B
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),

@ijjk
Copy link
Member Author

ijjk commented Aug 12, 2019

Stats from current PR

Click to expand stats ✅ Total Bundle Size Decrease ✅
zeit/next.js canary ijjk/next.js prerender-followup Change
Build Duration 22.2s 22.4s ⚠️ +154ms
node_modules Size 41.6 MB 41.6 MB ⚠️ +1.7 kB
Total Bundle (main, webpack, commons) Size 213 kB 212 kB -609 B
Total Bundle (main, webpack, commons) gzip Size 70 kB 69.7 kB -246 B
Total Bundle (main, webpack, commons) Modern Size 188 kB 187 kB -448 B
Total Bundle (main, webpack, commons) Modern gzip Size 61.8 kB 61.6 kB -180 B
Client _app Size 2.35 kB 2.35 kB
Client _app gzip Size 1.07 kB 1.07 kB
Client _app Modern Size 1.79 kB 1.79 kB
Client _app gzip Modern Size 880 B 880 B
Client _error Size 8.22 kB 8.22 kB
Client _error gzip Size 3.16 kB 3.16 kB
Client _error Modern Size 5.85 kB 5.85 kB
Client _error gzip Modern Size 2.33 kB 2.33 kB
Client pages/index Size 343 B 343 B
Client pages/index gzip Size 246 B 246 B
Client pages/index Modern Size 319 B 319 B
Client pages/index gzip Modern Size 254 B 254 B
Client pages/link Size 4.18 kB 4.18 kB
Client pages/link gzip Size 1.82 kB 1.82 kB
Client pages/link Modern Size 3.81 kB 3.81 kB
Client pages/link gzip Modern Size 1.72 kB 1.72 kB
Client pages/routerDirect Size 423 B 423 B
Client pages/routerDirect gzip Size 306 B 306 B
Client pages/routerDirect Modern Size 411 B 411 B
Client pages/routerDirect gzip Modern Size 314 B 314 B
Client pages/withRouter Size 435 B 435 B
Client pages/withRouter gzip Size 301 B 301 B
Client pages/withRouter Modern Size 423 B 423 B
Client pages/withRouter gzip Modern Size 309 B 309 B
Client main Size 14.7 kB 14.5 kB -227 B
Client main gzip Size 5.08 kB 5.03 kB -57 B
Client main Modern Size 11.6 kB 11.4 kB -186 B
Client main Modern gzip Size 4.37 kB 4.32 kB -52 B
Client commons Size 195 kB 195 kB -382 B
Client commons gzip Size 63.6 kB 63.4 kB -189 B
Client commons Modern Size 176 kB 176 kB -262 B
Client commons Modern gzip Size 57.4 kB 57.3 kB -128 B
Client webpack Size 1.53 kB 1.53 kB
Client webpack gzip Size 778 B 778 B
Client webpack Modern Size 1.53 kB 1.53 kB
Client webpack Modern gzip Size 785 B 785 B
Base Rendered Size 2.76 kB 2.76 kB
Build Dir Size 1.43 MB 1.43 MB -3.38 kB
Click to expand serverless stats ✅ Total Bundle Size Decrease ✅
zeit/next.js canary ijjk/next.js prerender-followup Change
Build Duration 24.1s 25.4s ⚠️ +1.3s
node_modules Size 41.6 MB 41.6 MB ⚠️ +1.7 kB
Total Bundle (main, webpack, commons) Size 213 kB 212 kB -609 B
Total Bundle (main, webpack, commons) gzip Size 70 kB 69.7 kB -246 B
Total Bundle (main, webpack, commons) Modern Size 188 kB 187 kB -448 B
Total Bundle (main, webpack, commons) Modern gzip Size 61.8 kB 61.6 kB -180 B
Client _app Size 2.35 kB 2.35 kB
Client _app gzip Size 1.07 kB 1.07 kB
Client _app Modern Size 1.79 kB 1.79 kB
Client _app gzip Modern Size 880 B 880 B
Client _error Size 8.22 kB 8.22 kB
Client _error gzip Size 3.16 kB 3.16 kB
Client _error Modern Size 5.85 kB 5.85 kB
Client _error gzip Modern Size 2.33 kB 2.33 kB
Client pages/index Size 343 B 343 B
Client pages/index gzip Size 246 B 246 B
Client pages/index Modern Size 319 B 319 B
Client pages/index gzip Modern Size 254 B 254 B
Client pages/link Size 4.18 kB 4.18 kB
Client pages/link gzip Size 1.82 kB 1.82 kB
Client pages/link Modern Size 3.81 kB 3.81 kB
Client pages/link gzip Modern Size 1.72 kB 1.72 kB
Client pages/routerDirect Size 423 B 423 B
Client pages/routerDirect gzip Size 306 B 306 B
Client pages/routerDirect Modern Size 411 B 411 B
Client pages/routerDirect gzip Modern Size 314 B 314 B
Client pages/withRouter Size 435 B 435 B
Client pages/withRouter gzip Size 301 B 301 B
Client pages/withRouter Modern Size 423 B 423 B
Client pages/withRouter gzip Modern Size 309 B 309 B
Client main Size 14.7 kB 14.5 kB -227 B
Client main gzip Size 5.08 kB 5.03 kB -57 B
Client main Modern Size 11.6 kB 11.4 kB -186 B
Client main Modern gzip Size 4.37 kB 4.32 kB -52 B
Client commons Size 195 kB 195 kB -382 B
Client commons gzip Size 63.6 kB 63.4 kB -189 B
Client commons Modern Size 176 kB 176 kB -262 B
Client commons Modern gzip Size 57.4 kB 57.3 kB -128 B
Client webpack Size 1.53 kB 1.53 kB
Client webpack gzip Size 778 B 778 B
Client webpack Modern Size 1.53 kB 1.53 kB
Client webpack Modern gzip Size 785 B 785 B
Serverless pages/link Size 256 kB 257 kB ⚠️ +456 B
Serverless pages/link gzip Size 68.8 kB 69 kB ⚠️ +118 B
Serverless pages/index Size 249 kB 249 kB ⚠️ +456 B
Serverless pages/index gzip Size 66.6 kB 66.7 kB ⚠️ +118 B
Serverless pages/_error Size 248 kB 248 kB ⚠️ +456 B
Serverless pages/_error gzip Size 66.3 kB 66.4 kB ⚠️ +118 B
Serverless pages/routerDirect Size 249 kB 250 kB ⚠️ +456 B
Serverless pages/routerDirect gzip Size 66.5 kB 66.6 kB ⚠️ +119 B
Serverless pages/withRouter Size 249 kB 250 kB ⚠️ +456 B
Serverless pages/withRouter gzip Size 66.6 kB 66.7 kB ⚠️ +109 B
Build Dir Size 2.64 MB 2.64 MB -804 B
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 Timer merged commit fc7e235 into vercel:canary Aug 12, 2019
@ijjk ijjk deleted the prerender-followup branch August 12, 2019 14:36
@vercel vercel locked as resolved and limited conversation to collaborators Feb 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

2 participants