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
+66
−24
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Stats from current PRClick to expand stats
Click to expand serverless stats
|
Stats from current PRClick to expand stats
Click to expand serverless stats
|
Stats from current PRClick to expand stats
Click to expand serverless stats
|
Stats from current PRClick to expand stats
Click to expand serverless stats
|
huv1k
suggested changes
Aug 6, 2019
There was a problem hiding this 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.
I would remove the routes from defaultPathMap, but show a warning indeed. |
Stats from current PRClick to expand stats ✅ Total Bundle Size Decrease ✅
Click to expand serverless stats ✅ Total Bundle Size Decrease ✅
Diff for main.js@@ -1,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
changed the title
Throw error if next export detects an API route
Show warning if next export detects an API route
Aug 8, 2019
Stats from current PRClick to expand stats
Click to expand serverless stats
|
timneutkens
approved these changes
Aug 11, 2019
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
.