Skip to content
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

Show warning if next export detects an API route #8257

Merged
merged 7 commits into from Aug 11, 2019

Conversation

lfades
Copy link
Member

@lfades lfades commented Aug 6, 2019

Continuation of #8250

A warning is shown if the user defines a path for an API route, paths that use an API route are removed to avoid a throw from next export.

@ijjk
Copy link
Member

ijjk commented Aug 6, 2019

Stats from current PR

Click to expand stats
zeit/next.js canary lfades/next.js api-export-error Change
Build Duration 12.8s 12.5s -265ms
node_modules Size 43.6 MB 43.6 MB ⚠️ +429 B
Total Bundle (main, webpack, commons) Size 206 kB 206 kB
Total Bundle (main, webpack, commons) gzip Size 67.8 kB 67.8 kB
Client _app Size 2.39 kB 2.39 kB
Client _app gzip Size 1.08 kB 1.08 kB
Client _error Size 8.22 kB 8.22 kB
Client _error gzip Size 3.16 kB 3.16 kB
Client pages/index Size 343 B 343 B
Client pages/index gzip Size 246 B 246 B
Client pages/link Size 4.08 kB 4.08 kB
Client pages/link gzip Size 1.8 kB 1.8 kB
Client pages/routerDirect Size 423 B 423 B
Client pages/routerDirect gzip Size 306 B 306 B
Client pages/withRouter Size 435 B 435 B
Client pages/withRouter gzip Size 301 B 301 B
Client main Size 15.4 kB 15.4 kB
Client main gzip Size 5.35 kB 5.35 kB
Client commons Size 188 kB 188 kB
Client commons gzip Size 61.1 kB 61.1 kB
Client webpack Size 1.53 kB 1.53 kB
Client webpack gzip Size 778 B 778 B
Base Rendered Size 1.35 kB 1.35 kB
Build Dir Size 702 kB 702 kB
Click to expand serverless stats
zeit/next.js canary lfades/next.js api-export-error Change
Build Duration 13.4s 13.6s ⚠️ +191ms
node_modules Size 43.6 MB 43.6 MB ⚠️ +429 B
Total Bundle (main, webpack, commons) Size 206 kB 206 kB
Total Bundle (main, webpack, commons) gzip Size 67.8 kB 67.8 kB
Client _app Size 2.39 kB 2.39 kB
Client _app gzip Size 1.08 kB 1.08 kB
Client _error Size 8.22 kB 8.22 kB
Client _error gzip Size 3.16 kB 3.16 kB
Client pages/index Size 343 B 343 B
Client pages/index gzip Size 246 B 246 B
Client pages/link Size 4.08 kB 4.08 kB
Client pages/link gzip Size 1.8 kB 1.8 kB
Client pages/routerDirect Size 423 B 423 B
Client pages/routerDirect gzip Size 306 B 306 B
Client pages/withRouter Size 435 B 435 B
Client pages/withRouter gzip Size 300 B 300 B
Client main Size 15.4 kB 15.4 kB
Client main gzip Size 5.35 kB 5.35 kB
Client commons Size 188 kB 188 kB
Client commons gzip Size 61.1 kB 61.1 kB
Client webpack Size 1.53 kB 1.53 kB
Client webpack gzip Size 778 B 778 B
Serverless pages/link Size 251 kB 251 kB
Serverless pages/link gzip Size 67.8 kB 67.8 kB
Serverless pages/index Size 244 kB 244 kB
Serverless pages/index gzip Size 65.6 kB 65.6 kB
Serverless pages/_error Size 243 kB 243 kB
Serverless pages/_error gzip Size 65.4 kB 65.4 kB ⚠️ +1 B
Serverless pages/routerDirect Size 244 kB 244 kB
Serverless pages/routerDirect gzip Size 65.6 kB 65.6 kB ⚠️ +2 B
Serverless pages/withRouter Size 244 kB 244 kB
Serverless pages/withRouter gzip Size 65.7 kB 65.7 kB -1 B
Build Dir Size 1.89 MB 1.89 MB

@ijjk
Copy link
Member

ijjk commented Aug 6, 2019

Stats from current PR

Click to expand stats
zeit/next.js canary lfades/next.js api-export-error Change
Build Duration 13.2s 13.2s -55ms
node_modules Size 43.6 MB 43.6 MB ⚠️ +429 B
Total Bundle (main, webpack, commons) Size 206 kB 206 kB
Total Bundle (main, webpack, commons) gzip Size 67.8 kB 67.8 kB
Client _app Size 2.39 kB 2.39 kB
Client _app gzip Size 1.08 kB 1.08 kB
Client _error Size 8.22 kB 8.22 kB
Client _error gzip Size 3.16 kB 3.16 kB
Client pages/index Size 343 B 343 B
Client pages/index gzip Size 246 B 246 B
Client pages/link Size 4.08 kB 4.08 kB
Client pages/link gzip Size 1.8 kB 1.8 kB
Client pages/routerDirect Size 423 B 423 B
Client pages/routerDirect gzip Size 306 B 306 B
Client pages/withRouter Size 435 B 435 B
Client pages/withRouter gzip Size 301 B 301 B
Client main Size 15.4 kB 15.4 kB
Client main gzip Size 5.35 kB 5.35 kB
Client commons Size 188 kB 188 kB
Client commons gzip Size 61.1 kB 61.1 kB
Client webpack Size 1.53 kB 1.53 kB
Client webpack gzip Size 778 B 778 B
Base Rendered Size 1.35 kB 1.35 kB
Build Dir Size 702 kB 702 kB
Click to expand serverless stats
zeit/next.js canary lfades/next.js api-export-error Change
Build Duration 14.6s 14.6s ⚠️ +69ms
node_modules Size 43.6 MB 43.6 MB ⚠️ +429 B
Total Bundle (main, webpack, commons) Size 206 kB 206 kB
Total Bundle (main, webpack, commons) gzip Size 67.8 kB 67.8 kB
Client _app Size 2.39 kB 2.39 kB
Client _app gzip Size 1.08 kB 1.08 kB
Client _error Size 8.22 kB 8.22 kB
Client _error gzip Size 3.16 kB 3.16 kB
Client pages/index Size 343 B 343 B
Client pages/index gzip Size 246 B 246 B
Client pages/link Size 4.08 kB 4.08 kB
Client pages/link gzip Size 1.8 kB 1.8 kB
Client pages/routerDirect Size 423 B 423 B
Client pages/routerDirect gzip Size 306 B 306 B
Client pages/withRouter Size 435 B 435 B
Client pages/withRouter gzip Size 301 B 301 B
Client main Size 15.4 kB 15.4 kB
Client main gzip Size 5.35 kB 5.35 kB
Client commons Size 188 kB 188 kB
Client commons gzip Size 61.1 kB 61.1 kB
Client webpack Size 1.53 kB 1.53 kB
Client webpack gzip Size 778 B 778 B
Serverless pages/link Size 251 kB 251 kB
Serverless pages/link gzip Size 67.8 kB 67.8 kB -1 B
Serverless pages/index Size 244 kB 244 kB
Serverless pages/index gzip Size 65.6 kB 65.6 kB -1 B
Serverless pages/_error Size 243 kB 243 kB
Serverless pages/_error gzip Size 65.4 kB 65.4 kB
Serverless pages/routerDirect Size 244 kB 244 kB
Serverless pages/routerDirect gzip Size 65.6 kB 65.6 kB -1 B
Serverless pages/withRouter Size 244 kB 244 kB
Serverless pages/withRouter gzip Size 65.7 kB 65.7 kB -1 B
Build Dir Size 1.89 MB 1.89 MB

@ijjk
Copy link
Member

ijjk commented Aug 6, 2019

Stats from current PR

Click to expand stats
zeit/next.js canary lfades/next.js api-export-error Change
Build Duration 13.1s 13.1s -83ms
node_modules Size 43.6 MB 43.6 MB ⚠️ +429 B
Total Bundle (main, webpack, commons) Size 206 kB 206 kB
Total Bundle (main, webpack, commons) gzip Size 67.8 kB 67.8 kB -1 B
Client _app Size 2.39 kB 2.39 kB
Client _app gzip Size 1.08 kB 1.08 kB -1 B
Client _error Size 8.22 kB 8.22 kB
Client _error gzip Size 3.16 kB 3.16 kB
Client pages/index Size 343 B 343 B
Client pages/index gzip Size 246 B 246 B
Client pages/link Size 4.08 kB 4.08 kB
Client pages/link gzip Size 1.8 kB 1.8 kB
Client pages/routerDirect Size 423 B 423 B
Client pages/routerDirect gzip Size 306 B 306 B
Client pages/withRouter Size 435 B 435 B
Client pages/withRouter gzip Size 301 B 300 B -1 B
Client main Size 15.4 kB 15.4 kB
Client main gzip Size 5.35 kB 5.35 kB
Client commons Size 188 kB 188 kB
Client commons gzip Size 61.1 kB 61.1 kB
Client webpack Size 1.53 kB 1.53 kB
Client webpack gzip Size 778 B 778 B
Base Rendered Size 1.35 kB 1.35 kB
Build Dir Size 702 kB 702 kB
Click to expand serverless stats
zeit/next.js canary lfades/next.js api-export-error Change
Build Duration 14.3s 14.2s -47ms
node_modules Size 43.6 MB 43.6 MB ⚠️ +429 B
Total Bundle (main, webpack, commons) Size 206 kB 206 kB
Total Bundle (main, webpack, commons) gzip Size 67.8 kB 67.8 kB -1 B
Client _app Size 2.39 kB 2.39 kB
Client _app gzip Size 1.08 kB 1.08 kB -1 B
Client _error Size 8.22 kB 8.22 kB
Client _error gzip Size 3.16 kB 3.16 kB
Client pages/index Size 343 B 343 B
Client pages/index gzip Size 246 B 246 B
Client pages/link Size 4.08 kB 4.08 kB
Client pages/link gzip Size 1.8 kB 1.8 kB
Client pages/routerDirect Size 423 B 423 B
Client pages/routerDirect gzip Size 306 B 306 B
Client pages/withRouter Size 435 B 435 B
Client pages/withRouter gzip Size 301 B 300 B -1 B
Client main Size 15.4 kB 15.4 kB
Client main gzip Size 5.35 kB 5.35 kB
Client commons Size 188 kB 188 kB
Client commons gzip Size 61.1 kB 61.1 kB
Client webpack Size 1.53 kB 1.53 kB
Client webpack gzip Size 778 B 778 B
Serverless pages/link Size 251 kB 251 kB
Serverless pages/link gzip Size 67.8 kB 67.8 kB
Serverless pages/index Size 244 kB 244 kB
Serverless pages/index gzip Size 65.6 kB 65.6 kB
Serverless pages/_error Size 243 kB 243 kB
Serverless pages/_error gzip Size 65.4 kB 65.4 kB
Serverless pages/routerDirect Size 244 kB 244 kB
Serverless pages/routerDirect gzip Size 65.6 kB 65.6 kB
Serverless pages/withRouter Size 244 kB 244 kB
Serverless pages/withRouter gzip Size 65.7 kB 65.7 kB ⚠️ +2 B
Build Dir Size 1.89 MB 1.89 MB

@ijjk
Copy link
Member

ijjk commented Aug 6, 2019

Stats from current PR

Click to expand stats
zeit/next.js canary lfades/next.js api-export-error Change
Build Duration 12.4s 12.6s ⚠️ +233ms
node_modules Size 43.6 MB 43.6 MB ⚠️ +429 B
Total Bundle (main, webpack, commons) Size 206 kB 206 kB
Total Bundle (main, webpack, commons) gzip Size 67.8 kB 67.8 kB
Client _app Size 2.39 kB 2.39 kB
Client _app gzip Size 1.08 kB 1.08 kB
Client _error Size 8.22 kB 8.22 kB
Client _error gzip Size 3.16 kB 3.16 kB
Client pages/index Size 343 B 343 B
Client pages/index gzip Size 246 B 246 B
Client pages/link Size 4.08 kB 4.08 kB
Client pages/link gzip Size 1.8 kB 1.8 kB
Client pages/routerDirect Size 423 B 423 B
Client pages/routerDirect gzip Size 306 B 306 B
Client pages/withRouter Size 435 B 435 B
Client pages/withRouter gzip Size 301 B 301 B
Client main Size 15.4 kB 15.4 kB
Client main gzip Size 5.35 kB 5.35 kB
Client commons Size 188 kB 188 kB
Client commons gzip Size 61.1 kB 61.1 kB
Client webpack Size 1.53 kB 1.53 kB
Client webpack gzip Size 778 B 778 B
Base Rendered Size 1.35 kB 1.35 kB
Build Dir Size 702 kB 702 kB
Click to expand serverless stats
zeit/next.js canary lfades/next.js api-export-error Change
Build Duration 13.2s 13.7s ⚠️ +490ms
node_modules Size 43.6 MB 43.6 MB ⚠️ +429 B
Total Bundle (main, webpack, commons) Size 206 kB 206 kB
Total Bundle (main, webpack, commons) gzip Size 67.8 kB 67.8 kB
Client _app Size 2.39 kB 2.39 kB
Client _app gzip Size 1.08 kB 1.08 kB
Client _error Size 8.22 kB 8.22 kB
Client _error gzip Size 3.16 kB 3.16 kB
Client pages/index Size 343 B 343 B
Client pages/index gzip Size 246 B 246 B
Client pages/link Size 4.08 kB 4.08 kB
Client pages/link gzip Size 1.8 kB 1.8 kB
Client pages/routerDirect Size 423 B 423 B
Client pages/routerDirect gzip Size 306 B 306 B
Client pages/withRouter Size 435 B 435 B
Client pages/withRouter gzip Size 301 B 301 B
Client main Size 15.4 kB 15.4 kB
Client main gzip Size 5.35 kB 5.35 kB
Client commons Size 188 kB 188 kB
Client commons gzip Size 61.1 kB 61.1 kB
Client webpack Size 1.53 kB 1.53 kB
Client webpack gzip Size 778 B 778 B
Serverless pages/link Size 251 kB 251 kB
Serverless pages/link gzip Size 67.8 kB 67.8 kB ⚠️ +1 B
Serverless pages/index Size 244 kB 244 kB
Serverless pages/index gzip Size 65.6 kB 65.6 kB ⚠️ +1 B
Serverless pages/_error Size 243 kB 243 kB
Serverless pages/_error gzip Size 65.4 kB 65.4 kB
Serverless pages/routerDirect Size 244 kB 244 kB
Serverless pages/routerDirect gzip Size 65.6 kB 65.6 kB ⚠️ +1 B
Serverless pages/withRouter Size 244 kB 244 kB
Serverless pages/withRouter gzip Size 65.7 kB 65.7 kB
Build Dir Size 1.89 MB 1.89 MB

@lfades lfades requested a review from huv1k August 6, 2019 16:45
Copy link
Contributor

@huv1k huv1k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would show a warning for default export map, so users are aware that there is no export fo API routes.

@timneutkens
Copy link
Member

I would remove the routes from defaultPathMap, but show a warning indeed.

@ijjk
Copy link
Member

ijjk commented Aug 8, 2019

Stats from current PR

Click to expand stats ✅ Total Bundle Size Decrease ✅
zeit/next.js canary lfades/next.js api-export-error Change
Build Duration 21.2s 21s -242ms
node_modules Size 43.6 MB 43.5 MB -29.9 kB
Total Bundle (main, webpack, commons) Size 207 kB 206 kB -674 B
Total Bundle (main, webpack, commons) gzip Size 68.1 kB 67.8 kB -285 B
Total Bundle (main, webpack, commons) Modern Size 182 kB 181 kB -467 B
Total Bundle (main, webpack, commons) Modern gzip Size 59.9 kB 59.7 kB -205 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.8 kB 15.6 kB -240 B
Client main gzip Size 5.46 kB 5.39 kB -63 B
Client main Modern Size 12.8 kB 12.7 kB -197 B
Client main Modern gzip Size 4.83 kB 4.77 kB -65 B
Client commons Size 188 kB 188 kB -434 B
Client commons gzip Size 61.3 kB 61.1 kB -222 B
Client commons Modern Size 169 kB 168 kB -270 B
Client commons Modern gzip Size 55.1 kB 54.9 kB -140 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.02 kB
Click to expand serverless stats ✅ Total Bundle Size Decrease ✅
zeit/next.js canary lfades/next.js api-export-error Change
Build Duration 22.4s 22.8s ⚠️ +377ms
node_modules Size 43.6 MB 43.5 MB -29.9 kB
Total Bundle (main, webpack, commons) Size 207 kB 206 kB -674 B
Total Bundle (main, webpack, commons) gzip Size 68.1 kB 67.8 kB -285 B
Total Bundle (main, webpack, commons) Modern Size 182 kB 181 kB -467 B
Total Bundle (main, webpack, commons) Modern gzip Size 59.9 kB 59.7 kB -205 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.8 kB 15.6 kB -240 B
Client main gzip Size 5.46 kB 5.39 kB -63 B
Client main Modern Size 12.8 kB 12.7 kB -197 B
Client main Modern gzip Size 4.83 kB 4.77 kB -65 B
Client commons Size 188 kB 188 kB -434 B
Client commons gzip Size 61.3 kB 61.1 kB -222 B
Client commons Modern Size 169 kB 168 kB -270 B
Client commons Modern gzip Size 55.1 kB 54.9 kB -140 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 254 kB -1.18 kB
Serverless pages/link gzip Size 68.6 kB 68.2 kB -398 B
Serverless pages/index Size 248 kB 247 kB -1.16 kB
Serverless pages/index gzip Size 66.4 kB 66 kB -382 B
Serverless pages/_error Size 247 kB 246 kB -1.16 kB
Serverless pages/_error gzip Size 66.1 kB 65.7 kB -386 B
Serverless pages/routerDirect Size 248 kB 247 kB -1.16 kB
Serverless pages/routerDirect gzip Size 66.3 kB 65.9 kB -388 B
Serverless pages/withRouter Size 248 kB 247 kB -1.16 kB
Serverless pages/withRouter gzip Size 66.4 kB 66 kB -384 B
Build Dir Size 2.59 MB 2.58 MB -12.8 kB
Diff for main.js
@@ -1,4 +1,4 @@
-(window["webpackJsonp"] = window["webpackJsonp"] || []).push([[8],{
+(window["webpackJsonp"] = window["webpackJsonp"] || []).push([[2],{
 
 /***/ "+iuc":
 /***/ (function(module, exports, __webpack_require__) {
@@ -503,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;
 
     return _regenerator["default"].wrap(function _callee$(_context) {
       while (1) {
@@ -584,41 +584,16 @@ function () {
                 });
               }
             });
-            renderCtx = {
+            render({
               App: App,
               Component: Component,
               props: props,
               err: initialErr,
               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 26:
           case "end":
             return _context.stop();
         }
Diff for commons.js
@@ -3223,14 +3223,7 @@ function () {
 
         var _url_1$parse = url_1.parse(url, true),
             pathname = _url_1$parse.pathname,
-            query = _url_1$parse.query,
-            protocol = _url_1$parse.protocol;
-
-        if (!pathname || protocol) {
-          if (false) {}
-
-          return resolve(false);
-        } // If asked to change the current URL we should reload the current page
+            query = _url_1$parse.query; // If asked to change the current URL we should reload the current page
         // (not location.reload() but reload getInitialProps and other Next.js stuffs)
         // We also need to set the method = replaceState always
         // as this should not go into the history (That's how browsers work)
@@ -3499,18 +3492,12 @@ function () {
       var _this4 = this;
 
       return new _promise["default"](function (resolve, reject) {
-        var _url_1$parse3 = url_1.parse(url),
-            pathname = _url_1$parse3.pathname,
-            protocol = _url_1$parse3.protocol;
-
-        if (!pathname || protocol) {
-          if (false) {}
-
-          return;
-        } // Prefetch is not supported in development mode because it would trigger on-demand-entries
+        // Prefetch is not supported in development mode because it would trigger on-demand-entries
+        if (false) {}
 
+        var _url_1$parse3 = url_1.parse(url),
+            pathname = _url_1$parse3.pathname; // @ts-ignore pathname is always defined
 
-        if (false) {} // @ts-ignore pathname is always defined
 
         var route = toRoute(pathname);
 
@@ -3576,7 +3563,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, err;
         return _regenerator["default"].wrap(function _callee2$(_context2) {
           while (1) {
             switch (_context2.prev = _context2.next) {
@@ -3589,59 +3576,7 @@ function () {
 
                 this.clc = cancel;
                 App = this.components['/_app'].Component;
-
-                if (!Component.__NEXT_PRERENDER) {
-                  _context2.next = 20;
-                  break;
-                }
-
-                url = url_1.format({
-                  pathname: ctx.asPath,
-                  query: ctx.query
-                });
-                _context2.next = 8;
-                return fetch(url, {
-                  headers: {
-                    'content-type': 'application/json'
-                  }
-                });
-
-              case 8:
-                res = _context2.sent;
-
-                if (!res.ok) {
-                  _context2.next = 15;
-                  break;
-                }
-
-                _context2.next = 12;
-                return res.json()["catch"](function (err) {
-                  return {
-                    error: err.message
-                  };
-                });
-
-              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;
-                break;
-
-              case 20:
-                _context2.next = 22;
+                _context2.next = 6;
                 return utils_1.loadGetInitialProps(App, {
                   AppTree: this._wrapApp(App),
                   Component: Component,
@@ -3649,16 +3584,15 @@ function () {
                   ctx: ctx
                 });
 
-              case 22:
+              case 6:
                 props = _context2.sent;
 
-              case 23:
                 if (cancel === this.clc) {
                   this.clc = null;
                 }
 
                 if (!cancelled) {
-                  _context2.next = 28;
+                  _context2.next = 12;
                   break;
                 }
 
@@ -3666,10 +3600,10 @@ function () {
                 err.cancelled = true;
                 throw err;
 
-              case 28:
+              case 12:
                 return _context2.abrupt("return", props);
 
-              case 29:
+              case 13:
               case "end":
                 return _context2.stop();
             }
@@ -6750,7 +6684,8 @@ var singletonRouter = {
   }
 }; // Create public properties and methods of the router in the singletonRouter
 
-var urlPropertyFields = ['pathname', 'route', 'query', 'asPath', 'components'];
+var urlPropertyFields = ['pathname', 'route', 'query', 'asPath'];
+var propertyFields = ['components'];
 var routerEvents = ['routeChangeStart', 'beforeHistoryChange', 'routeChangeComplete', 'routeChangeError', 'hashChangeStart', 'hashChangeComplete'];
 var coreMethodFields = ['push', 'replace', 'reload', 'back', 'prefetch', 'beforePopState']; // Events is a static property on the router, the router doesn't have to be initialized to use it
 
@@ -6759,7 +6694,7 @@ var coreMethodFields = ['push', 'replace', 'reload', 'back', 'prefetch', 'before
     return _router2["default"].events;
   }
 });
-urlPropertyFields.forEach(function (field) {
+propertyFields.concat(urlPropertyFields).forEach(function (field) {
   // Here we need to use Object.defineProperty because, we need to return
   // the property assigned to the actual router
   // The value might get changed as we change routes and this is the
@@ -6858,6 +6793,17 @@ function makePublicRouterInstance(router) {
 
 
   instance.events = _router2["default"].events;
+  propertyFields.forEach(function (field) {
+    // Here we need to use Object.defineProperty because, we need to return
+    // the property assigned to the actual router
+    // The value might get changed as we change routes and this is the
+    // proper way to access it
+    (0, _defineProperty["default"])(instance, field, {
+      get: function get() {
+        return _router[field];
+      }
+    });
+  });
   coreMethodFields.forEach(function (field) {
     instance[field] = function () {
       return _router[field].apply(_router, arguments);
Diff for mainModern.js
@@ -1,4 +1,4 @@
-(window["webpackJsonp"] = window["webpackJsonp"] || []).push([[8],{
+(window["webpackJsonp"] = window["webpackJsonp"] || []).push([[2],{
 
 /***/ "+iuc":
 /***/ (function(module, exports, __webpack_require__) {
@@ -495,30 +495,13 @@ function () {
         });
       }
     });
-    const renderCtx = {
+    render({
       App,
       Component,
       props,
       err: initialErr,
       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
@@ -2700,21 +2700,13 @@ class Router {
 
       const {
         pathname,
-        query,
-        protocol
-      } = url_1.parse(url, true);
-
-      if (!pathname || protocol) {
-        if (false) {}
-
-        return resolve(false);
-      } // If asked to change the current URL we should reload the current page
+        query
+      } = url_1.parse(url, true); // If asked to change the current URL we should reload the current page
       // (not location.reload() but reload getInitialProps and other Next.js stuffs)
       // We also need to set the method = replaceState always
       // as this should not go into the history (That's how browsers work)
       // We should compare the new asPath to the current asPath, not the url
 
-
       if (!this.urlIsNew(as)) {
         method = 'replaceState';
       } // @ts-ignore pathname is always a string
@@ -2953,19 +2945,11 @@ class Router {
 
   prefetch(url) {
     return new _promise.default((resolve, reject) => {
+      // Prefetch is not supported in development mode because it would trigger on-demand-entries
+      if (false) {}
       const {
-        pathname,
-        protocol
-      } = url_1.parse(url);
-
-      if (!pathname || protocol) {
-        if (false) {}
-
-        return;
-      } // Prefetch is not supported in development mode because it would trigger on-demand-entries
-
-
-      if (false) {} // @ts-ignore pathname is always defined
+        pathname
+      } = url_1.parse(url); // @ts-ignore pathname is always defined
 
       const route = toRoute(pathname);
       this.pageLoader.prefetch(route).then(resolve, reject);
@@ -3005,34 +2989,12 @@ class Router {
     const {
       Component: App
     } = this.components['/_app'];
-    let props;
-
-    if (Component.__NEXT_PRERENDER) {
-      const url = url_1.format({
-        pathname: ctx.asPath,
-        query: ctx.query
-      });
-      const res = 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
-        }
-      };
-    } else {
-      props = await utils_1.loadGetInitialProps(App, {
-        AppTree: this._wrapApp(App),
-        Component,
-        router: this,
-        ctx
-      });
-    }
+    const props = await utils_1.loadGetInitialProps(App, {
+      AppTree: this._wrapApp(App),
+      Component,
+      router: this,
+      ctx
+    });
 
     if (cancel === this.clc) {
       this.clc = null;
@@ -4901,7 +4863,8 @@ const singletonRouter = {
 
 }; // Create public properties and methods of the router in the singletonRouter
 
-const urlPropertyFields = ['pathname', 'route', 'query', 'asPath', 'components'];
+const urlPropertyFields = ['pathname', 'route', 'query', 'asPath'];
+const propertyFields = ['components'];
 const routerEvents = ['routeChangeStart', 'beforeHistoryChange', 'routeChangeComplete', 'routeChangeError', 'hashChangeStart', 'hashChangeComplete'];
 const coreMethodFields = ['push', 'replace', 'reload', 'back', 'prefetch', 'beforePopState']; // Events is a static property on the router, the router doesn't have to be initialized to use it
 
@@ -4911,7 +4874,7 @@ const coreMethodFields = ['push', 'replace', 'reload', 'back', 'prefetch', 'befo
   }
 
 });
-urlPropertyFields.forEach(field => {
+propertyFields.concat(urlPropertyFields).forEach(field => {
   // Here we need to use Object.defineProperty because, we need to return
   // the property assigned to the actual router
   // The value might get changed as we change routes and this is the
@@ -5007,6 +4970,18 @@ function makePublicRouterInstance(router) {
 
 
   instance.events = _router2.default.events;
+  propertyFields.forEach(field => {
+    // Here we need to use Object.defineProperty because, we need to return
+    // the property assigned to the actual router
+    // The value might get changed as we change routes and this is the
+    // proper way to access it
+    (0, _defineProperty.default)(instance, field, {
+      get() {
+        return _router[field];
+      }
+
+    });
+  });
   coreMethodFields.forEach(field => {
     instance[field] = function () {
       return _router[field](...arguments);

@lfades lfades changed the title Throw error if next export detects an API route Show warning if next export detects an API route Aug 8, 2019
@ijjk
Copy link
Member

ijjk commented Aug 9, 2019

Stats from current PR

Click to expand stats
zeit/next.js canary lfades/next.js api-export-error Change
Build Duration 20.3s 20.5s ⚠️ +238ms
node_modules Size 41.6 MB 41.6 MB ⚠️ +612 B
Total Bundle (main, webpack, commons) Size 214 kB 214 kB
Total Bundle (main, webpack, commons) gzip Size 70.3 kB 70.3 kB
Total Bundle (main, webpack, commons) Modern Size 188 kB 188 kB
Total Bundle (main, webpack, commons) Modern gzip Size 62.1 kB 62.1 kB
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.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 15.6 kB 15.6 kB
Client main gzip Size 5.5 kB 5.5 kB
Client main Modern Size 12.4 kB 12.4 kB
Client main Modern gzip Size 4.78 kB 4.78 kB
Client commons Size 195 kB 195 kB
Client commons gzip Size 63.5 kB 63.5 kB
Client commons Modern Size 176 kB 176 kB
Client commons Modern gzip Size 57.3 kB 57.3 kB
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
Click to expand serverless stats
zeit/next.js canary lfades/next.js api-export-error Change
Build Duration 22s 22.1s ⚠️ +76ms
node_modules Size 41.6 MB 41.6 MB ⚠️ +612 B
Total Bundle (main, webpack, commons) Size 214 kB 214 kB
Total Bundle (main, webpack, commons) gzip Size 70.3 kB 70.3 kB
Total Bundle (main, webpack, commons) Modern Size 188 kB 188 kB
Total Bundle (main, webpack, commons) Modern gzip Size 62.1 kB 62.1 kB
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.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 15.6 kB 15.6 kB
Client main gzip Size 5.5 kB 5.5 kB
Client main Modern Size 12.4 kB 12.4 kB
Client main Modern gzip Size 4.78 kB 4.78 kB
Client commons Size 195 kB 195 kB
Client commons gzip Size 63.5 kB 63.5 kB
Client commons Modern Size 176 kB 176 kB
Client commons Modern gzip Size 57.3 kB 57.3 kB
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
Serverless pages/link gzip Size 68.7 kB 68.7 kB ⚠️ +2 B
Serverless pages/index Size 248 kB 248 kB
Serverless pages/index gzip Size 66.4 kB 66.4 kB ⚠️ +2 B
Serverless pages/_error Size 248 kB 248 kB
Serverless pages/_error gzip Size 66.2 kB 66.2 kB
Serverless pages/routerDirect Size 249 kB 249 kB
Serverless pages/routerDirect gzip Size 66.4 kB 66.4 kB ⚠️ +1 B
Serverless pages/withRouter Size 249 kB 249 kB
Serverless pages/withRouter gzip Size 66.5 kB 66.5 kB ⚠️ +1 B
Build Dir Size 2.64 MB 2.64 MB

@timneutkens timneutkens merged commit 36aabe0 into vercel:canary Aug 11, 2019
@Timer Timer added this to the 9.0.4 milestone Aug 11, 2019
@lfades lfades deleted the api-export-error branch January 28, 2020 15:22
@lfades lfades restored the api-export-error branch January 28, 2020 15:23
@lfades lfades deleted the api-export-error branch January 28, 2020 15:27
@vercel vercel locked as resolved and limited conversation to collaborators Jan 31, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants