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

Make sure to handle improperly encoded URLs #11533

Closed
wants to merge 3 commits into from

Conversation

ijjk
Copy link
Member

@ijjk ijjk commented Mar 31, 2020

When an improperly encoded URL is visited such as http://localhost:3000/% it causes an error to be thrown from failing to decode the URL params.

URIError: URI malformed
    at decodeURIComponent (<anonymous>)
    at /Users/jj/dev/zeit/next.js/test/integration/dynamic-routing/.next/serverless/pages/[name].js:776:114
    at Array.forEach (<anonymous>)
    at /Users/jj/dev/zeit/next.js/test/integration/dynamic-routing/.next/serverless/pages/[name].js:771:25
    at renderReqToHTML (/Users/jj/dev/zeit/next.js/test/integration/dynamic-routing/.next/serverless/pages/[name].js:4184:84)
    at Module.render (/Users/jj/dev/zeit/next.js/test/integration/dynamic-routing/.next/serverless/pages/[name].js:4265:28)

To handle this gracefully this implements the safe-decode-uri-component package. I added the initial URL that showed this behavior as a test in the dynamic-routing suite, if there are others that should be added let me know and we can get them tested also

@ijjk ijjk added this to the 9.3.4 milestone Mar 31, 2020
@ijjk
Copy link
Member Author

ijjk commented Mar 31, 2020

Stats from current PR

Default Server Mode (Increase detected ⚠️)
General Overall increase ⚠️
zeit/next.js canary ijjk/next.js add/NEXT-156 Change
buildDuration 10.4s 10.1s -219ms
nodeModulesSize 47.7 MB 47.8 MB ⚠️ +62.9 kB
Client Bundles (main, webpack, commons) Overall increase ⚠️
zeit/next.js canary ijjk/next.js add/NEXT-156 Change
main-HASH.js gzip 6.25 kB 6.25 kB
webpack-HASH.js gzip 746 B 746 B
de003c3a9d30..c6c1.js gzip 10.1 kB N/A N/A
framework.HASH.js gzip 39.1 kB 39.1 kB
de003c3a9d30..e6ba.js gzip N/A 10.6 kB N/A
Overall change 56.3 kB 56.7 kB ⚠️ +485 B
Client Bundles (main, webpack, commons) Modern Overall increase ⚠️
zeit/next.js canary ijjk/next.js add/NEXT-156 Change
main-HASH.module.js gzip 4.78 kB 4.78 kB
webpack-HASH..dule.js gzip 746 B 746 B
de003c3a9d30..dule.js gzip 6.71 kB N/A N/A
framework.HA..dule.js gzip 39.1 kB 39.1 kB
de003c3a9d30..dule.js gzip N/A 7.19 kB N/A
Overall change 51.4 kB 51.9 kB ⚠️ +486 B
Legacy Client Bundles (polyfills)
zeit/next.js canary ijjk/next.js add/NEXT-156 Change
polyfills-HASH.js gzip 26.3 kB 26.3 kB
Overall change 26.3 kB 26.3 kB
Client Pages
zeit/next.js canary ijjk/next.js add/NEXT-156 Change
_app.js gzip 1.24 kB 1.24 kB
_error.js gzip 3.15 kB 3.15 kB
hooks.js gzip 664 B 664 B
index.js gzip 222 B 222 B
link.js gzip 2.03 kB 2.03 kB
routerDirect.js gzip 279 B 279 B
withRouter.js gzip 278 B 278 B
Overall change 7.86 kB 7.86 kB
Client Pages Modern
zeit/next.js canary ijjk/next.js add/NEXT-156 Change
_app.module.js gzip 594 B 594 B
_error.module.js gzip 2.08 kB 2.08 kB
hooks.module.js gzip 370 B 370 B
index.module.js gzip 212 B 212 B
link.module.js gzip 1.48 kB 1.48 kB
routerDirect..dule.js gzip 271 B 271 B
withRouter.m..dule.js gzip 270 B 270 B
Overall change 5.28 kB 5.28 kB
Client Build Manifests
zeit/next.js canary ijjk/next.js add/NEXT-156 Change
_buildManifest.js gzip 61 B 61 B
_buildManife..dule.js gzip 61 B 61 B
Overall change 122 B 122 B
Rendered Page Sizes Overall decrease ✓
zeit/next.js canary ijjk/next.js add/NEXT-156 Change
index.html gzip 919 B 918 B -1 B
link.html gzip 927 B 929 B ⚠️ +2 B
withRouter.html gzip 917 B 915 B -2 B
Overall change 2.76 kB 2.76 kB -1 B

Diffs

Diff for link.html
@@ -1 +1 @@
-<!DOCTYPE html><html><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width"/><meta name="next-head-count" content="2"/><link rel="preload" href="/_next/static/BUILD_ID/pages/link.module.js" as="script" crossorigin="anonymous"/><link rel="preload" href="/_next/static/BUILD_ID/pages/_app.module.js" as="script" crossorigin="anonymous"/><link rel="preload" href="/_next/static/runtime/webpack-d629b83a65f3e33fa99e.module.js" as="script" crossorigin="anonymous"/><link rel="preload" href="/_next/static/chunks/framework.5bb7f30f859f5f31359f.module.js" as="script" crossorigin="anonymous"/><link rel="preload" href="/_next/static/chunks/de003c3a9d308750aa009870a5926f9b18ab31f4.d8f88b74aefd825bf023.module.js" as="script" crossorigin="anonymous"/><link rel="preload" href="/_next/static/runtime/main-f68f05515eff91645605.module.js" as="script" crossorigin="anonymous"/></head><body><div id="__next"><div><h3>A Link page!</h3><a href="/">Go to /</a></div></div><script id="__NEXT_DATA__" type="application/json" crossorigin="anonymous">{"props":{"pageProps":{}},"page":"/link","query":{},"buildId":"BUILD_ID","isFallback":false}</script><script crossorigin="anonymous" nomodule="">!function(){var e=document,t=e.createElement("script");if(!("noModule"in t)&&"onbeforeload"in t){var n=!1;e.addEventListener("beforeload",function(e){if(e.target===t)n=!0;else if(!e.target.hasAttribute("nomodule")||!n)return;e.preventDefault()},!0),t.type="module",t.src=".",e.head.appendChild(t),t.remove()}}();</script><script crossorigin="anonymous" nomodule="" src="/_next/static/runtime/polyfills-51838dc5b2b8e0705281.js"></script><script async="" data-next-page="/link" src="/_next/static/BUILD_ID/pages/link.js" crossorigin="anonymous" nomodule=""></script><script async="" data-next-page="/link" src="/_next/static/BUILD_ID/pages/link.module.js" crossorigin="anonymous" type="module"></script><script async="" data-next-page="/_app" src="/_next/static/BUILD_ID/pages/_app.js" crossorigin="anonymous" nomodule=""></script><script async="" data-next-page="/_app" src="/_next/static/BUILD_ID/pages/_app.module.js" crossorigin="anonymous" type="module"></script><script src="/_next/static/runtime/webpack-4d739ac7b0d8f888ab18.js" async="" crossorigin="anonymous" nomodule=""></script><script src="/_next/static/runtime/webpack-d629b83a65f3e33fa99e.module.js" async="" crossorigin="anonymous" type="module"></script><script src="/_next/static/chunks/framework.5bb7f30f859f5f31359f.js" async="" crossorigin="anonymous" nomodule=""></script><script src="/_next/static/chunks/framework.5bb7f30f859f5f31359f.module.js" async="" crossorigin="anonymous" type="module"></script><script src="/_next/static/chunks/de003c3a9d308750aa009870a5926f9b18ab31f4.d70844b46f3177e37fca.js" async="" crossorigin="anonymous" nomodule=""></script><script src="/_next/static/chunks/de003c3a9d308750aa009870a5926f9b18ab31f4.d8f88b74aefd825bf023.module.js" async="" crossorigin="anonymous" type="module"></script><script src="/_next/static/runtime/main-1863b30ecf58cb26de5f.js" async="" crossorigin="anonymous" nomodule=""></script><script src="/_next/static/runtime/main-f68f05515eff91645605.module.js" async="" crossorigin="anonymous" type="module"></script><script src="/_next/static/BUILD_ID/_buildManifest.js" async="" crossorigin="anonymous" nomodule=""></script><script src="/_next/static/BUILD_ID/_buildManifest.module.js" async="" crossorigin="anonymous" type="module"></script><script src="/_next/static/BUILD_ID/_ssgManifest.js" async="" crossorigin="anonymous" nomodule=""></script><script src="/_next/static/BUILD_ID/_ssgManifest.module.js" async="" crossorigin="anonymous" type="module"></script></body></html>
\ No newline at end of file
+<!DOCTYPE html><html><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width"/><meta name="next-head-count" content="2"/><link rel="preload" href="/_next/static/BUILD_ID/pages/link.module.js" as="script" crossorigin="anonymous"/><link rel="preload" href="/_next/static/BUILD_ID/pages/_app.module.js" as="script" crossorigin="anonymous"/><link rel="preload" href="/_next/static/runtime/webpack-d629b83a65f3e33fa99e.module.js" as="script" crossorigin="anonymous"/><link rel="preload" href="/_next/static/chunks/framework.5bb7f30f859f5f31359f.module.js" as="script" crossorigin="anonymous"/><link rel="preload" href="/_next/static/chunks/de003c3a9d308750aa009870a5926f9b18ab31f4.bc2d044661db40396778.module.js" as="script" crossorigin="anonymous"/><link rel="preload" href="/_next/static/runtime/main-f68f05515eff91645605.module.js" as="script" crossorigin="anonymous"/></head><body><div id="__next"><div><h3>A Link page!</h3><a href="/">Go to /</a></div></div><script id="__NEXT_DATA__" type="application/json" crossorigin="anonymous">{"props":{"pageProps":{}},"page":"/link","query":{},"buildId":"BUILD_ID","isFallback":false}</script><script crossorigin="anonymous" nomodule="">!function(){var e=document,t=e.createElement("script");if(!("noModule"in t)&&"onbeforeload"in t){var n=!1;e.addEventListener("beforeload",function(e){if(e.target===t)n=!0;else if(!e.target.hasAttribute("nomodule")||!n)return;e.preventDefault()},!0),t.type="module",t.src=".",e.head.appendChild(t),t.remove()}}();</script><script crossorigin="anonymous" nomodule="" src="/_next/static/runtime/polyfills-51838dc5b2b8e0705281.js"></script><script async="" data-next-page="/link" src="/_next/static/BUILD_ID/pages/link.js" crossorigin="anonymous" nomodule=""></script><script async="" data-next-page="/link" src="/_next/static/BUILD_ID/pages/link.module.js" crossorigin="anonymous" type="module"></script><script async="" data-next-page="/_app" src="/_next/static/BUILD_ID/pages/_app.js" crossorigin="anonymous" nomodule=""></script><script async="" data-next-page="/_app" src="/_next/static/BUILD_ID/pages/_app.module.js" crossorigin="anonymous" type="module"></script><script src="/_next/static/runtime/webpack-4d739ac7b0d8f888ab18.js" async="" crossorigin="anonymous" nomodule=""></script><script src="/_next/static/runtime/webpack-d629b83a65f3e33fa99e.module.js" async="" crossorigin="anonymous" type="module"></script><script src="/_next/static/chunks/framework.5bb7f30f859f5f31359f.js" async="" crossorigin="anonymous" nomodule=""></script><script src="/_next/static/chunks/framework.5bb7f30f859f5f31359f.module.js" async="" crossorigin="anonymous" type="module"></script><script src="/_next/static/chunks/de003c3a9d308750aa009870a5926f9b18ab31f4.0d0dc712562cbd9b5d66.js" async="" crossorigin="anonymous" nomodule=""></script><script src="/_next/static/chunks/de003c3a9d308750aa009870a5926f9b18ab31f4.bc2d044661db40396778.module.js" async="" crossorigin="anonymous" type="module"></script><script src="/_next/static/runtime/main-1863b30ecf58cb26de5f.js" async="" crossorigin="anonymous" nomodule=""></script><script src="/_next/static/runtime/main-f68f05515eff91645605.module.js" async="" crossorigin="anonymous" type="module"></script><script src="/_next/static/BUILD_ID/_buildManifest.js" async="" crossorigin="anonymous" nomodule=""></script><script src="/_next/static/BUILD_ID/_buildManifest.module.js" async="" crossorigin="anonymous" type="module"></script><script src="/_next/static/BUILD_ID/_ssgManifest.js" async="" crossorigin="anonymous" nomodule=""></script><script src="/_next/static/BUILD_ID/_ssgManifest.module.js" async="" crossorigin="anonymous" type="module"></script></body></html>
\ No newline at end of file
Diff for de003c3a9d30..23.module.js
@@ -222,6 +222,131 @@ var e,t=(e=__webpack_require__("s4NR"))&&"object"==typeof e&&"default"in e?e.def
 //# sourceMappingURL=index.js.map
 
 
+/***/ }),
+
+/***/ "TVkt":
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+
+module.exports = function decodeURIComponent(string) {
+  var k = string.indexOf('%');
+  if (k === -1) return string;
+
+  var length = string.length;
+  var decoded = '';
+  var last = 0;
+  var codepoint = 0;
+  var startOfOctets = k;
+  state = UTF8_ACCEPT;
+
+  while (k > -1 && k < length - 2) {
+    var high = hexCodeToInt(string[k + 1], 4);
+    var low = hexCodeToInt(string[k + 2], 0);
+    codepoint = decode(codepoint, high | low);
+
+    switch (state) {
+      case UTF8_ACCEPT:
+        decoded += string.substring(last, startOfOctets);
+
+        decoded += (codepoint <= 0xFFFF) ?
+          String.fromCharCode(codepoint) :
+          String.fromCharCode(
+            (0xD7C0 + (codepoint >> 10)),
+            (0xDC00 + (codepoint & 0x3FF))
+          );
+
+        codepoint = 0;
+        last = k + 3;
+        k = startOfOctets = string.indexOf('%', last);
+        break;
+      default:
+        k += 3;
+        if (k < length && string[k] === '%') break;
+
+        // Intentional fall-through
+      case UTF8_REJECT:
+        state = UTF8_ACCEPT;
+        codepoint = 0;
+        k = startOfOctets = string.indexOf('%', startOfOctets + 1);
+        break;
+    }
+  }
+
+  return decoded + string.substring(last);
+};
+
+var HEX = Object.assign(Object.create(null), {
+  '0':  0, '1':  1,
+  '2':  2, '3':  3,
+  '4':  4, '5':  5,
+  '6':  6, '7':  7,
+  '8':  8, '9':  9,
+  'a': 10, 'A': 10,
+  'b': 11, 'B': 11,
+  'c': 12, 'C': 12,
+  'd': 13, 'D': 13,
+  'e': 14, 'E': 14,
+  'f': 15, 'F': 15,
+});
+function hexCodeToInt(c, shift) {
+  var i = HEX[c];
+  return i === undefined ? 255 : i << shift;
+}
+
+
+/**
+ * The below algorithm is based on Bjoern Hoehrmann's DFA Unicode Decoder.
+ * Copyright (c) 2008-2009 Bjoern Hoehrmann <bjoern@hoehrmann.de>
+ * See http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ for details.
+ */
+var UTF8_ACCEPT = 12;
+var UTF8_REJECT = 0;
+var UTF8_DATA = [
+  // The first part of the table maps bytes to character to a transition.
+   0, 0, 0, 0,  0, 0, 0, 0,   0, 0, 0, 0, 0, 0, 0, 0,
+   0, 0, 0, 0,  0, 0, 0, 0,   0, 0, 0, 0, 0, 0, 0, 0,
+   0, 0, 0, 0,  0, 0, 0, 0,   0, 0, 0, 0, 0, 0, 0, 0,
+   0, 0, 0, 0,  0, 0, 0, 0,   0, 0, 0, 0, 0, 0, 0, 0,
+   0, 0, 0, 0,  0, 0, 0, 0,   0, 0, 0, 0, 0, 0, 0, 0,
+   0, 0, 0, 0,  0, 0, 0, 0,   0, 0, 0, 0, 0, 0, 0, 0,
+   0, 0, 0, 0,  0, 0, 0, 0,   0, 0, 0, 0, 0, 0, 0, 0,
+   0, 0, 0, 0,  0, 0, 0, 0,   0, 0, 0, 0, 0, 0, 0, 0,
+   1, 1, 1, 1,  1, 1, 1, 1,   1, 1, 1, 1, 1, 1, 1, 1,
+   2, 2, 2, 2,  2, 2, 2, 2,   2, 2, 2, 2, 2, 2, 2, 2,
+   3, 3, 3, 3,  3, 3, 3, 3,   3, 3, 3, 3, 3, 3, 3, 3,
+   3, 3, 3, 3,  3, 3, 3, 3,   3, 3, 3, 3, 3, 3, 3, 3,
+   4, 4, 5, 5,  5, 5, 5, 5,   5, 5, 5, 5, 5, 5, 5, 5,
+   5, 5, 5, 5,  5, 5, 5, 5,   5, 5, 5, 5, 5, 5, 5, 5,
+   6, 7, 7, 7,  7, 7, 7, 7,   7, 7, 7, 7, 7, 8, 7, 7,
+  10, 9, 9, 9, 11, 4, 4, 4,   4, 4, 4, 4, 4, 4, 4, 4,
+
+  // The second part of the table maps a state to a new state when adding a
+  // transition.
+   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
+  12,  0,  0,  0,  0, 24, 36, 48, 60, 72, 84, 96,
+   0, 12, 12, 12,  0,  0,  0,  0,  0,  0,  0,  0,
+   0,  0,  0, 24,  0,  0,  0,  0,  0,  0,  0,  0,
+   0, 24, 24, 24,  0,  0,  0,  0,  0,  0,  0,  0,
+   0, 24, 24,  0,  0,  0,  0,  0,  0,  0,  0,  0,
+   0, 48, 48, 48,  0,  0,  0,  0,  0,  0,  0,  0,
+   0,  0, 48, 48,  0,  0,  0,  0,  0,  0,  0,  0,
+   0, 48,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
+
+  // The third part maps the current transition to a mask that needs to apply
+  // to the byte.
+  0x7F, 0x3F, 0x3F, 0x3F, 0x00, 0x1F, 0x0F, 0x0F, 0x0F, 0x07, 0x07, 0x07,
+];
+
+var state = UTF8_ACCEPT;
+function decode(codepoint, byte) {
+  var type = UTF8_DATA[byte];
+  state = UTF8_DATA[256 + state + type];
+  return (codepoint << 6) | (byte & UTF8_DATA[364 + type]);
+}
+
+
 /***/ }),
 
 /***/ "TqRt":
@@ -1160,9 +1285,17 @@ exports.ST = exports.SP && typeof performance.mark === 'function' && typeof perf
 "use strict";
 
 
+var __importDefault = this && this.__importDefault || function (mod) {
+  return mod && mod.__esModule ? mod : {
+    "default": mod
+  };
+};
+
 Object.defineProperty(exports, "__esModule", {
   value: true
-});
+}); // @ts-ignore no types
+
+var safe_decode_uri_component_1 = __importDefault(__webpack_require__("TVkt"));
 
 function getRouteMatcher(routeRegex) {
   var {
@@ -1176,7 +1309,7 @@ function getRouteMatcher(routeRegex) {
       return false;
     }
 
-    var decode = decodeURIComponent;
+    var decode = safe_decode_uri_component_1.default;
     var params = {};
     Object.keys(groups).forEach(slugName => {
       var g = groups[slugName];
Diff for de003c3a9d30..177e37fca.js
@@ -255,6 +255,131 @@ function _setPrototypeOf(o, p) {
 
 module.exports = _setPrototypeOf;
 
+/***/ }),
+
+/***/ "TVkt":
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+
+module.exports = function decodeURIComponent(string) {
+  var k = string.indexOf('%');
+  if (k === -1) return string;
+
+  var length = string.length;
+  var decoded = '';
+  var last = 0;
+  var codepoint = 0;
+  var startOfOctets = k;
+  state = UTF8_ACCEPT;
+
+  while (k > -1 && k < length - 2) {
+    var high = hexCodeToInt(string[k + 1], 4);
+    var low = hexCodeToInt(string[k + 2], 0);
+    codepoint = decode(codepoint, high | low);
+
+    switch (state) {
+      case UTF8_ACCEPT:
+        decoded += string.substring(last, startOfOctets);
+
+        decoded += (codepoint <= 0xFFFF) ?
+          String.fromCharCode(codepoint) :
+          String.fromCharCode(
+            (0xD7C0 + (codepoint >> 10)),
+            (0xDC00 + (codepoint & 0x3FF))
+          );
+
+        codepoint = 0;
+        last = k + 3;
+        k = startOfOctets = string.indexOf('%', last);
+        break;
+      default:
+        k += 3;
+        if (k < length && string[k] === '%') break;
+
+        // Intentional fall-through
+      case UTF8_REJECT:
+        state = UTF8_ACCEPT;
+        codepoint = 0;
+        k = startOfOctets = string.indexOf('%', startOfOctets + 1);
+        break;
+    }
+  }
+
+  return decoded + string.substring(last);
+};
+
+var HEX = Object.assign(Object.create(null), {
+  '0':  0, '1':  1,
+  '2':  2, '3':  3,
+  '4':  4, '5':  5,
+  '6':  6, '7':  7,
+  '8':  8, '9':  9,
+  'a': 10, 'A': 10,
+  'b': 11, 'B': 11,
+  'c': 12, 'C': 12,
+  'd': 13, 'D': 13,
+  'e': 14, 'E': 14,
+  'f': 15, 'F': 15,
+});
+function hexCodeToInt(c, shift) {
+  var i = HEX[c];
+  return i === undefined ? 255 : i << shift;
+}
+
+
+/**
+ * The below algorithm is based on Bjoern Hoehrmann's DFA Unicode Decoder.
+ * Copyright (c) 2008-2009 Bjoern Hoehrmann <bjoern@hoehrmann.de>
+ * See http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ for details.
+ */
+var UTF8_ACCEPT = 12;
+var UTF8_REJECT = 0;
+var UTF8_DATA = [
+  // The first part of the table maps bytes to character to a transition.
+   0, 0, 0, 0,  0, 0, 0, 0,   0, 0, 0, 0, 0, 0, 0, 0,
+   0, 0, 0, 0,  0, 0, 0, 0,   0, 0, 0, 0, 0, 0, 0, 0,
+   0, 0, 0, 0,  0, 0, 0, 0,   0, 0, 0, 0, 0, 0, 0, 0,
+   0, 0, 0, 0,  0, 0, 0, 0,   0, 0, 0, 0, 0, 0, 0, 0,
+   0, 0, 0, 0,  0, 0, 0, 0,   0, 0, 0, 0, 0, 0, 0, 0,
+   0, 0, 0, 0,  0, 0, 0, 0,   0, 0, 0, 0, 0, 0, 0, 0,
+   0, 0, 0, 0,  0, 0, 0, 0,   0, 0, 0, 0, 0, 0, 0, 0,
+   0, 0, 0, 0,  0, 0, 0, 0,   0, 0, 0, 0, 0, 0, 0, 0,
+   1, 1, 1, 1,  1, 1, 1, 1,   1, 1, 1, 1, 1, 1, 1, 1,
+   2, 2, 2, 2,  2, 2, 2, 2,   2, 2, 2, 2, 2, 2, 2, 2,
+   3, 3, 3, 3,  3, 3, 3, 3,   3, 3, 3, 3, 3, 3, 3, 3,
+   3, 3, 3, 3,  3, 3, 3, 3,   3, 3, 3, 3, 3, 3, 3, 3,
+   4, 4, 5, 5,  5, 5, 5, 5,   5, 5, 5, 5, 5, 5, 5, 5,
+   5, 5, 5, 5,  5, 5, 5, 5,   5, 5, 5, 5, 5, 5, 5, 5,
+   6, 7, 7, 7,  7, 7, 7, 7,   7, 7, 7, 7, 7, 8, 7, 7,
+  10, 9, 9, 9, 11, 4, 4, 4,   4, 4, 4, 4, 4, 4, 4, 4,
+
+  // The second part of the table maps a state to a new state when adding a
+  // transition.
+   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
+  12,  0,  0,  0,  0, 24, 36, 48, 60, 72, 84, 96,
+   0, 12, 12, 12,  0,  0,  0,  0,  0,  0,  0,  0,
+   0,  0,  0, 24,  0,  0,  0,  0,  0,  0,  0,  0,
+   0, 24, 24, 24,  0,  0,  0,  0,  0,  0,  0,  0,
+   0, 24, 24,  0,  0,  0,  0,  0,  0,  0,  0,  0,
+   0, 48, 48, 48,  0,  0,  0,  0,  0,  0,  0,  0,
+   0,  0, 48, 48,  0,  0,  0,  0,  0,  0,  0,  0,
+   0, 48,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
+
+  // The third part maps the current transition to a mask that needs to apply
+  // to the byte.
+  0x7F, 0x3F, 0x3F, 0x3F, 0x00, 0x1F, 0x0F, 0x0F, 0x0F, 0x07, 0x07, 0x07,
+];
+
+var state = UTF8_ACCEPT;
+function decode(codepoint, byte) {
+  var type = UTF8_DATA[byte];
+  state = UTF8_DATA[256 + state + type];
+  return (codepoint << 6) | (byte & UTF8_DATA[364 + type]);
+}
+
+
 /***/ }),
 
 /***/ "TqRt":
@@ -1339,9 +1464,17 @@ exports.ST = exports.SP && typeof performance.mark === 'function' && typeof perf
 "use strict";
 
 
+var __importDefault = this && this.__importDefault || function (mod) {
+  return mod && mod.__esModule ? mod : {
+    "default": mod
+  };
+};
+
 Object.defineProperty(exports, "__esModule", {
   value: true
-});
+}); // @ts-ignore no types
+
+var safe_decode_uri_component_1 = __importDefault(__webpack_require__("TVkt"));
 
 function getRouteMatcher(routeRegex) {
   var re = routeRegex.re,
@@ -1353,7 +1486,7 @@ function getRouteMatcher(routeRegex) {
       return false;
     }
 
-    var decode = decodeURIComponent;
+    var decode = safe_decode_uri_component_1["default"];
     var params = {};
     Object.keys(groups).forEach(function (slugName) {
       var g = groups[slugName];
Diff for index.html
@@ -1 +1 @@
-<!DOCTYPE html><html><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width"/><meta name="next-head-count" content="2"/><link rel="preload" href="/_next/static/BUILD_ID/pages/index.module.js" as="script" crossorigin="anonymous"/><link rel="preload" href="/_next/static/BUILD_ID/pages/_app.module.js" as="script" crossorigin="anonymous"/><link rel="preload" href="/_next/static/runtime/webpack-d629b83a65f3e33fa99e.module.js" as="script" crossorigin="anonymous"/><link rel="preload" href="/_next/static/chunks/framework.5bb7f30f859f5f31359f.module.js" as="script" crossorigin="anonymous"/><link rel="preload" href="/_next/static/chunks/de003c3a9d308750aa009870a5926f9b18ab31f4.d8f88b74aefd825bf023.module.js" as="script" crossorigin="anonymous"/><link rel="preload" href="/_next/static/runtime/main-f68f05515eff91645605.module.js" as="script" crossorigin="anonymous"/></head><body><div id="__next">Hello world 👋</div><script id="__NEXT_DATA__" type="application/json" crossorigin="anonymous">{"props":{"pageProps":{}},"page":"/","query":{},"buildId":"BUILD_ID","isFallback":false}</script><script crossorigin="anonymous" nomodule="">!function(){var e=document,t=e.createElement("script");if(!("noModule"in t)&&"onbeforeload"in t){var n=!1;e.addEventListener("beforeload",function(e){if(e.target===t)n=!0;else if(!e.target.hasAttribute("nomodule")||!n)return;e.preventDefault()},!0),t.type="module",t.src=".",e.head.appendChild(t),t.remove()}}();</script><script crossorigin="anonymous" nomodule="" src="/_next/static/runtime/polyfills-51838dc5b2b8e0705281.js"></script><script async="" data-next-page="/" src="/_next/static/BUILD_ID/pages/index.js" crossorigin="anonymous" nomodule=""></script><script async="" data-next-page="/" src="/_next/static/BUILD_ID/pages/index.module.js" crossorigin="anonymous" type="module"></script><script async="" data-next-page="/_app" src="/_next/static/BUILD_ID/pages/_app.js" crossorigin="anonymous" nomodule=""></script><script async="" data-next-page="/_app" src="/_next/static/BUILD_ID/pages/_app.module.js" crossorigin="anonymous" type="module"></script><script src="/_next/static/runtime/webpack-4d739ac7b0d8f888ab18.js" async="" crossorigin="anonymous" nomodule=""></script><script src="/_next/static/runtime/webpack-d629b83a65f3e33fa99e.module.js" async="" crossorigin="anonymous" type="module"></script><script src="/_next/static/chunks/framework.5bb7f30f859f5f31359f.js" async="" crossorigin="anonymous" nomodule=""></script><script src="/_next/static/chunks/framework.5bb7f30f859f5f31359f.module.js" async="" crossorigin="anonymous" type="module"></script><script src="/_next/static/chunks/de003c3a9d308750aa009870a5926f9b18ab31f4.d70844b46f3177e37fca.js" async="" crossorigin="anonymous" nomodule=""></script><script src="/_next/static/chunks/de003c3a9d308750aa009870a5926f9b18ab31f4.d8f88b74aefd825bf023.module.js" async="" crossorigin="anonymous" type="module"></script><script src="/_next/static/runtime/main-1863b30ecf58cb26de5f.js" async="" crossorigin="anonymous" nomodule=""></script><script src="/_next/static/runtime/main-f68f05515eff91645605.module.js" async="" crossorigin="anonymous" type="module"></script><script src="/_next/static/BUILD_ID/_buildManifest.js" async="" crossorigin="anonymous" nomodule=""></script><script src="/_next/static/BUILD_ID/_buildManifest.module.js" async="" crossorigin="anonymous" type="module"></script><script src="/_next/static/BUILD_ID/_ssgManifest.js" async="" crossorigin="anonymous" nomodule=""></script><script src="/_next/static/BUILD_ID/_ssgManifest.module.js" async="" crossorigin="anonymous" type="module"></script></body></html>
\ No newline at end of file
+<!DOCTYPE html><html><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width"/><meta name="next-head-count" content="2"/><link rel="preload" href="/_next/static/BUILD_ID/pages/index.module.js" as="script" crossorigin="anonymous"/><link rel="preload" href="/_next/static/BUILD_ID/pages/_app.module.js" as="script" crossorigin="anonymous"/><link rel="preload" href="/_next/static/runtime/webpack-d629b83a65f3e33fa99e.module.js" as="script" crossorigin="anonymous"/><link rel="preload" href="/_next/static/chunks/framework.5bb7f30f859f5f31359f.module.js" as="script" crossorigin="anonymous"/><link rel="preload" href="/_next/static/chunks/de003c3a9d308750aa009870a5926f9b18ab31f4.bc2d044661db40396778.module.js" as="script" crossorigin="anonymous"/><link rel="preload" href="/_next/static/runtime/main-f68f05515eff91645605.module.js" as="script" crossorigin="anonymous"/></head><body><div id="__next">Hello world 👋</div><script id="__NEXT_DATA__" type="application/json" crossorigin="anonymous">{"props":{"pageProps":{}},"page":"/","query":{},"buildId":"BUILD_ID","isFallback":false}</script><script crossorigin="anonymous" nomodule="">!function(){var e=document,t=e.createElement("script");if(!("noModule"in t)&&"onbeforeload"in t){var n=!1;e.addEventListener("beforeload",function(e){if(e.target===t)n=!0;else if(!e.target.hasAttribute("nomodule")||!n)return;e.preventDefault()},!0),t.type="module",t.src=".",e.head.appendChild(t),t.remove()}}();</script><script crossorigin="anonymous" nomodule="" src="/_next/static/runtime/polyfills-51838dc5b2b8e0705281.js"></script><script async="" data-next-page="/" src="/_next/static/BUILD_ID/pages/index.js" crossorigin="anonymous" nomodule=""></script><script async="" data-next-page="/" src="/_next/static/BUILD_ID/pages/index.module.js" crossorigin="anonymous" type="module"></script><script async="" data-next-page="/_app" src="/_next/static/BUILD_ID/pages/_app.js" crossorigin="anonymous" nomodule=""></script><script async="" data-next-page="/_app" src="/_next/static/BUILD_ID/pages/_app.module.js" crossorigin="anonymous" type="module"></script><script src="/_next/static/runtime/webpack-4d739ac7b0d8f888ab18.js" async="" crossorigin="anonymous" nomodule=""></script><script src="/_next/static/runtime/webpack-d629b83a65f3e33fa99e.module.js" async="" crossorigin="anonymous" type="module"></script><script src="/_next/static/chunks/framework.5bb7f30f859f5f31359f.js" async="" crossorigin="anonymous" nomodule=""></script><script src="/_next/static/chunks/framework.5bb7f30f859f5f31359f.module.js" async="" crossorigin="anonymous" type="module"></script><script src="/_next/static/chunks/de003c3a9d308750aa009870a5926f9b18ab31f4.0d0dc712562cbd9b5d66.js" async="" crossorigin="anonymous" nomodule=""></script><script src="/_next/static/chunks/de003c3a9d308750aa009870a5926f9b18ab31f4.bc2d044661db40396778.module.js" async="" crossorigin="anonymous" type="module"></script><script src="/_next/static/runtime/main-1863b30ecf58cb26de5f.js" async="" crossorigin="anonymous" nomodule=""></script><script src="/_next/static/runtime/main-f68f05515eff91645605.module.js" async="" crossorigin="anonymous" type="module"></script><script src="/_next/static/BUILD_ID/_buildManifest.js" async="" crossorigin="anonymous" nomodule=""></script><script src="/_next/static/BUILD_ID/_buildManifest.module.js" async="" crossorigin="anonymous" type="module"></script><script src="/_next/static/BUILD_ID/_ssgManifest.js" async="" crossorigin="anonymous" nomodule=""></script><script src="/_next/static/BUILD_ID/_ssgManifest.module.js" async="" crossorigin="anonymous" type="module"></script></body></html>
\ No newline at end of file
Diff for withRouter.html
@@ -1 +1 @@
-<!DOCTYPE html><html><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width"/><meta name="next-head-count" content="2"/><link rel="preload" href="/_next/static/BUILD_ID/pages/withRouter.module.js" as="script" crossorigin="anonymous"/><link rel="preload" href="/_next/static/BUILD_ID/pages/_app.module.js" as="script" crossorigin="anonymous"/><link rel="preload" href="/_next/static/runtime/webpack-d629b83a65f3e33fa99e.module.js" as="script" crossorigin="anonymous"/><link rel="preload" href="/_next/static/chunks/framework.5bb7f30f859f5f31359f.module.js" as="script" crossorigin="anonymous"/><link rel="preload" href="/_next/static/chunks/de003c3a9d308750aa009870a5926f9b18ab31f4.d8f88b74aefd825bf023.module.js" as="script" crossorigin="anonymous"/><link rel="preload" href="/_next/static/runtime/main-f68f05515eff91645605.module.js" as="script" crossorigin="anonymous"/></head><body><div id="__next"><div>I use withRouter</div></div><script id="__NEXT_DATA__" type="application/json" crossorigin="anonymous">{"props":{"pageProps":{}},"page":"/withRouter","query":{},"buildId":"BUILD_ID","isFallback":false}</script><script crossorigin="anonymous" nomodule="">!function(){var e=document,t=e.createElement("script");if(!("noModule"in t)&&"onbeforeload"in t){var n=!1;e.addEventListener("beforeload",function(e){if(e.target===t)n=!0;else if(!e.target.hasAttribute("nomodule")||!n)return;e.preventDefault()},!0),t.type="module",t.src=".",e.head.appendChild(t),t.remove()}}();</script><script crossorigin="anonymous" nomodule="" src="/_next/static/runtime/polyfills-51838dc5b2b8e0705281.js"></script><script async="" data-next-page="/withRouter" src="/_next/static/BUILD_ID/pages/withRouter.js" crossorigin="anonymous" nomodule=""></script><script async="" data-next-page="/withRouter" src="/_next/static/BUILD_ID/pages/withRouter.module.js" crossorigin="anonymous" type="module"></script><script async="" data-next-page="/_app" src="/_next/static/BUILD_ID/pages/_app.js" crossorigin="anonymous" nomodule=""></script><script async="" data-next-page="/_app" src="/_next/static/BUILD_ID/pages/_app.module.js" crossorigin="anonymous" type="module"></script><script src="/_next/static/runtime/webpack-4d739ac7b0d8f888ab18.js" async="" crossorigin="anonymous" nomodule=""></script><script src="/_next/static/runtime/webpack-d629b83a65f3e33fa99e.module.js" async="" crossorigin="anonymous" type="module"></script><script src="/_next/static/chunks/framework.5bb7f30f859f5f31359f.js" async="" crossorigin="anonymous" nomodule=""></script><script src="/_next/static/chunks/framework.5bb7f30f859f5f31359f.module.js" async="" crossorigin="anonymous" type="module"></script><script src="/_next/static/chunks/de003c3a9d308750aa009870a5926f9b18ab31f4.d70844b46f3177e37fca.js" async="" crossorigin="anonymous" nomodule=""></script><script src="/_next/static/chunks/de003c3a9d308750aa009870a5926f9b18ab31f4.d8f88b74aefd825bf023.module.js" async="" crossorigin="anonymous" type="module"></script><script src="/_next/static/runtime/main-1863b30ecf58cb26de5f.js" async="" crossorigin="anonymous" nomodule=""></script><script src="/_next/static/runtime/main-f68f05515eff91645605.module.js" async="" crossorigin="anonymous" type="module"></script><script src="/_next/static/BUILD_ID/_buildManifest.js" async="" crossorigin="anonymous" nomodule=""></script><script src="/_next/static/BUILD_ID/_buildManifest.module.js" async="" crossorigin="anonymous" type="module"></script><script src="/_next/static/BUILD_ID/_ssgManifest.js" async="" crossorigin="anonymous" nomodule=""></script><script src="/_next/static/BUILD_ID/_ssgManifest.module.js" async="" crossorigin="anonymous" type="module"></script></body></html>
\ No newline at end of file
+<!DOCTYPE html><html><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width"/><meta name="next-head-count" content="2"/><link rel="preload" href="/_next/static/BUILD_ID/pages/withRouter.module.js" as="script" crossorigin="anonymous"/><link rel="preload" href="/_next/static/BUILD_ID/pages/_app.module.js" as="script" crossorigin="anonymous"/><link rel="preload" href="/_next/static/runtime/webpack-d629b83a65f3e33fa99e.module.js" as="script" crossorigin="anonymous"/><link rel="preload" href="/_next/static/chunks/framework.5bb7f30f859f5f31359f.module.js" as="script" crossorigin="anonymous"/><link rel="preload" href="/_next/static/chunks/de003c3a9d308750aa009870a5926f9b18ab31f4.bc2d044661db40396778.module.js" as="script" crossorigin="anonymous"/><link rel="preload" href="/_next/static/runtime/main-f68f05515eff91645605.module.js" as="script" crossorigin="anonymous"/></head><body><div id="__next"><div>I use withRouter</div></div><script id="__NEXT_DATA__" type="application/json" crossorigin="anonymous">{"props":{"pageProps":{}},"page":"/withRouter","query":{},"buildId":"BUILD_ID","isFallback":false}</script><script crossorigin="anonymous" nomodule="">!function(){var e=document,t=e.createElement("script");if(!("noModule"in t)&&"onbeforeload"in t){var n=!1;e.addEventListener("beforeload",function(e){if(e.target===t)n=!0;else if(!e.target.hasAttribute("nomodule")||!n)return;e.preventDefault()},!0),t.type="module",t.src=".",e.head.appendChild(t),t.remove()}}();</script><script crossorigin="anonymous" nomodule="" src="/_next/static/runtime/polyfills-51838dc5b2b8e0705281.js"></script><script async="" data-next-page="/withRouter" src="/_next/static/BUILD_ID/pages/withRouter.js" crossorigin="anonymous" nomodule=""></script><script async="" data-next-page="/withRouter" src="/_next/static/BUILD_ID/pages/withRouter.module.js" crossorigin="anonymous" type="module"></script><script async="" data-next-page="/_app" src="/_next/static/BUILD_ID/pages/_app.js" crossorigin="anonymous" nomodule=""></script><script async="" data-next-page="/_app" src="/_next/static/BUILD_ID/pages/_app.module.js" crossorigin="anonymous" type="module"></script><script src="/_next/static/runtime/webpack-4d739ac7b0d8f888ab18.js" async="" crossorigin="anonymous" nomodule=""></script><script src="/_next/static/runtime/webpack-d629b83a65f3e33fa99e.module.js" async="" crossorigin="anonymous" type="module"></script><script src="/_next/static/chunks/framework.5bb7f30f859f5f31359f.js" async="" crossorigin="anonymous" nomodule=""></script><script src="/_next/static/chunks/framework.5bb7f30f859f5f31359f.module.js" async="" crossorigin="anonymous" type="module"></script><script src="/_next/static/chunks/de003c3a9d308750aa009870a5926f9b18ab31f4.0d0dc712562cbd9b5d66.js" async="" crossorigin="anonymous" nomodule=""></script><script src="/_next/static/chunks/de003c3a9d308750aa009870a5926f9b18ab31f4.bc2d044661db40396778.module.js" async="" crossorigin="anonymous" type="module"></script><script src="/_next/static/runtime/main-1863b30ecf58cb26de5f.js" async="" crossorigin="anonymous" nomodule=""></script><script src="/_next/static/runtime/main-f68f05515eff91645605.module.js" async="" crossorigin="anonymous" type="module"></script><script src="/_next/static/BUILD_ID/_buildManifest.js" async="" crossorigin="anonymous" nomodule=""></script><script src="/_next/static/BUILD_ID/_buildManifest.module.js" async="" crossorigin="anonymous" type="module"></script><script src="/_next/static/BUILD_ID/_ssgManifest.js" async="" crossorigin="anonymous" nomodule=""></script><script src="/_next/static/BUILD_ID/_ssgManifest.module.js" async="" crossorigin="anonymous" type="module"></script></body></html>
\ No newline at end of file

Serverless Mode (Increase detected ⚠️)
General Overall increase ⚠️
zeit/next.js canary ijjk/next.js add/NEXT-156 Change
buildDuration 11.1s 11.1s ⚠️ +8ms
nodeModulesSize 47.7 MB 47.8 MB ⚠️ +62.9 kB
Client Bundles (main, webpack, commons) Overall increase ⚠️
zeit/next.js canary ijjk/next.js add/NEXT-156 Change
main-HASH.js gzip 6.25 kB 6.25 kB
webpack-HASH.js gzip 746 B 746 B
de003c3a9d30..c6c1.js gzip 10.1 kB N/A N/A
framework.HASH.js gzip 39.1 kB 39.1 kB
de003c3a9d30..e6ba.js gzip N/A 10.6 kB N/A
Overall change 56.3 kB 56.7 kB ⚠️ +485 B
Client Bundles (main, webpack, commons) Modern Overall increase ⚠️
zeit/next.js canary ijjk/next.js add/NEXT-156 Change
main-HASH.module.js gzip 4.78 kB 4.78 kB
webpack-HASH..dule.js gzip 746 B 746 B
de003c3a9d30..dule.js gzip 6.71 kB N/A N/A
framework.HA..dule.js gzip 39.1 kB 39.1 kB
de003c3a9d30..dule.js gzip N/A 7.19 kB N/A
Overall change 51.4 kB 51.9 kB ⚠️ +486 B
Legacy Client Bundles (polyfills)
zeit/next.js canary ijjk/next.js add/NEXT-156 Change
polyfills-HASH.js gzip 26.3 kB 26.3 kB
Overall change 26.3 kB 26.3 kB
Client Pages
zeit/next.js canary ijjk/next.js add/NEXT-156 Change
_app.js gzip 1.24 kB 1.24 kB
_error.js gzip 3.15 kB 3.15 kB
hooks.js gzip 664 B 664 B
index.js gzip 222 B 222 B
link.js gzip 2.03 kB 2.03 kB
routerDirect.js gzip 279 B 279 B
withRouter.js gzip 278 B 278 B
Overall change 7.86 kB 7.86 kB
Client Pages Modern
zeit/next.js canary ijjk/next.js add/NEXT-156 Change
_app.module.js gzip 594 B 594 B
_error.module.js gzip 2.08 kB 2.08 kB
hooks.module.js gzip 370 B 370 B
index.module.js gzip 212 B 212 B
link.module.js gzip 1.48 kB 1.48 kB
routerDirect..dule.js gzip 271 B 271 B
withRouter.m..dule.js gzip 270 B 270 B
Overall change 5.28 kB 5.28 kB
Client Build Manifests
zeit/next.js canary ijjk/next.js add/NEXT-156 Change
_buildManifest.js gzip 61 B 61 B
_buildManife..dule.js gzip 61 B 61 B
Overall change 122 B 122 B
Serverless bundles Overall increase ⚠️
zeit/next.js canary ijjk/next.js add/NEXT-156 Change
_error.js gzip 233 kB 234 kB ⚠️ +1.02 kB
404.html gzip 1.33 kB 1.33 kB
hooks.html gzip 960 B 959 B -1 B
index.js gzip 232 kB 233 kB ⚠️ +1.33 kB
link.js gzip 243 kB 244 kB ⚠️ +1.28 kB
routerDirect.js gzip 241 kB 242 kB ⚠️ +1.1 kB
withRouter.js gzip 241 kB 242 kB ⚠️ +1.18 kB
Overall change 1.19 MB 1.2 MB ⚠️ +5.92 kB

@ijjk
Copy link
Member Author

ijjk commented Mar 31, 2020

Failing test suites

test/integration/size-limit/test/index.test.js

  • Production response size > should not increase the overall response size of default build
  • Production response size > should not increase the overall response size of modern build
Expand output

● Production response size › should not increase the overall response size of default build

expect(received).toBeLessThanOrEqual(expected)

Expected: <= 1024
Received:    2192

  82 |     // These numbers are without gzip compression!
  83 |     const delta = responseSizesBytes - 257 * 1024
> 84 |     expect(delta).toBeLessThanOrEqual(1024) // don't increase size more than 1kb
     |                   ^
  85 |     expect(delta).toBeGreaterThanOrEqual(-1024) // don't decrease size more than 1kb without updating target
  86 |   })
  87 | 

  at Object.<anonymous> (integration/size-limit/test/index.test.js:84:19)

● Production response size › should not increase the overall response size of modern build

expect(received).toBeLessThanOrEqual(expected)

Expected: <= 1024
Received:    2297

  102 |     // These numbers are without gzip compression!
  103 |     const delta = responseSizesBytes - 165 * 1024
> 104 |     expect(delta).toBeLessThanOrEqual(1024) // don't increase size more than 1kb
      |                   ^
  105 |     expect(delta).toBeGreaterThanOrEqual(-1024) // don't decrease size more than 1kb without updating target
  106 |   })
  107 | })

  at Object.<anonymous> (integration/size-limit/test/index.test.js:104:19)

Copy link
Member

@timneutkens timneutkens left a comment

Choose a reason for hiding this comment

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

We should just render a 404 when that particular error happens instead of introducing another package.

Copy link
Member

@Timer Timer left a comment

Choose a reason for hiding this comment

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

Let's leave this a 400 and fix for serverless. Please remove this additional dep.

@ijjk
Copy link
Member Author

ijjk commented Apr 1, 2020

Closing in favor of new PR

@ijjk ijjk closed this Apr 1, 2020
@ijjk ijjk deleted the add/NEXT-156 branch April 1, 2020 15:29
@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.

3 participants