-
Notifications
You must be signed in to change notification settings - Fork 26.1k
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
Reduce router code #16159
Merged
Merged
Reduce router code #16159
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 PRDefault Server Mode (Increase detected
|
vercel/next.js canary | Timer/next.js check-drop-code | Change | |
---|---|---|---|
buildDuration | 12.8s | 13.1s | |
nodeModulesSize | 57.3 MB | 57.3 MB |
Page Load Tests Overall increase ✓
vercel/next.js canary | Timer/next.js check-drop-code | Change | |
---|---|---|---|
/ failed reqs | 0 | 0 | ✓ |
/ total time (seconds) | 2.215 | 2.232 | |
/ avg req/sec | 1128.47 | 1120.17 | |
/error-in-render failed reqs | 0 | 0 | ✓ |
/error-in-render total time (seconds) | 1.274 | 1.252 | -0.02 |
/error-in-render avg req/sec | 1962.17 | 1996.82 | +34.65 |
Client Bundles (main, webpack, commons) Overall decrease ✓
vercel/next.js canary | Timer/next.js check-drop-code | Change | |
---|---|---|---|
677f882d2ed8..a830.js gzip | 10.3 kB | 10.2 kB | -67 B |
framework.HASH.js gzip | 39.1 kB | 39.1 kB | ✓ |
main-50e55c1..9850.js gzip | 6.73 kB | 6.73 kB | ✓ |
webpack-ccf5..276a.js gzip | 751 B | 751 B | ✓ |
Overall change | 56.9 kB | 56.9 kB | -67 B |
Client Bundles (main, webpack, commons) Modern Overall decrease ✓
vercel/next.js canary | Timer/next.js check-drop-code | Change | |
---|---|---|---|
677f882d2ed8..dule.js gzip | 6.13 kB | 6.12 kB | -6 B |
framework.HA..dule.js gzip | 39.1 kB | 39.1 kB | ✓ |
main-7c4b50e..dule.js gzip | 5.82 kB | 5.82 kB | ✓ |
webpack-10c7..dule.js gzip | 751 B | 751 B | ✓ |
Overall change | 51.8 kB | 51.8 kB | -6 B |
Legacy Client Bundles (polyfills)
vercel/next.js canary | Timer/next.js check-drop-code | Change | |
---|---|---|---|
polyfills-75..1629.js gzip | 31 kB | 31 kB | ✓ |
Overall change | 31 kB | 31 kB | ✓ |
Client Pages
vercel/next.js canary | Timer/next.js check-drop-code | Change | |
---|---|---|---|
_app-874bd8a..0103.js gzip | 1.28 kB | 1.28 kB | ✓ |
_error-fa39c..ec40.js gzip | 3.45 kB | 3.45 kB | ✓ |
hooks-585f07..95a3.js gzip | 887 B | 887 B | ✓ |
index-c7b63f..fc02.js gzip | 227 B | 227 B | ✓ |
link-4c2bd9b..eadd.js gzip | 1.29 kB | 1.29 kB | ✓ |
routerDirect..ebc7.js gzip | 284 B | 284 B | ✓ |
withRouter-2..db68.js gzip | 284 B | 284 B | ✓ |
Overall change | 7.71 kB | 7.71 kB | ✓ |
Client Pages Modern
vercel/next.js canary | Timer/next.js check-drop-code | Change | |
---|---|---|---|
_app-97e743e..dule.js gzip | 626 B | 626 B | ✓ |
_error-b4004..dule.js gzip | 2.3 kB | 2.3 kB | ✓ |
hooks-696209..dule.js gzip | 387 B | 387 B | ✓ |
index-a4dd74..dule.js gzip | 226 B | 226 B | ✓ |
link-236a801..dule.js gzip | 1.26 kB | 1.26 kB | ✓ |
routerDirect..dule.js gzip | 284 B | 284 B | ✓ |
withRouter-1..dule.js gzip | 282 B | 282 B | ✓ |
Overall change | 5.37 kB | 5.37 kB | ✓ |
Client Build Manifests
vercel/next.js canary | Timer/next.js check-drop-code | Change | |
---|---|---|---|
_buildManifest.js gzip | 321 B | 321 B | ✓ |
_buildManife..dule.js gzip | 329 B | 329 B | ✓ |
Overall change | 650 B | 650 B | ✓ |
Rendered Page Sizes
vercel/next.js canary | Timer/next.js check-drop-code | Change | |
---|---|---|---|
index.html gzip | 946 B | 946 B | ✓ |
link.html gzip | 954 B | 953 B | -1 B |
withRouter.html gzip | 939 B | 940 B | |
Overall change | 2.84 kB | 2.84 kB | ✓ |
Diffs
Diff for 677f882d2ed8..37.module.js
@@ -1279,15 +1279,16 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
} // handle resolving href for dynamic routes
if (!pages.includes(cleanPathname)) {
- for (var page of pages) {
+ // eslint-disable-next-line array-callback-return
+ pages.some(page => {
if (
(0, _isDynamic.isDynamicRoute)(page) &&
(0, _routeRegex.getRouteRegex)(page).re.test(cleanPathname)
) {
parsedHref.pathname = addBasePath(page);
- break;
+ return true;
}
- }
+ });
}
return parsedHref;
Diff for 677f882d2ed8..a0f17105c.js
@@ -678,80 +678,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
var _createClass = __webpack_require__("W8MJ");
- function _createForOfIteratorHelper(o, allowArrayLike) {
- var it;
- if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
- if (
- Array.isArray(o) ||
- (it = _unsupportedIterableToArray(o)) ||
- (allowArrayLike && o && typeof o.length === "number")
- ) {
- if (it) o = it;
- var i = 0;
- var F = function F() {};
- return {
- s: F,
- n: function n() {
- if (i >= o.length) return { done: true };
- return { done: false, value: o[i++] };
- },
- e: function e(_e) {
- throw _e;
- },
- f: F
- };
- }
- throw new TypeError(
- "Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."
- );
- }
- var normalCompletion = true,
- didErr = false,
- err;
- return {
- s: function s() {
- it = o[Symbol.iterator]();
- },
- n: function n() {
- var step = it.next();
- normalCompletion = step.done;
- return step;
- },
- e: function e(_e2) {
- didErr = true;
- err = _e2;
- },
- f: function f() {
- try {
- if (!normalCompletion && it["return"] != null) it["return"]();
- } finally {
- if (didErr) throw err;
- }
- }
- };
- }
-
- function _unsupportedIterableToArray(o, minLen) {
- if (!o) return;
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
- var n = Object.prototype.toString.call(o).slice(8, -1);
- if (n === "Object" && o.constructor) n = o.constructor.name;
- if (n === "Map" || n === "Set") return Array.from(o);
- if (
- n === "Arguments" ||
- /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)
- )
- return _arrayLikeToArray(o, minLen);
- }
-
- function _arrayLikeToArray(arr, len) {
- if (len == null || len > arr.length) len = arr.length;
- for (var i = 0, arr2 = new Array(len); i < len; i++) {
- arr2[i] = arr[i];
- }
- return arr2;
- }
-
exports.__esModule = true;
exports.hasBasePath = hasBasePath;
exports.addBasePath = addBasePath;
@@ -1864,28 +1790,16 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
} // handle resolving href for dynamic routes
if (!pages.includes(cleanPathname)) {
- var _iterator = _createForOfIteratorHelper(pages),
- _step;
-
- try {
- for (_iterator.s(); !(_step = _iterator.n()).done; ) {
- var page = _step.value;
-
- if (
- (0, _isDynamic.isDynamicRoute)(page) &&
- (0, _routeRegex.getRouteRegex)(page).re.test(
- cleanPathname
- )
- ) {
- parsedHref.pathname = addBasePath(page);
- break;
- }
+ // eslint-disable-next-line array-callback-return
+ pages.some(function(page) {
+ if (
+ (0, _isDynamic.isDynamicRoute)(page) &&
+ (0, _routeRegex.getRouteRegex)(page).re.test(cleanPathname)
+ ) {
+ parsedHref.pathname = addBasePath(page);
+ return true;
}
- } catch (err) {
- _iterator.e(err);
- } finally {
- _iterator.f();
- }
+ });
}
return parsedHref;
@@ -2069,10 +1983,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
}
if (cancelled) {
- var _err = new Error("Loading initial props cancelled");
-
- _err.cancelled = true;
- throw _err;
+ var err = new Error("Loading initial props cancelled");
+ err.cancelled = true;
+ throw err;
}
return data;
Diff for index.html
@@ -24,7 +24,7 @@
/>
<link
rel="preload"
- href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.55dcddc4eb72216b9437.module.js"
+ href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.5020e365fe246cfb523c.module.js"
as="script"
crossorigin="anonymous"
/>
@@ -117,13 +117,13 @@
type="module"
></script>
<script
- src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.a0a2278c1e6a0f17105c.js"
+ src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.c4ee795a228846419646.js"
async=""
crossorigin="anonymous"
nomodule=""
></script>
<script
- src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.55dcddc4eb72216b9437.module.js"
+ src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.5020e365fe246cfb523c.module.js"
async=""
crossorigin="anonymous"
type="module"
Diff for link.html
@@ -24,7 +24,7 @@
/>
<link
rel="preload"
- href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.55dcddc4eb72216b9437.module.js"
+ href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.5020e365fe246cfb523c.module.js"
as="script"
crossorigin="anonymous"
/>
@@ -122,13 +122,13 @@
type="module"
></script>
<script
- src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.a0a2278c1e6a0f17105c.js"
+ src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.c4ee795a228846419646.js"
async=""
crossorigin="anonymous"
nomodule=""
></script>
<script
- src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.55dcddc4eb72216b9437.module.js"
+ src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.5020e365fe246cfb523c.module.js"
async=""
crossorigin="anonymous"
type="module"
Diff for withRouter.html
@@ -24,7 +24,7 @@
/>
<link
rel="preload"
- href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.55dcddc4eb72216b9437.module.js"
+ href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.5020e365fe246cfb523c.module.js"
as="script"
crossorigin="anonymous"
/>
@@ -117,13 +117,13 @@
type="module"
></script>
<script
- src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.a0a2278c1e6a0f17105c.js"
+ src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.c4ee795a228846419646.js"
async=""
crossorigin="anonymous"
nomodule=""
></script>
<script
- src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.55dcddc4eb72216b9437.module.js"
+ src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.5020e365fe246cfb523c.module.js"
async=""
crossorigin="anonymous"
type="module"
Serverless Mode (Increase detected ⚠️ )
General Overall increase ⚠️
vercel/next.js canary | Timer/next.js check-drop-code | Change | |
---|---|---|---|
buildDuration | 14.8s | 14.8s | |
nodeModulesSize | 57.3 MB | 57.3 MB |
Client Bundles (main, webpack, commons) Overall decrease ✓
vercel/next.js canary | Timer/next.js check-drop-code | Change | |
---|---|---|---|
677f882d2ed8..a830.js gzip | 10.3 kB | N/A | N/A |
framework.HASH.js gzip | 39.1 kB | 39.1 kB | ✓ |
main-50e55c1..9850.js gzip | 6.73 kB | 6.73 kB | ✓ |
webpack-ccf5..276a.js gzip | 751 B | 751 B | ✓ |
677f882d2ed8..c139.js gzip | N/A | 10.2 kB | N/A |
Overall change | 56.9 kB | 56.9 kB | -67 B |
Client Bundles (main, webpack, commons) Modern Overall decrease ✓
vercel/next.js canary | Timer/next.js check-drop-code | Change | |
---|---|---|---|
677f882d2ed8..dule.js gzip | 6.13 kB | N/A | N/A |
framework.HA..dule.js gzip | 39.1 kB | 39.1 kB | ✓ |
main-7c4b50e..dule.js gzip | 5.82 kB | 5.82 kB | ✓ |
webpack-10c7..dule.js gzip | 751 B | 751 B | ✓ |
677f882d2ed8..dule.js gzip | N/A | 6.12 kB | N/A |
Overall change | 51.8 kB | 51.8 kB | -6 B |
Legacy Client Bundles (polyfills)
vercel/next.js canary | Timer/next.js check-drop-code | Change | |
---|---|---|---|
polyfills-75..1629.js gzip | 31 kB | 31 kB | ✓ |
Overall change | 31 kB | 31 kB | ✓ |
Client Pages
vercel/next.js canary | Timer/next.js check-drop-code | Change | |
---|---|---|---|
_app-874bd8a..0103.js gzip | 1.28 kB | 1.28 kB | ✓ |
_error-fa39c..ec40.js gzip | 3.45 kB | 3.45 kB | ✓ |
hooks-585f07..95a3.js gzip | 887 B | 887 B | ✓ |
index-c7b63f..fc02.js gzip | 227 B | 227 B | ✓ |
link-4c2bd9b..eadd.js gzip | 1.29 kB | 1.29 kB | ✓ |
routerDirect..ebc7.js gzip | 284 B | 284 B | ✓ |
withRouter-2..db68.js gzip | 284 B | 284 B | ✓ |
Overall change | 7.71 kB | 7.71 kB | ✓ |
Client Pages Modern
vercel/next.js canary | Timer/next.js check-drop-code | Change | |
---|---|---|---|
_app-97e743e..dule.js gzip | 626 B | 626 B | ✓ |
_error-b4004..dule.js gzip | 2.3 kB | 2.3 kB | ✓ |
hooks-696209..dule.js gzip | 387 B | 387 B | ✓ |
index-a4dd74..dule.js gzip | 226 B | 226 B | ✓ |
link-236a801..dule.js gzip | 1.26 kB | 1.26 kB | ✓ |
routerDirect..dule.js gzip | 284 B | 284 B | ✓ |
withRouter-1..dule.js gzip | 282 B | 282 B | ✓ |
Overall change | 5.37 kB | 5.37 kB | ✓ |
Client Build Manifests
vercel/next.js canary | Timer/next.js check-drop-code | Change | |
---|---|---|---|
_buildManifest.js gzip | 321 B | 321 B | ✓ |
_buildManife..dule.js gzip | 329 B | 329 B | ✓ |
Overall change | 650 B | 650 B | ✓ |
Serverless bundles Overall increase ⚠️
vercel/next.js canary | Timer/next.js check-drop-code | Change | |
---|---|---|---|
_error.js | 1.03 MB | 1.03 MB | ✓ |
404.html | 4.18 kB | 4.18 kB | ✓ |
hooks.html | 3.82 kB | 3.82 kB | ✓ |
index.js | 1.03 MB | 1.03 MB | ✓ |
link.js | 1.07 MB | 1.07 MB | |
routerDirect.js | 1.06 MB | 1.06 MB | |
withRouter.js | 1.06 MB | 1.06 MB | |
Overall change | 5.26 MB | 5.26 MB |
Ah I totally missed that 👀 |
timneutkens
approved these changes
Aug 13, 2020
m-lautenbach
pushed a commit
to m-lautenbach/next.js
that referenced
this pull request
Aug 20, 2020
This reduces the code as suggested: vercel#15231 (comment). Removes these bloated Babel helpers: ```diff @@ -678,80 +678,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI var _createClass = __webpack_require__("W8MJ"); - function _createForOfIteratorHelper(o, allowArrayLike) { - var it; - if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { - if ( - Array.isArray(o) || - (it = _unsupportedIterableToArray(o)) || - (allowArrayLike && o && typeof o.length === "number") - ) { - if (it) o = it; - var i = 0; - var F = function F() {}; - return { - s: F, - n: function n() { - if (i >= o.length) return { done: true }; - return { done: false, value: o[i++] }; - }, - e: function e(_e) { - throw _e; - }, - f: F - }; - } - throw new TypeError( - "Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method." - ); - } - var normalCompletion = true, - didErr = false, - err; - return { - s: function s() { - it = o[Symbol.iterator](); - }, - n: function n() { - var step = it.next(); - normalCompletion = step.done; - return step; - }, - e: function e(_e2) { - didErr = true; - err = _e2; - }, - f: function f() { - try { - if (!normalCompletion && it["return"] != null) it["return"](); - } finally { - if (didErr) throw err; - } - } - }; - } - - function _unsupportedIterableToArray(o, minLen) { - if (!o) return; - if (typeof o === "string") return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if (n === "Object" && o.constructor) n = o.constructor.name; - if (n === "Map" || n === "Set") return Array.from(o); - if ( - n === "Arguments" || - /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n) - ) - return _arrayLikeToArray(o, minLen); - } - - function _arrayLikeToArray(arr, len) { - if (len == null || len > arr.length) len = arr.length; - for (var i = 0, arr2 = new Array(len); i < len; i++) { - arr2[i] = arr[i]; - } - return arr2; - } - exports.__esModule = true; exports.hasBasePath = hasBasePath; exports.addBasePath = addBasePath; @@ -1864,28 +1790,16 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI } // handle resolving href for dynamic routes if (!pages.includes(cleanPathname)) { - var _iterator = _createForOfIteratorHelper(pages), - _step; - - try { - for (_iterator.s(); !(_step = _iterator.n()).done; ) { - var page = _step.value; - - if ( - (0, _isDynamic.isDynamicRoute)(page) && - (0, _routeRegex.getRouteRegex)(page).re.test( - cleanPathname - ) - ) { - parsedHref.pathname = addBasePath(page); - break; - } + // eslint-disable-next-line array-callback-return + pages.some(function(page) { + if ( + (0, _isDynamic.isDynamicRoute)(page) && + (0, _routeRegex.getRouteRegex)(page).re.test(cleanPathname) + ) { + parsedHref.pathname = addBasePath(page); + return true; } - } catch (err) { - _iterator.e(err); - } finally { - _iterator.f(); - } + }); } return parsedHref; @@ -2069,10 +1983,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI } if (cancelled) { - var _err = new Error("Loading initial props cancelled"); - - _err.cancelled = true; - throw _err; + var err = new Error("Loading initial props cancelled"); + err.cancelled = true; + throw err; } return data; ```
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.
This reduces the code as suggested: #15231 (comment).
Removes these bloated Babel helpers: