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

Add warning for invalid href being passed to router #8231

Merged
merged 6 commits into from
Aug 7, 2019

Conversation

ijjk
Copy link
Member

@ijjk ijjk commented Aug 3, 2019

If a user passes a href with mailto: or an external link https://google.com it can cause unexpected behavior.

This throws an error in development mode so the invalid href can be corrected and handles it gracefully in production.

Closes: #8212
Closes: #8273
x-ref: #7843

errors/invalid-href-passed.md Outdated Show resolved Hide resolved
errors/invalid-href-passed.md Outdated Show resolved Hide resolved
errors/invalid-href-passed.md Outdated Show resolved Hide resolved
errors/invalid-href-passed.md Outdated Show resolved Hide resolved
errors/invalid-href-passed.md Outdated Show resolved Hide resolved
packages/next-server/lib/router/router.ts Outdated Show resolved Hide resolved
packages/next-server/lib/router/router.ts Outdated Show resolved Hide resolved
packages/next-server/lib/router/router.ts Outdated Show resolved Hide resolved
@ijjk
Copy link
Member Author

ijjk commented Aug 5, 2019

Stats from current PR

Click to expand stats ⚠️ Total Bundle Size Increase ⚠️
zeit/next.js canary ijjk/next.js invalid-href-warning Change
Build Duration 13.9s 13.8s -54ms
node_modules Size 43.6 MB 43.6 MB ⚠️ +919 B
Total Bundle (main, webpack, commons) Size 206 kB 206 kB ⚠️ +101 B
Total Bundle (main, webpack, commons) gzip Size 67.8 kB 67.8 kB ⚠️ +45 B
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 ⚠️ +101 B
Client commons gzip Size 61.1 kB 61.2 kB ⚠️ +45 B
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 703 kB ⚠️ +793 B
Click to expand serverless stats ⚠️ Total Bundle Size Increase ⚠️
zeit/next.js canary ijjk/next.js invalid-href-warning Change
Build Duration 14s 15.1s ⚠️ +1.1s
node_modules Size 43.6 MB 43.6 MB ⚠️ +919 B
Total Bundle (main, webpack, commons) Size 206 kB 206 kB ⚠️ +101 B
Total Bundle (main, webpack, commons) gzip Size 67.8 kB 67.8 kB ⚠️ +45 B
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 ⚠️ +101 B
Client commons gzip Size 61.1 kB 61.2 kB ⚠️ +45 B
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 ⚠️ +294 B
Serverless pages/link gzip Size 67.8 kB 67.9 kB ⚠️ +74 B
Serverless pages/index Size 244 kB 244 kB ⚠️ +268 B
Serverless pages/index gzip Size 65.6 kB 65.7 kB ⚠️ +53 B
Serverless pages/_error Size 243 kB 244 kB ⚠️ +268 B
Serverless pages/_error gzip Size 65.4 kB 65.4 kB ⚠️ +53 B
Serverless pages/routerDirect Size 244 kB 245 kB ⚠️ +268 B
Serverless pages/routerDirect gzip Size 65.6 kB 65.6 kB ⚠️ +54 B
Serverless pages/withRouter Size 244 kB 245 kB ⚠️ +268 B
Serverless pages/withRouter gzip Size 65.7 kB 65.8 kB ⚠️ +54 B
Build Dir Size 1.89 MB 1.89 MB ⚠️ +2.57 kB
Diff for commons.js
@@ -3009,6 +3009,10 @@ function toRoute(path) {
   return path.replace(/\/$/, '') || '/';
 }
 
+function invalidHref(href) {
+  if (false) {}
+}
+
 var Router =
 /*#__PURE__*/
 function () {
@@ -3223,7 +3227,13 @@ function () {
 
         var _url_1$parse = url_1.parse(url, true),
             pathname = _url_1$parse.pathname,
-            query = _url_1$parse.query; // If asked to change the current URL we should reload the current page
+            query = _url_1$parse.query,
+            protocol = _url_1$parse.protocol;
+
+        if (!pathname || protocol) {
+          invalidHref(url);
+          return resolve(false);
+        } // 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)
@@ -3492,12 +3502,17 @@ function () {
       var _this4 = this;
 
       return new _promise["default"](function (resolve, reject) {
-        // 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
+            pathname = _url_1$parse3.pathname,
+            protocol = _url_1$parse3.protocol;
+
+        if (!pathname || protocol) {
+          invalidHref(url);
+          return;
+        } // Prefetch is not supported in development mode because it would trigger on-demand-entries
+
 
+        if (false) {} // @ts-ignore pathname is always defined
 
         var route = toRoute(pathname);
 
Diff for main.js
@@ -1,4 +1,4 @@
-(window["webpackJsonp"] = window["webpackJsonp"] || []).push([[2],{
+(window["webpackJsonp"] = window["webpackJsonp"] || []).push([[8],{
 
 /***/ "+iuc":
 /***/ (function(module, exports, __webpack_require__) {

@ijjk
Copy link
Member Author

ijjk commented Aug 5, 2019

Stats from current PR

Click to expand stats ⚠️ Total Bundle Size Increase ⚠️
zeit/next.js canary ijjk/next.js invalid-href-warning Change
Build Duration 12.9s 12.9s ⚠️ +77ms
node_modules Size 43.6 MB 43.6 MB ⚠️ +1.2 kB
Total Bundle (main, webpack, commons) Size 206 kB 206 kB ⚠️ +73 B
Total Bundle (main, webpack, commons) gzip Size 67.8 kB 67.8 kB ⚠️ +27 B
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 ⚠️ +73 B
Client commons gzip Size 61.1 kB 61.1 kB ⚠️ +27 B
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 703 kB ⚠️ +873 B
Click to expand serverless stats ⚠️ Total Bundle Size Increase ⚠️
zeit/next.js canary ijjk/next.js invalid-href-warning Change
Build Duration 14.1s 14.2s ⚠️ +123ms
node_modules Size 43.6 MB 43.6 MB ⚠️ +1.2 kB
Total Bundle (main, webpack, commons) Size 206 kB 206 kB ⚠️ +73 B
Total Bundle (main, webpack, commons) gzip Size 67.8 kB 67.8 kB ⚠️ +27 B
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 ⚠️ +73 B
Client commons gzip Size 61.1 kB 61.1 kB ⚠️ +27 B
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 ⚠️ +240 B
Serverless pages/link gzip Size 67.8 kB 67.9 kB ⚠️ +60 B
Serverless pages/index Size 244 kB 244 kB ⚠️ +214 B
Serverless pages/index gzip Size 65.6 kB 65.7 kB ⚠️ +39 B
Serverless pages/_error Size 243 kB 244 kB ⚠️ +214 B
Serverless pages/_error gzip Size 65.4 kB 65.4 kB ⚠️ +40 B
Serverless pages/routerDirect Size 244 kB 245 kB ⚠️ +214 B
Serverless pages/routerDirect gzip Size 65.6 kB 65.6 kB ⚠️ +41 B
Serverless pages/withRouter Size 244 kB 245 kB ⚠️ +214 B
Serverless pages/withRouter gzip Size 65.7 kB 65.8 kB ⚠️ +34 B
Build Dir Size 1.89 MB 1.89 MB ⚠️ +2.49 kB
Diff for commons.js
@@ -3223,7 +3223,14 @@ function () {
 
         var _url_1$parse = url_1.parse(url, true),
             pathname = _url_1$parse.pathname,
-            query = _url_1$parse.query; // If asked to change the current URL we should reload the current page
+            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
         // (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)
@@ -3492,12 +3499,18 @@ function () {
       var _this4 = this;
 
       return new _promise["default"](function (resolve, reject) {
-        // 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
+            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
+
 
+        if (false) {} // @ts-ignore pathname is always defined
 
         var route = toRoute(pathname);
 

@ijjk
Copy link
Member Author

ijjk commented Aug 5, 2019

Stats from current PR

Click to expand stats ⚠️ Total Bundle Size Increase ⚠️
zeit/next.js canary ijjk/next.js invalid-href-warning Change
Build Duration 12.8s 12.7s -84ms
node_modules Size 43.6 MB 43.6 MB ⚠️ +1.2 kB
Total Bundle (main, webpack, commons) Size 206 kB 206 kB ⚠️ +73 B
Total Bundle (main, webpack, commons) gzip Size 67.8 kB 67.8 kB ⚠️ +27 B
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 ⚠️ +73 B
Client commons gzip Size 61.1 kB 61.1 kB ⚠️ +27 B
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 703 kB ⚠️ +873 B
Click to expand serverless stats ⚠️ Total Bundle Size Increase ⚠️
zeit/next.js canary ijjk/next.js invalid-href-warning Change
Build Duration 13.8s 14.3s ⚠️ +579ms
node_modules Size 43.6 MB 43.6 MB ⚠️ +1.2 kB
Total Bundle (main, webpack, commons) Size 206 kB 206 kB ⚠️ +73 B
Total Bundle (main, webpack, commons) gzip Size 67.8 kB 67.8 kB ⚠️ +26 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 ⚠️ +73 B
Client commons gzip Size 61.1 kB 61.1 kB ⚠️ +27 B
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 ⚠️ +240 B
Serverless pages/link gzip Size 67.8 kB 67.9 kB ⚠️ +58 B
Serverless pages/index Size 244 kB 244 kB ⚠️ +214 B
Serverless pages/index gzip Size 65.6 kB 65.7 kB ⚠️ +38 B
Serverless pages/_error Size 243 kB 244 kB ⚠️ +214 B
Serverless pages/_error gzip Size 65.4 kB 65.4 kB ⚠️ +39 B
Serverless pages/routerDirect Size 244 kB 245 kB ⚠️ +214 B
Serverless pages/routerDirect gzip Size 65.6 kB 65.6 kB ⚠️ +39 B
Serverless pages/withRouter Size 244 kB 245 kB ⚠️ +214 B
Serverless pages/withRouter gzip Size 65.7 kB 65.8 kB ⚠️ +33 B
Build Dir Size 1.89 MB 1.89 MB ⚠️ +2.49 kB
Diff for commons.js
@@ -3223,7 +3223,14 @@ function () {
 
         var _url_1$parse = url_1.parse(url, true),
             pathname = _url_1$parse.pathname,
-            query = _url_1$parse.query; // If asked to change the current URL we should reload the current page
+            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
         // (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)
@@ -3492,12 +3499,18 @@ function () {
       var _this4 = this;
 
       return new _promise["default"](function (resolve, reject) {
-        // 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
+            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
+
 
+        if (false) {} // @ts-ignore pathname is always defined
 
         var route = toRoute(pathname);
 

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

ijjk commented Aug 7, 2019

Stats from current PR

Click to expand stats ⚠️ Total Bundle Size Increase ⚠️
zeit/next.js canary ijjk/next.js invalid-href-warning Change
Build Duration 22s 20.9s -1.1s
node_modules Size 43.6 MB 43.6 MB ⚠️ +1.2 kB
Total Bundle (main, webpack, commons) Size 207 kB 207 kB ⚠️ +73 B
Total Bundle (main, webpack, commons) gzip Size 68.1 kB 68.1 kB ⚠️ +33 B
Total Bundle (main, webpack, commons) Modern Size 181 kB 182 kB ⚠️ +66 B
Total Bundle (main, webpack, commons) Modern gzip Size 59.9 kB 59.9 kB ⚠️ +22 B
Client _app Size 2.39 kB 2.39 kB
Client _app gzip Size 1.08 kB 1.08 kB -1 B
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 300 B -1 B
Client pages/withRouter Modern Size 423 B 423 B
Client pages/withRouter gzip Modern Size 309 B 309 B
Client main Size 15.8 kB 15.8 kB
Client main gzip Size 5.46 kB 5.46 kB ⚠️ +2 B
Client main Modern Size 12.8 kB 12.8 kB
Client main Modern gzip Size 4.83 kB 4.83 kB
Client commons Size 188 kB 188 kB ⚠️ +73 B
Client commons gzip Size 61.3 kB 61.3 kB ⚠️ +32 B
Client commons Modern Size 169 kB 169 kB ⚠️ +66 B
Client commons Modern gzip Size 55.1 kB 55.1 kB ⚠️ +22 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 ⚠️ +1.68 kB
Click to expand serverless stats ⚠️ Total Bundle Size Increase ⚠️
zeit/next.js canary ijjk/next.js invalid-href-warning Change
Build Duration 22.3s 22.7s ⚠️ +400ms
node_modules Size 43.6 MB 43.6 MB ⚠️ +1.2 kB
Total Bundle (main, webpack, commons) Size 207 kB 207 kB ⚠️ +73 B
Total Bundle (main, webpack, commons) gzip Size 68.1 kB 68.1 kB ⚠️ +32 B
Total Bundle (main, webpack, commons) Modern Size 181 kB 182 kB ⚠️ +66 B
Total Bundle (main, webpack, commons) Modern gzip Size 59.9 kB 59.9 kB ⚠️ +22 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.8 kB
Client main gzip Size 5.46 kB 5.46 kB
Client main Modern Size 12.8 kB 12.8 kB
Client main Modern gzip Size 4.83 kB 4.83 kB
Client commons Size 188 kB 188 kB ⚠️ +73 B
Client commons gzip Size 61.3 kB 61.3 kB ⚠️ +32 B
Client commons Modern Size 169 kB 169 kB ⚠️ +66 B
Client commons Modern gzip Size 55.1 kB 55.1 kB ⚠️ +22 B
Client webpack Size 1.53 kB 1.53 kB
Client webpack gzip Size 778 B 778 B
Client webpack Modern Size 1.53 kB 1.53 kB
Client webpack Modern gzip Size 785 B 785 B
Serverless pages/link Size 255 kB 255 kB ⚠️ +240 B
Serverless pages/link gzip Size 68.5 kB 68.6 kB ⚠️ +47 B
Serverless pages/index Size 247 kB 248 kB ⚠️ +214 B
Serverless pages/index gzip Size 66.3 kB 66.4 kB ⚠️ +26 B
Serverless pages/_error Size 247 kB 247 kB ⚠️ +214 B
Serverless pages/_error gzip Size 66.1 kB 66.1 kB ⚠️ +27 B
Serverless pages/routerDirect Size 248 kB 248 kB ⚠️ +214 B
Serverless pages/routerDirect gzip Size 66.3 kB 66.3 kB ⚠️ +27 B
Serverless pages/withRouter Size 248 kB 248 kB ⚠️ +214 B
Serverless pages/withRouter gzip Size 66.4 kB 66.4 kB ⚠️ +26 B
Build Dir Size 2.59 MB 2.59 MB ⚠️ +3.3 kB
Diff for commons.js
@@ -3223,7 +3223,14 @@ function () {
 
         var _url_1$parse = url_1.parse(url, true),
             pathname = _url_1$parse.pathname,
-            query = _url_1$parse.query; // If asked to change the current URL we should reload the current page
+            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
         // (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)
@@ -3492,12 +3499,18 @@ function () {
       var _this4 = this;
 
       return new _promise["default"](function (resolve, reject) {
-        // 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
+            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
+
 
+        if (false) {} // @ts-ignore pathname is always defined
 
         var route = toRoute(pathname);
 
Diff for commonsModern.js
@@ -2700,13 +2700,21 @@ class Router {
 
       const {
         pathname,
-        query
-      } = url_1.parse(url, true); // If asked to change the current URL we should reload the current page
+        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
       // (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
@@ -2945,11 +2953,19 @@ 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
-      } = url_1.parse(url); // @ts-ignore pathname is always defined
+        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
 
       const route = toRoute(pathname);
       this.pageLoader.prefetch(route).then(resolve, reject);

@Timer Timer merged commit 8e4509c into vercel:canary Aug 7, 2019
@ijjk ijjk deleted the invalid-href-warning branch August 7, 2019 15:14
Janpot added a commit to Janpot/material-ui that referenced this pull request Aug 24, 2019
const { pathname, query } = parse(url, true)
const { pathname, query, protocol } = parse(url, true)

if (!pathname || protocol) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this condition looks wrong, IMO should be !pathname || !protocol

Copy link
Contributor

@Kinbaum Kinbaum Sep 30, 2019

Choose a reason for hiding this comment

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

I agree, just stumbled upon this today using Router.push and passing an absolute URL object to both href, and as.

@vercel vercel locked as resolved and limited conversation to collaborators Feb 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Links to external resources are treated as pages Add dev-only warning for invalid <Link>s
4 participants