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

Update error when internal href and external as are used #20658

Merged
merged 4 commits into from
Jan 1, 2021

Conversation

ijjk
Copy link
Member

@ijjk ijjk commented Jan 1, 2021

This adds an err.sh and test case for when a user adds an internal href /hello with an external as https://google.com

Closes: #19428

@ijjk

This comment has been minimized.

@ijjk

This comment has been minimized.

@ijjk ijjk marked this pull request as draft January 1, 2021 07:21
@ijjk
Copy link
Member Author

ijjk commented Jan 1, 2021

Stats from current PR

Default Server Mode (Increase detected ⚠️)
General Overall increase ⚠️
vercel/next.js canary ijjk/next.js invalid-relative-href Change
buildDuration 8.2s 8.4s ⚠️ +155ms
nodeModulesSize 83 MB 83 MB ⚠️ +1.06 kB
Page Load Tests Overall decrease ⚠️
vercel/next.js canary ijjk/next.js invalid-relative-href Change
/ failed reqs 0 0
/ total time (seconds) 1.668 1.689 ⚠️ +0.02
/ avg req/sec 1498.53 1479.9 ⚠️ -18.63
/error-in-render failed reqs 0 0
/error-in-render total time (seconds) 1.045 1.101 ⚠️ +0.06
/error-in-render avg req/sec 2392.4 2269.68 ⚠️ -122.72
Client Bundles (main, webpack, commons) Overall increase ⚠️
vercel/next.js canary ijjk/next.js invalid-relative-href Change
677f882d2ed8..2428.js gzip 12.9 kB 13 kB ⚠️ +38 B
framework.HASH.js gzip 39 kB 39 kB
main-212f85f..f23b.js gzip 6.59 kB 6.59 kB
webpack-7193..1446.js gzip 751 B 751 B
Overall change 59.2 kB 59.3 kB ⚠️ +38 B
Legacy Client Bundles (polyfills)
vercel/next.js canary ijjk/next.js invalid-relative-href Change
polyfills-67..b7d1.js gzip 31.2 kB 31.2 kB
Overall change 31.2 kB 31.2 kB
Client Pages
vercel/next.js canary ijjk/next.js invalid-relative-href Change
_app-6220e08..9a40.js gzip 1.28 kB 1.28 kB
_error-4b0b5..2c91.js gzip 3.44 kB 3.44 kB
hooks-5f309a..7282.js gzip 887 B 887 B
index-57f580..c562.js gzip 227 B 227 B
link-b862cd7..dba8.js gzip 1.64 kB 1.64 kB
routerDirect..bd82.js gzip 303 B 303 B
withRouter-2..e384.js gzip 302 B 302 B
Overall change 8.08 kB 8.08 kB
Client Build Manifests
vercel/next.js canary ijjk/next.js invalid-relative-href Change
_buildManifest.js gzip 321 B 321 B
Overall change 321 B 321 B
Rendered Page Sizes Overall decrease ✓
vercel/next.js canary ijjk/next.js invalid-relative-href Change
index.html gzip 617 B 616 B -1 B
link.html gzip 622 B 621 B -1 B
withRouter.html gzip 610 B 610 B
Overall change 1.85 kB 1.85 kB -2 B

Diffs

Diff for 677f882d2ed8..09954e463.js
@@ -2058,13 +2058,38 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                             if (false) {
                             }
 
+                            if (isLocalURL(as)) {
+                              _context.next = 62;
+                              break;
+                            }
+
+                            if (true) {
+                              _context.next = 60;
+                              break;
+                            }
+
+                            throw new Error(
+                              'Invalid href: "'
+                                .concat(url, '" and as: "')
+                                .concat(
+                                  as,
+                                  '", received relative href and external as'
+                                ) +
+                                "\nSee more info: https://err.sh/next.js/invalid-relative-url-external-as"
+                            );
+
+                          case 60:
+                            window.location.href = as;
+                            return _context.abrupt("return", false);
+
+                          case 62:
                             resolvedAs = delLocale(
                               delBasePath(resolvedAs),
                               this.locale
                             );
 
                             if (!(0, _isDynamic.isDynamicRoute)(route)) {
-                              _context.next = 73;
+                              _context.next = 78;
                               break;
                             }
 
@@ -2087,7 +2112,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                                 (shouldInterpolate && !interpolatedAs.result)
                               )
                             ) {
-                              _context.next = 72;
+                              _context.next = 77;
                               break;
                             }
 
@@ -2098,7 +2123,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                             });
 
                             if (!(missingParams.length > 0)) {
-                              _context.next = 70;
+                              _context.next = 75;
                               break;
                             }
 
@@ -2129,11 +2154,11 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                                 )
                             );
 
-                          case 70:
-                            _context.next = 73;
+                          case 75:
+                            _context.next = 78;
                             break;
 
-                          case 72:
+                          case 77:
                             if (shouldInterpolate) {
                               as = (0, _utils.formatWithValidation)(
                                 Object.assign({}, _parsedAs, {
@@ -2149,14 +2174,14 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                               Object.assign(query, routeMatch);
                             }
 
-                          case 73:
+                          case 78:
                             Router.events.emit(
                               "routeChangeStart",
                               as,
                               routeProps
                             );
-                            _context.prev = 74;
-                            _context.next = 77;
+                            _context.prev = 79;
+                            _context.next = 82;
                             return this.getRouteInfo(
                               route,
                               pathname,
@@ -2165,7 +2190,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                               routeProps
                             );
 
-                          case 77:
+                          case 82:
                             routeInfo = _context.sent;
                             (_routeInfo = routeInfo),
                               (error = _routeInfo.error),
@@ -2174,14 +2199,14 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                               (__N_SSP = _routeInfo.__N_SSP); // handle redirect on client-transition
 
                             if (!((__N_SSG || __N_SSP) && props)) {
-                              _context.next = 103;
+                              _context.next = 108;
                               break;
                             }
 
                             if (
                               !(props.pageProps && props.pageProps.__N_REDIRECT)
                             ) {
-                              _context.next = 90;
+                              _context.next = 95;
                               break;
                             }
 
@@ -2190,7 +2215,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                             // it's not
 
                             if (!destination.startsWith("/")) {
-                              _context.next = 88;
+                              _context.next = 93;
                               break;
                             }
 
@@ -2200,7 +2225,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                             this._resolveHref(parsedHref, pages, false);
 
                             if (!pages.includes(parsedHref.pathname)) {
-                              _context.next = 88;
+                              _context.next = 93;
                               break;
                             }
 
@@ -2216,35 +2241,35 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                               this.change(method, newUrl, newAs, options)
                             );
 
-                          case 88:
+                          case 93:
                             window.location.href = destination;
                             return _context.abrupt(
                               "return",
                               new Promise(function() {})
                             );
 
-                          case 90:
+                          case 95:
                             if (!(props.notFound === SSG_DATA_NOT_FOUND)) {
-                              _context.next = 103;
+                              _context.next = 108;
                               break;
                             }
 
-                            _context.prev = 91;
-                            _context.next = 94;
+                            _context.prev = 96;
+                            _context.next = 99;
                             return this.fetchComponent("/404");
 
-                          case 94:
+                          case 99:
                             notFoundRoute = "/404";
-                            _context.next = 100;
+                            _context.next = 105;
                             break;
 
-                          case 97:
-                            _context.prev = 97;
-                            _context.t1 = _context["catch"](91);
+                          case 102:
+                            _context.prev = 102;
+                            _context.t1 = _context["catch"](96);
                             notFoundRoute = "/_error";
 
-                          case 100:
-                            _context.next = 102;
+                          case 105:
+                            _context.next = 107;
                             return this.getRouteInfo(
                               notFoundRoute,
                               notFoundRoute,
@@ -2255,10 +2280,10 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                               }
                             );
 
-                          case 102:
+                          case 107:
                             routeInfo = _context.sent;
 
-                          case 103:
+                          case 108:
                             Router.events.emit(
                               "beforeHistoryChange",
                               as,
@@ -2269,7 +2294,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                             if (false) {
                             }
 
-                            _context.next = 108;
+                            _context.next = 113;
                             return this.set(
                               route,
                               pathname,
@@ -2288,9 +2313,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                               else throw e;
                             });
 
-                          case 108:
+                          case 113:
                             if (!error) {
-                              _context.next = 111;
+                              _context.next = 116;
                               break;
                             }
 
@@ -2302,7 +2327,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                             );
                             throw error;
 
-                          case 111:
+                          case 116:
                             if (false) {
                             }
 
@@ -2313,21 +2338,21 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                             );
                             return _context.abrupt("return", true);
 
-                          case 116:
-                            _context.prev = 116;
-                            _context.t2 = _context["catch"](74);
+                          case 121:
+                            _context.prev = 121;
+                            _context.t2 = _context["catch"](79);
 
                             if (!_context.t2.cancelled) {
-                              _context.next = 120;
+                              _context.next = 125;
                               break;
                             }
 
                             return _context.abrupt("return", false);
 
-                          case 120:
+                          case 125:
                             throw _context.t2;
 
-                          case 121:
+                          case 126:
                           case "end":
                             return _context.stop();
                         }
@@ -2337,8 +2362,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                     this,
                     [
                       [36, 46],
-                      [74, 116],
-                      [91, 97]
+                      [79, 121],
+                      [96, 102]
                     ]
                   );
                 })
@@ -3405,7 +3430,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
           origin = _URL.origin;
 
         if (origin !== globalBase.origin) {
-          throw new Error("invariant: invalid relative URL");
+          throw new Error(
+            "invariant: invalid relative URL, router received ".concat(url)
+          );
         }
 
         return {
Diff for index.html
@@ -22,7 +22,7 @@
     />
     <link
       rel="preload"
-      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.8fc8494a87d09954e463.js"
+      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.c8e4476148174ac63f42.js"
       as="script"
     />
     <link
@@ -65,7 +65,7 @@
       async=""
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.8fc8494a87d09954e463.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.c8e4476148174ac63f42.js"
       async=""
     ></script>
     <script
Diff for link.html
@@ -22,7 +22,7 @@
     />
     <link
       rel="preload"
-      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.8fc8494a87d09954e463.js"
+      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.c8e4476148174ac63f42.js"
       as="script"
     />
     <link
@@ -70,7 +70,7 @@
       async=""
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.8fc8494a87d09954e463.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.c8e4476148174ac63f42.js"
       async=""
     ></script>
     <script
Diff for withRouter.html
@@ -22,7 +22,7 @@
     />
     <link
       rel="preload"
-      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.8fc8494a87d09954e463.js"
+      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.c8e4476148174ac63f42.js"
       as="script"
     />
     <link
@@ -65,7 +65,7 @@
       async=""
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.8fc8494a87d09954e463.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.c8e4476148174ac63f42.js"
       async=""
     ></script>
     <script

Serverless Mode (Increase detected ⚠️)
General Overall increase ⚠️
vercel/next.js canary ijjk/next.js invalid-relative-href Change
buildDuration 9.9s 9.9s ⚠️ +38ms
nodeModulesSize 83 MB 83 MB ⚠️ +1.06 kB
Client Bundles (main, webpack, commons) Overall increase ⚠️
vercel/next.js canary ijjk/next.js invalid-relative-href Change
677f882d2ed8..2428.js gzip 12.9 kB N/A N/A
framework.HASH.js gzip 39 kB 39 kB
main-212f85f..f23b.js gzip 6.59 kB 6.59 kB
webpack-7193..1446.js gzip 751 B 751 B
677f882d2ed8..dbe2.js gzip N/A 13 kB N/A
Overall change 59.2 kB 59.3 kB ⚠️ +38 B
Legacy Client Bundles (polyfills)
vercel/next.js canary ijjk/next.js invalid-relative-href Change
polyfills-67..b7d1.js gzip 31.2 kB 31.2 kB
Overall change 31.2 kB 31.2 kB
Client Pages
vercel/next.js canary ijjk/next.js invalid-relative-href Change
_app-6220e08..9a40.js gzip 1.28 kB 1.28 kB
_error-4b0b5..2c91.js gzip 3.44 kB 3.44 kB
hooks-5f309a..7282.js gzip 887 B 887 B
index-57f580..c562.js gzip 227 B 227 B
link-b862cd7..dba8.js gzip 1.64 kB 1.64 kB
routerDirect..bd82.js gzip 303 B 303 B
withRouter-2..e384.js gzip 302 B 302 B
Overall change 8.08 kB 8.08 kB
Client Build Manifests
vercel/next.js canary ijjk/next.js invalid-relative-href Change
_buildManifest.js gzip 321 B 321 B
Overall change 321 B 321 B
Serverless bundles Overall increase ⚠️
vercel/next.js canary ijjk/next.js invalid-relative-href Change
_error.js 1 MB 1 MB ⚠️ +24 B
404.html 2.67 kB 2.67 kB
hooks.html 1.92 kB 1.92 kB
index.js 1 MB 1 MB ⚠️ +24 B
link.js 1.06 MB 1.06 MB ⚠️ +132 B
routerDirect.js 1.05 MB 1.05 MB ⚠️ +132 B
withRouter.js 1.05 MB 1.05 MB ⚠️ +132 B
Overall change 5.17 MB 5.17 MB ⚠️ +444 B
Commit: 1d95929

@ijjk ijjk marked this pull request as ready for review January 1, 2021 17:35
errors/invalid-relative-url-external-as.md Outdated Show resolved Hide resolved
errors/invalid-relative-url-external-as.md Outdated Show resolved Hide resolved
errors/invalid-relative-url-external-as.md Outdated Show resolved Hide resolved
@ijjk ijjk requested a review from Timer January 1, 2021 17:54
@ijjk
Copy link
Member Author

ijjk commented Jan 1, 2021

Stats from current PR

Default Server Mode (Increase detected ⚠️)
General Overall increase ⚠️
vercel/next.js canary ijjk/next.js invalid-relative-href Change
buildDuration 8.8s 8.6s -118ms
nodeModulesSize 83 MB 83 MB ⚠️ +1.06 kB
Page Load Tests Overall increase ✓
vercel/next.js canary ijjk/next.js invalid-relative-href Change
/ failed reqs 0 0
/ total time (seconds) 1.738 1.754 ⚠️ +0.02
/ avg req/sec 1438.27 1425 ⚠️ -13.27
/error-in-render failed reqs 0 0
/error-in-render total time (seconds) 1.096 1.061 -0.04
/error-in-render avg req/sec 2281.05 2357.09 +76.04
Client Bundles (main, webpack, commons) Overall increase ⚠️
vercel/next.js canary ijjk/next.js invalid-relative-href Change
677f882d2ed8..2428.js gzip 12.9 kB 13 kB ⚠️ +38 B
framework.HASH.js gzip 39 kB 39 kB
main-212f85f..f23b.js gzip 6.59 kB 6.59 kB
webpack-7193..1446.js gzip 751 B 751 B
Overall change 59.2 kB 59.3 kB ⚠️ +38 B
Legacy Client Bundles (polyfills)
vercel/next.js canary ijjk/next.js invalid-relative-href Change
polyfills-67..b7d1.js gzip 31.2 kB 31.2 kB
Overall change 31.2 kB 31.2 kB
Client Pages
vercel/next.js canary ijjk/next.js invalid-relative-href Change
_app-6220e08..9a40.js gzip 1.28 kB 1.28 kB
_error-4b0b5..2c91.js gzip 3.44 kB 3.44 kB
hooks-5f309a..7282.js gzip 887 B 887 B
index-57f580..c562.js gzip 227 B 227 B
link-b862cd7..dba8.js gzip 1.64 kB 1.64 kB
routerDirect..bd82.js gzip 303 B 303 B
withRouter-2..e384.js gzip 302 B 302 B
Overall change 8.08 kB 8.08 kB
Client Build Manifests
vercel/next.js canary ijjk/next.js invalid-relative-href Change
_buildManifest.js gzip 321 B 321 B
Overall change 321 B 321 B
Rendered Page Sizes Overall decrease ✓
vercel/next.js canary ijjk/next.js invalid-relative-href Change
index.html gzip 617 B 616 B -1 B
link.html gzip 622 B 621 B -1 B
withRouter.html gzip 610 B 610 B
Overall change 1.85 kB 1.85 kB -2 B

Diffs

Diff for 677f882d2ed8..09954e463.js
@@ -2058,13 +2058,38 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                             if (false) {
                             }
 
+                            if (isLocalURL(as)) {
+                              _context.next = 62;
+                              break;
+                            }
+
+                            if (true) {
+                              _context.next = 60;
+                              break;
+                            }
+
+                            throw new Error(
+                              'Invalid href: "'
+                                .concat(url, '" and as: "')
+                                .concat(
+                                  as,
+                                  '", received relative href and external as'
+                                ) +
+                                "\nSee more info: https://err.sh/next.js/invalid-relative-url-external-as"
+                            );
+
+                          case 60:
+                            window.location.href = as;
+                            return _context.abrupt("return", false);
+
+                          case 62:
                             resolvedAs = delLocale(
                               delBasePath(resolvedAs),
                               this.locale
                             );
 
                             if (!(0, _isDynamic.isDynamicRoute)(route)) {
-                              _context.next = 73;
+                              _context.next = 78;
                               break;
                             }
 
@@ -2087,7 +2112,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                                 (shouldInterpolate && !interpolatedAs.result)
                               )
                             ) {
-                              _context.next = 72;
+                              _context.next = 77;
                               break;
                             }
 
@@ -2098,7 +2123,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                             });
 
                             if (!(missingParams.length > 0)) {
-                              _context.next = 70;
+                              _context.next = 75;
                               break;
                             }
 
@@ -2129,11 +2154,11 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                                 )
                             );
 
-                          case 70:
-                            _context.next = 73;
+                          case 75:
+                            _context.next = 78;
                             break;
 
-                          case 72:
+                          case 77:
                             if (shouldInterpolate) {
                               as = (0, _utils.formatWithValidation)(
                                 Object.assign({}, _parsedAs, {
@@ -2149,14 +2174,14 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                               Object.assign(query, routeMatch);
                             }
 
-                          case 73:
+                          case 78:
                             Router.events.emit(
                               "routeChangeStart",
                               as,
                               routeProps
                             );
-                            _context.prev = 74;
-                            _context.next = 77;
+                            _context.prev = 79;
+                            _context.next = 82;
                             return this.getRouteInfo(
                               route,
                               pathname,
@@ -2165,7 +2190,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                               routeProps
                             );
 
-                          case 77:
+                          case 82:
                             routeInfo = _context.sent;
                             (_routeInfo = routeInfo),
                               (error = _routeInfo.error),
@@ -2174,14 +2199,14 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                               (__N_SSP = _routeInfo.__N_SSP); // handle redirect on client-transition
 
                             if (!((__N_SSG || __N_SSP) && props)) {
-                              _context.next = 103;
+                              _context.next = 108;
                               break;
                             }
 
                             if (
                               !(props.pageProps && props.pageProps.__N_REDIRECT)
                             ) {
-                              _context.next = 90;
+                              _context.next = 95;
                               break;
                             }
 
@@ -2190,7 +2215,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                             // it's not
 
                             if (!destination.startsWith("/")) {
-                              _context.next = 88;
+                              _context.next = 93;
                               break;
                             }
 
@@ -2200,7 +2225,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                             this._resolveHref(parsedHref, pages, false);
 
                             if (!pages.includes(parsedHref.pathname)) {
-                              _context.next = 88;
+                              _context.next = 93;
                               break;
                             }
 
@@ -2216,35 +2241,35 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                               this.change(method, newUrl, newAs, options)
                             );
 
-                          case 88:
+                          case 93:
                             window.location.href = destination;
                             return _context.abrupt(
                               "return",
                               new Promise(function() {})
                             );
 
-                          case 90:
+                          case 95:
                             if (!(props.notFound === SSG_DATA_NOT_FOUND)) {
-                              _context.next = 103;
+                              _context.next = 108;
                               break;
                             }
 
-                            _context.prev = 91;
-                            _context.next = 94;
+                            _context.prev = 96;
+                            _context.next = 99;
                             return this.fetchComponent("/404");
 
-                          case 94:
+                          case 99:
                             notFoundRoute = "/404";
-                            _context.next = 100;
+                            _context.next = 105;
                             break;
 
-                          case 97:
-                            _context.prev = 97;
-                            _context.t1 = _context["catch"](91);
+                          case 102:
+                            _context.prev = 102;
+                            _context.t1 = _context["catch"](96);
                             notFoundRoute = "/_error";
 
-                          case 100:
-                            _context.next = 102;
+                          case 105:
+                            _context.next = 107;
                             return this.getRouteInfo(
                               notFoundRoute,
                               notFoundRoute,
@@ -2255,10 +2280,10 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                               }
                             );
 
-                          case 102:
+                          case 107:
                             routeInfo = _context.sent;
 
-                          case 103:
+                          case 108:
                             Router.events.emit(
                               "beforeHistoryChange",
                               as,
@@ -2269,7 +2294,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                             if (false) {
                             }
 
-                            _context.next = 108;
+                            _context.next = 113;
                             return this.set(
                               route,
                               pathname,
@@ -2288,9 +2313,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                               else throw e;
                             });
 
-                          case 108:
+                          case 113:
                             if (!error) {
-                              _context.next = 111;
+                              _context.next = 116;
                               break;
                             }
 
@@ -2302,7 +2327,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                             );
                             throw error;
 
-                          case 111:
+                          case 116:
                             if (false) {
                             }
 
@@ -2313,21 +2338,21 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                             );
                             return _context.abrupt("return", true);
 
-                          case 116:
-                            _context.prev = 116;
-                            _context.t2 = _context["catch"](74);
+                          case 121:
+                            _context.prev = 121;
+                            _context.t2 = _context["catch"](79);
 
                             if (!_context.t2.cancelled) {
-                              _context.next = 120;
+                              _context.next = 125;
                               break;
                             }
 
                             return _context.abrupt("return", false);
 
-                          case 120:
+                          case 125:
                             throw _context.t2;
 
-                          case 121:
+                          case 126:
                           case "end":
                             return _context.stop();
                         }
@@ -2337,8 +2362,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                     this,
                     [
                       [36, 46],
-                      [74, 116],
-                      [91, 97]
+                      [79, 121],
+                      [96, 102]
                     ]
                   );
                 })
@@ -3405,7 +3430,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
           origin = _URL.origin;
 
         if (origin !== globalBase.origin) {
-          throw new Error("invariant: invalid relative URL");
+          throw new Error(
+            "invariant: invalid relative URL, router received ".concat(url)
+          );
         }
 
         return {
Diff for index.html
@@ -22,7 +22,7 @@
     />
     <link
       rel="preload"
-      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.8fc8494a87d09954e463.js"
+      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.c8e4476148174ac63f42.js"
       as="script"
     />
     <link
@@ -65,7 +65,7 @@
       async=""
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.8fc8494a87d09954e463.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.c8e4476148174ac63f42.js"
       async=""
     ></script>
     <script
Diff for link.html
@@ -22,7 +22,7 @@
     />
     <link
       rel="preload"
-      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.8fc8494a87d09954e463.js"
+      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.c8e4476148174ac63f42.js"
       as="script"
     />
     <link
@@ -70,7 +70,7 @@
       async=""
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.8fc8494a87d09954e463.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.c8e4476148174ac63f42.js"
       async=""
     ></script>
     <script
Diff for withRouter.html
@@ -22,7 +22,7 @@
     />
     <link
       rel="preload"
-      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.8fc8494a87d09954e463.js"
+      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.c8e4476148174ac63f42.js"
       as="script"
     />
     <link
@@ -65,7 +65,7 @@
       async=""
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.8fc8494a87d09954e463.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.c8e4476148174ac63f42.js"
       async=""
     ></script>
     <script

Serverless Mode (Increase detected ⚠️)
General Overall increase ⚠️
vercel/next.js canary ijjk/next.js invalid-relative-href Change
buildDuration 10.4s 10.5s ⚠️ +134ms
nodeModulesSize 83 MB 83 MB ⚠️ +1.06 kB
Client Bundles (main, webpack, commons) Overall increase ⚠️
vercel/next.js canary ijjk/next.js invalid-relative-href Change
677f882d2ed8..2428.js gzip 12.9 kB N/A N/A
framework.HASH.js gzip 39 kB 39 kB
main-212f85f..f23b.js gzip 6.59 kB 6.59 kB
webpack-7193..1446.js gzip 751 B 751 B
677f882d2ed8..dbe2.js gzip N/A 13 kB N/A
Overall change 59.2 kB 59.3 kB ⚠️ +38 B
Legacy Client Bundles (polyfills)
vercel/next.js canary ijjk/next.js invalid-relative-href Change
polyfills-67..b7d1.js gzip 31.2 kB 31.2 kB
Overall change 31.2 kB 31.2 kB
Client Pages
vercel/next.js canary ijjk/next.js invalid-relative-href Change
_app-6220e08..9a40.js gzip 1.28 kB 1.28 kB
_error-4b0b5..2c91.js gzip 3.44 kB 3.44 kB
hooks-5f309a..7282.js gzip 887 B 887 B
index-57f580..c562.js gzip 227 B 227 B
link-b862cd7..dba8.js gzip 1.64 kB 1.64 kB
routerDirect..bd82.js gzip 303 B 303 B
withRouter-2..e384.js gzip 302 B 302 B
Overall change 8.08 kB 8.08 kB
Client Build Manifests
vercel/next.js canary ijjk/next.js invalid-relative-href Change
_buildManifest.js gzip 321 B 321 B
Overall change 321 B 321 B
Serverless bundles Overall increase ⚠️
vercel/next.js canary ijjk/next.js invalid-relative-href Change
_error.js 1 MB 1 MB ⚠️ +24 B
404.html 2.67 kB 2.67 kB
hooks.html 1.92 kB 1.92 kB
index.js 1 MB 1 MB ⚠️ +24 B
link.js 1.06 MB 1.06 MB ⚠️ +132 B
routerDirect.js 1.05 MB 1.05 MB ⚠️ +132 B
withRouter.js 1.05 MB 1.05 MB ⚠️ +132 B
Overall change 5.17 MB 5.17 MB ⚠️ +444 B
Commit: 5d65dc2

@ijjk ijjk merged commit 8b803d7 into vercel:canary Jan 1, 2021
@ijjk ijjk deleted the invalid-relative-href branch January 1, 2021 18:14
kodiakhq bot pushed a commit that referenced this pull request Jan 6, 2021
…0766)

This is a follow-up to #20596 and #20658 ensuring the `as` value is prefixed with the `basePath` correctly with a query. This updates the test to also ensure no errors are shown when a query is present on the index `basePath` route. 

Fixes: #20757 (comment)
@vercel vercel locked as resolved and limited conversation to collaborators Jan 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invariant: invalid relative URL - Next.js i18n + Link
2 participants